OLD | NEW |
| (Empty) |
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 "base/macros.h" | |
13 #include "chromeos/chromeos_export.h" | |
14 #include "chromeos/dbus/dbus_client.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. Read-only. | |
35 dbus::Property<std::string> mode; | |
36 | |
37 // The adapter's current power state. Read-write. | |
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". Read-only. | |
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". Read-only. | |
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. Read-only. | |
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. Read-only. | |
55 dbus::Property<std::vector<dbus::ObjectPath> > devices; | |
56 | |
57 Properties(dbus::ObjectProxy* object_proxy, | |
58 const PropertyChangedCallback& callback); | |
59 ~Properties() override; | |
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 ~NfcAdapterClient() override; | |
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 // Returns the list of adapter object paths known to the system. | |
90 virtual std::vector<dbus::ObjectPath> GetAdapters() = 0; | |
91 | |
92 // Obtains the properties for the adapter with object path |object_path|, any | |
93 // values should be copied if needed. A NULL pointer will be returned, if no | |
94 // adapter with the given object path is known to exist. | |
95 virtual Properties* GetProperties(const dbus::ObjectPath& object_path) = 0; | |
96 | |
97 // Starts the polling loop for the adapter with object path |object_path|. | |
98 // Depending on the mode, the adapter will start polling for targets, | |
99 // listening to NFC devices, or both. The |mode| parameter should be one of | |
100 // "Initiator", "Target", or "Dual". The "Dual" mode will have the adapter | |
101 // alternate between "Initiator" and "Target" modes during the polling loop. | |
102 // For any other value, the adapter will default to "Initiator" mode. | |
103 virtual void StartPollLoop( | |
104 const dbus::ObjectPath& object_path, | |
105 const std::string& mode, | |
106 const base::Closure& callback, | |
107 const nfc_client_helpers::ErrorCallback& error_callback) = 0; | |
108 | |
109 // Stops the polling loop for the adapter with object_path |object_path|. | |
110 virtual void StopPollLoop( | |
111 const dbus::ObjectPath& object_path, | |
112 const base::Closure& callback, | |
113 const nfc_client_helpers::ErrorCallback& error_callback) = 0; | |
114 | |
115 // Creates the instance. | |
116 static NfcAdapterClient* Create(NfcManagerClient* manager_client); | |
117 | |
118 protected: | |
119 friend class NfcClientTest; | |
120 | |
121 NfcAdapterClient(); | |
122 | |
123 private: | |
124 DISALLOW_COPY_AND_ASSIGN(NfcAdapterClient); | |
125 }; | |
126 | |
127 } // namespace chromeos | |
128 | |
129 #endif // CHROMEOS_DBUS_NFC_ADAPTER_CLIENT_H_ | |
OLD | NEW |