• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef CHROMEOS_DBUS_FAKE_NFC_ADAPTER_CLIENT_H_
6 #define CHROMEOS_DBUS_FAKE_NFC_ADAPTER_CLIENT_H_
7 
8 #include <string>
9 
10 #include "base/memory/scoped_ptr.h"
11 #include "base/observer_list.h"
12 #include "chromeos/chromeos_export.h"
13 #include "chromeos/dbus/nfc_adapter_client.h"
14 #include "chromeos/dbus/nfc_client_helpers.h"
15 
16 namespace chromeos {
17 
18 // FakeNfcAdapterClient simulates the behavior of the NFC adapter objects
19 // and is used both in test cases in place of a mock and on the Linux desktop.
20 class CHROMEOS_EXPORT FakeNfcAdapterClient : public NfcAdapterClient {
21  public:
22   struct Properties : public NfcAdapterClient::Properties {
23     explicit Properties(const PropertyChangedCallback& callback);
24     virtual ~Properties();
25 
26     // dbus::PropertySet overrides.
27     virtual void Get(dbus::PropertyBase* property,
28                      dbus::PropertySet::GetCallback callback) OVERRIDE;
29     virtual void GetAll() OVERRIDE;
30     virtual void Set(dbus::PropertyBase* property,
31                      dbus::PropertySet::SetCallback callback) OVERRIDE;
32   };
33 
34   FakeNfcAdapterClient();
35   virtual ~FakeNfcAdapterClient();
36 
37   // NfcAdapterClient overrides.
38   virtual void Init(dbus::Bus* bus) OVERRIDE;
39   virtual void AddObserver(Observer* observer) OVERRIDE;
40   virtual void RemoveObserver(Observer* observer) OVERRIDE;
41   virtual std::vector<dbus::ObjectPath> GetAdapters() OVERRIDE;
42   virtual Properties* GetProperties(
43       const dbus::ObjectPath& object_path) OVERRIDE;
44   virtual void StartPollLoop(
45       const dbus::ObjectPath& object_path,
46       const std::string& mode,
47       const base::Closure& callback,
48       const nfc_client_helpers::ErrorCallback& error_callback) OVERRIDE;
49   virtual void StopPollLoop(
50       const dbus::ObjectPath& object_path,
51       const base::Closure& callback,
52       const nfc_client_helpers::ErrorCallback& error_callback) OVERRIDE;
53 
54   // Sets the adapter as |present|.
55   void SetAdapterPresent(bool present);
56   void SetSecondAdapterPresent(bool present);
57 
58   // The object paths for the adapters that are being emulated.
59   static const char kAdapterPath0[];
60   static const char kAdapterPath1[];
61 
62  private:
63   // Property changed callback passed when we create Properties* structures.
64   void OnPropertyChanged(const dbus::ObjectPath& object_path,
65                          const std::string& property_name);
66 
67   // List of observers interested in event notifications from us.
68   ObserverList<Observer> observers_;
69 
70   // Fake properties that are returned for the emulated adapters.
71   scoped_ptr<Properties> properties_;
72   scoped_ptr<Properties> second_properties_;
73 
74   // Whether the adapter and second adapter is present or not.
75   bool present_;
76   bool second_present_;
77 
78   DISALLOW_COPY_AND_ASSIGN(FakeNfcAdapterClient);
79 };
80 
81 }  // namespace chromeos
82 
83 #endif  // CHROMEOS_DBUS_FAKE_NFC_ADAPTER_CLIENT_H_
84