11e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Copyright (c) 2013 The Chromium Authors. All rights reserved.
21e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
31e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// found in the LICENSE file.
41e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
51e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#ifndef CHROMEOS_DBUS_FAKE_NFC_MANAGER_CLIENT_H_
61e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#define CHROMEOS_DBUS_FAKE_NFC_MANAGER_CLIENT_H_
71e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
81e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include <set>
91e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include <string>
101e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "base/observer_list.h"
121e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "chromeos/chromeos_export.h"
131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "chromeos/dbus/nfc_manager_client.h"
141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "dbus/property.h"
151e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
161e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)namespace chromeos {
171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
181e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// FakeNfcManagerClient simulates the behavior of the NFC Daemon manager object
191e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// and is used both in test cases in place of a mock and on the Linux desktop.
201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class CHROMEOS_EXPORT FakeNfcManagerClient : public NfcManagerClient {
211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) public:
221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  struct Properties : public NfcManagerClient::Properties {
231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    explicit Properties(const PropertyChangedCallback& callback);
241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    virtual ~Properties();
251e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
261e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    // dbus::PropertySet overrides.
271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    virtual void Get(dbus::PropertyBase* property,
281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                     dbus::PropertySet::GetCallback callback) OVERRIDE;
291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    virtual void GetAll() OVERRIDE;
301e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    virtual void Set(dbus::PropertyBase* property,
311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                     dbus::PropertySet::SetCallback callback) OVERRIDE;
321e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  };
331e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  FakeNfcManagerClient();
351e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual ~FakeNfcManagerClient();
361e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
371e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // NfcManagerClient overrides.
381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual void Init(dbus::Bus* bus) OVERRIDE;
391e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual void AddObserver(Observer* observer) OVERRIDE;
401e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual void RemoveObserver(Observer* observer) OVERRIDE;
411e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual Properties* GetProperties() OVERRIDE;
421e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
431e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Methods to simulate adapters getting added and removed.
441e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  void AddAdapter(const std::string& adapter_path);
451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  void RemoveAdapter(const std::string& adapter_path);
461e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
471e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Default path of an adapter that is simulated for testing.
481e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  static const char kDefaultAdapterPath[];
491e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
501e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) private:
511e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Property callback passed when we create Properties* structures.
521e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  void OnPropertyChanged(const std::string& property_name);
531e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
541e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // List of observers interested in event notifications.
551e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  ObserverList<Observer> observers_;
561e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
571e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Set containing the currently simulated adapters.
581e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  std::set<dbus::ObjectPath> adapters_;
591e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
601e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Fake properties object. This gets updated whenever AddAdapter or
611e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // RemoveAdapter gets called.
621e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  scoped_ptr<Properties> properties_;
631e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
641e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(FakeNfcManagerClient);
651e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)};
661e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
671e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}  // namespace chromeos
681e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
691e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#endif  // CHROMEOS_DBUS_FAKE_NFC_MANAGER_CLIENT_H_
70