- add sources.
[platform/framework/web/crosswalk.git] / src / chromeos / dbus / nfc_adapter_client.h
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_NFC_ADAPTER_CLIENT_H_
6 #define CHROMEOS_DBUS_NFC_ADAPTER_CLIENT_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/callback.h"
12 #include "chromeos/chromeos_export.h"
13 #include "chromeos/dbus/dbus_client.h"
14 #include "chromeos/dbus/dbus_client_implementation_type.h"
15 #include "chromeos/dbus/nfc_client_helpers.h"
16 #include "chromeos/dbus/nfc_property_set.h"
17 #include "dbus/object_path.h"
18 #include "dbus/object_proxy.h"
19 #include "dbus/property.h"
20
21 namespace chromeos {
22
23 class NfcManagerClient;
24
25 // NfcAdapterClient is used to communicate with objects representing local NFC
26 // adapters.
27 class CHROMEOS_EXPORT NfcAdapterClient : public DBusClient {
28  public:
29   // Structure of properties associated with an NFC adapter.
30   struct Properties : public NfcPropertySet {
31     // The adapter NFC radio mode. One of "Initiator", "Target", and "Idle".
32     // The NFC adapter will usually be in the "Idle" mode. The mode will change
33     // to "Initiator" or "Target" based on how a pairing is established with a
34     // remote tag or device.
35     dbus::Property<std::string> mode;
36
37     // The adapter's current power state.
38     dbus::Property<bool> powered;
39
40     // Indicates whether or not the adapter is currently polling for targets.
41     // This property is only valid when |mode| is "Initiator".
42     dbus::Property<bool> polling;
43
44     // The NFC protocols that are supported by the adapter. Possible values
45     // are: "Felica", "MIFARE", "Jewel", "ISO-DEP", and "NFC-DEP".
46     dbus::Property<std::vector<std::string> > protocols;
47
48     // The object paths of the NFC tags that are known to the local adapter.
49     // These are tags that have been "tapped" on the local adapter.
50     dbus::Property<std::vector<dbus::ObjectPath> > tags;
51
52     // The object paths of the remote NFC devices that have been found by the
53     // local adapter. These are NFC adapters that were "tapped" on the local
54     // adapter.
55     dbus::Property<std::vector<dbus::ObjectPath> > devices;
56
57     Properties(dbus::ObjectProxy* object_proxy,
58                const PropertyChangedCallback& callback);
59     virtual ~Properties();
60   };
61
62   // Interface for observing changes from a local NFC adapter.
63   class Observer {
64    public:
65     virtual ~Observer() {}
66
67     // Called when a new adapter with object path |object_path| is added to the
68     // system.
69     virtual void AdapterAdded(const dbus::ObjectPath& object_path) {}
70
71     // Called when an adapter with object path |object_path| is removed from the
72     // system.
73     virtual void AdapterRemoved(const dbus::ObjectPath& object_path) {}
74
75     // Called when the adapter property with the name |property_name| on adapter
76     // with object path |object_path| has acquired a new value.
77     virtual void AdapterPropertyChanged(const dbus::ObjectPath& object_path,
78                                         const std::string& property_name) {}
79   };
80
81   virtual ~NfcAdapterClient();
82
83   // Adds and removes observers for events on all local bluetooth adapters.
84   // Check the |object_path| parameter of the observer methods to determine
85   // which adapter is issuing the event.
86   virtual void AddObserver(Observer* observer) = 0;
87   virtual void RemoveObserver(Observer* observer) = 0;
88
89   // Obtains the properties for the adapter with object path |object_path|, any
90   // values should be copied if needed. A NULL pointer will be returned, if no
91   // adapter with the given object path is known to exist.
92   virtual Properties* GetProperties(const dbus::ObjectPath& object_path) = 0;
93
94   // Starts the polling loop for the adapter with object path |object_path|.
95   // Depending on the mode, the adapter will start polling for targets,
96   // listening to NFC devices, or both. The |mode| parameter should be one of
97   // "Initiator", "Target", or "Dual". The "Dual" mode will have the adapter
98   // alternate between "Initiator" and "Target" modes during the polling loop.
99   // For any other value, the adapter will default to "Initiator" mode.
100   virtual void StartPollLoop(
101       const dbus::ObjectPath& object_path,
102       const std::string& mode,
103       const base::Closure& callback,
104       const nfc_client_helpers::ErrorCallback& error_callback) = 0;
105
106   // Stops the polling loop for the adapter with object_path |object_path|.
107   virtual void StopPollLoop(
108       const dbus::ObjectPath& object_path,
109       const base::Closure& callback,
110       const nfc_client_helpers::ErrorCallback& error_callback) = 0;
111
112   // Creates the instance.
113   static NfcAdapterClient* Create(DBusClientImplementationType type,
114                                   NfcManagerClient* manager_client);
115
116  protected:
117   friend class NfcClientTest;
118
119   NfcAdapterClient();
120
121  private:
122   DISALLOW_COPY_AND_ASSIGN(NfcAdapterClient);
123 };
124
125 }  // namespace chromeos
126
127 #endif   // CHROMEOS_DBUS_NFC_ADAPTER_CLIENT_H_