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_DEVICE_CLIENT_H_ | |
6 #define CHROMEOS_DBUS_NFC_DEVICE_CLIENT_H_ | |
7 | |
8 #include <map> | |
9 #include <string> | |
10 #include <vector> | |
11 | |
12 #include "base/macros.h" | |
13 #include "base/values.h" | |
14 #include "chromeos/chromeos_export.h" | |
15 #include "chromeos/dbus/dbus_client.h" | |
16 #include "chromeos/dbus/nfc_client_helpers.h" | |
17 #include "chromeos/dbus/nfc_property_set.h" | |
18 #include "chromeos/dbus/nfc_record_client.h" | |
19 #include "dbus/object_path.h" | |
20 #include "dbus/object_proxy.h" | |
21 #include "dbus/property.h" | |
22 | |
23 namespace chromeos { | |
24 | |
25 class NfcAdapterClient; | |
26 | |
27 // NfcDeviceClient is used to communicate with objects representing remote NFC | |
28 // devices that can be communicated with. | |
29 class CHROMEOS_EXPORT NfcDeviceClient : public DBusClient { | |
30 public: | |
31 // Structure of properties associated with an NFC device. | |
32 struct Properties : public NfcPropertySet { | |
33 // List of object paths for NDEF records associated with the NFC device. | |
34 // Read-only. | |
35 dbus::Property<std::vector<dbus::ObjectPath> > records; | |
36 | |
37 Properties(dbus::ObjectProxy* object_proxy, | |
38 const PropertyChangedCallback& callback); | |
39 ~Properties() override; | |
40 }; | |
41 | |
42 // Interface for observing changes from a remote NFC device. | |
43 class Observer { | |
44 public: | |
45 virtual ~Observer() {} | |
46 | |
47 // Called when a remote NFC device with the object |object_path| is added | |
48 // to the set of known devices. | |
49 virtual void DeviceAdded(const dbus::ObjectPath& object_path) {} | |
50 | |
51 // Called when a remote NFC device with the object path |object_path| is | |
52 // removed from the set of known devices. | |
53 virtual void DeviceRemoved(const dbus::ObjectPath& object_path) {} | |
54 | |
55 // Called when the device property with the name |property_name| on device | |
56 // with object path |object_path| has acquired a new value. | |
57 virtual void DevicePropertyChanged(const dbus::ObjectPath& object_path, | |
58 const std::string& property_name) {} | |
59 }; | |
60 | |
61 ~NfcDeviceClient() override; | |
62 | |
63 // Adds and removes observers for events on all remote NFC devices. Check the | |
64 // |object_path| parameter of observer methods to determine which device is | |
65 // issuing the event. | |
66 virtual void AddObserver(Observer* observer) = 0; | |
67 virtual void RemoveObserver(Observer* observer) = 0; | |
68 | |
69 // Returns the list of device object paths associated with the given adapter | |
70 // identified by the D-Bus object path |adapter_path|. | |
71 virtual std::vector<dbus::ObjectPath> GetDevicesForAdapter( | |
72 const dbus::ObjectPath& adapter_path) = 0; | |
73 | |
74 // Obtain the properties for the NFC device with object path |object_path|; | |
75 // any values should be copied if needed. | |
76 virtual Properties* GetProperties(const dbus::ObjectPath& object_path) = 0; | |
77 | |
78 // Creates an NDEF record for the NFC device with object path |object_path| | |
79 // using the parameters in |attributes|. |attributes| is a dictionary, | |
80 // containing the NFC Record properties which will be assigned to the | |
81 // resulting record object and pushed to the device. The properties are | |
82 // defined by the NFC Record interface (see namespace "nfc_record" in | |
83 // third_party/cros_system_api/dbus/service_constants.h and | |
84 // NfcRecordClient::Properties). |attributes| should at least contain a | |
85 // "Type" plus any other properties associated with that type. For example: | |
86 // | |
87 // { | |
88 // "Type": "Text", | |
89 // "Encoding": "UTF-8", | |
90 // "Language": "en", | |
91 // "Representation": "Chrome OS rulez!" | |
92 // }, | |
93 // { | |
94 // "Type": "URI", | |
95 // "URI": "http://www.chromium.org" | |
96 // }, | |
97 // etc. | |
98 virtual void Push( | |
99 const dbus::ObjectPath& object_path, | |
100 const base::DictionaryValue& attributes, | |
101 const base::Closure& callback, | |
102 const nfc_client_helpers::ErrorCallback& error_callback) = 0; | |
103 | |
104 // Creates the instance. | |
105 static NfcDeviceClient* Create(NfcAdapterClient* adapter_client); | |
106 | |
107 protected: | |
108 friend class NfcClientTest; | |
109 | |
110 NfcDeviceClient(); | |
111 | |
112 private: | |
113 DISALLOW_COPY_AND_ASSIGN(NfcDeviceClient); | |
114 }; | |
115 | |
116 } // namespace chromeos | |
117 | |
118 #endif // CHROMEOS_DBUS_NFC_DEVICE_CLIENT_H_ | |
OLD | NEW |