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_TAG_CLIENT_H_ | |
6 #define CHROMEOS_DBUS_NFC_TAG_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 // NfcTagClient is used to communicate with objects representing remote NFC | |
28 // tags. | |
29 class CHROMEOS_EXPORT NfcTagClient : public DBusClient { | |
30 public: | |
31 // Structure of properties associated with an NFC tag. | |
32 struct Properties : public NfcPropertySet { | |
33 // The NFC tag type. Possible values are "Type 1", "Type 2", "Type 3", | |
34 // and "Type 4". Read-only. | |
35 dbus::Property<std::string> type; | |
36 | |
37 // The NFC tag radio protocol. Possible values are "Felica", "MIFARE", | |
38 // "Jewel", "ISO-DEP", and "NFC-DEP". Read-only. | |
39 dbus::Property<std::string> protocol; | |
40 | |
41 // List of object paths for NDEF Records associated with the NFC tag. | |
42 // Read-only. | |
43 dbus::Property<std::vector<dbus::ObjectPath> > records; | |
44 | |
45 // The current status of the tag's read mode. Read-only. | |
46 dbus::Property<bool> read_only; | |
47 | |
48 Properties(dbus::ObjectProxy* object_proxy, | |
49 const PropertyChangedCallback& callback); | |
50 ~Properties() override; | |
51 }; | |
52 | |
53 // Interface for observing changes from a remote NFC tag. | |
54 class Observer { | |
55 public: | |
56 virtual ~Observer() {} | |
57 | |
58 // Called when a remote NFC tag with the object path |object_path| is added | |
59 // to the set of known tags. | |
60 virtual void TagAdded(const dbus::ObjectPath& object_path) {} | |
61 | |
62 // Called when a remote NFC tag with the object path |object_path| is | |
63 // removed from the set of known tags. | |
64 virtual void TagRemoved(const dbus::ObjectPath& object_path) {} | |
65 | |
66 // Called when the tag property with the name |property_name| on tag with | |
67 // object path |object_path| has acquired a new value. | |
68 virtual void TagPropertyChanged(const dbus::ObjectPath& object_path, | |
69 const std::string& property_name) {} | |
70 | |
71 // Called when all properties for the tag with object path |object_path| | |
72 // have been received. This method will be called after | |
73 // Observer::TagPropertyChanged has been called for all properties that | |
74 // were received through the initial property fetch that is done when the | |
75 // object proxy is first created or after a call to | |
76 // dbus::PropertySet::GetAll. Observers can use this method to be notified | |
77 // when all existing properties of a tag are available for use. | |
78 virtual void TagPropertiesReceived(const dbus::ObjectPath& object_path) {} | |
79 }; | |
80 | |
81 ~NfcTagClient() override; | |
82 | |
83 // Adds and removes observers for events on all remote NFC tags. Check the | |
84 // |object_path| parameter of observer methods to determine which tag is | |
85 // issuing the event. | |
86 virtual void AddObserver(Observer* observer) = 0; | |
87 virtual void RemoveObserver(Observer* observer) = 0; | |
88 | |
89 // Returns the list of tag object paths associated with the given adapter | |
90 // identified by the D-Bus object path |adapter_path|. | |
91 virtual std::vector<dbus::ObjectPath> GetTagsForAdapter( | |
92 const dbus::ObjectPath& adapter_path) = 0; | |
93 | |
94 // Obtain the properties for the NFC tag with object path |object_path|; any | |
95 // values should be copied if needed. | |
96 virtual Properties* GetProperties(const dbus::ObjectPath& object_path) = 0; | |
97 | |
98 // Creates an NDEF record for the NFC tag with object path |object_path| | |
99 // using the parameters in |attributes|. |attributes| is a dictionary, | |
100 // containing the NFC Record properties which will be assigned to the | |
101 // resulting record object and written to the tag. The properties are defined | |
102 // by the NFC Record interface (see namespace "nfc_record" in | |
103 // third_party/cros_system_api/dbus/service_constants.h and | |
104 // NfcRecordClient::Properties). |attributes| should at least contain a | |
105 // "Type" plus any other properties associated with that type. For example: | |
106 // | |
107 // { | |
108 // "Type": "Text", | |
109 // "Encoding": "UTF-8", | |
110 // "Language": "en", | |
111 // "Representation": "Chrome OS rulez!" | |
112 // }, | |
113 // { | |
114 // "Type": "URI", | |
115 // "URI": "http://www.chromium.org" | |
116 // }, | |
117 // etc. | |
118 virtual void Write( | |
119 const dbus::ObjectPath& object_path, | |
120 const base::DictionaryValue& attributes, | |
121 const base::Closure& callback, | |
122 const nfc_client_helpers::ErrorCallback& error_callback) = 0; | |
123 | |
124 // Creates the instance. | |
125 static NfcTagClient* Create(NfcAdapterClient* adapter_client); | |
126 | |
127 protected: | |
128 friend class NfcClientTest; | |
129 | |
130 NfcTagClient(); | |
131 | |
132 private: | |
133 DISALLOW_COPY_AND_ASSIGN(NfcTagClient); | |
134 }; | |
135 | |
136 } // namespace chromeos | |
137 | |
138 #endif // CHROMEOS_DBUS_NFC_TAG_CLIENT_H_ | |
OLD | NEW |