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_RECORD_CLIENT_H_ | |
6 #define CHROMEOS_DBUS_NFC_RECORD_CLIENT_H_ | |
7 | |
8 #include <stdint.h> | |
9 | |
10 #include <string> | |
11 | |
12 #include "base/macros.h" | |
13 #include "chromeos/chromeos_export.h" | |
14 #include "chromeos/dbus/dbus_client.h" | |
15 #include "chromeos/dbus/nfc_property_set.h" | |
16 #include "dbus/object_path.h" | |
17 #include "dbus/object_proxy.h" | |
18 #include "dbus/property.h" | |
19 | |
20 namespace chromeos { | |
21 | |
22 class NfcDeviceClient; | |
23 class NfcTagClient; | |
24 | |
25 // NfcRecordClient is used to communicate with objects representing NDEF | |
26 // records that are stored in remote NFC tags and devices. | |
27 class CHROMEOS_EXPORT NfcRecordClient : public DBusClient { | |
28 public: | |
29 // Structure of properties associated with an NFC record. | |
30 struct Properties : public NfcPropertySet { | |
31 // The NDEF record type. Possible values are "SmartPoster", "Text", "URI", | |
32 // "HandoverRequest", "HandoverSelect", "HandoverCarrier". Read-only. | |
33 dbus::Property<std::string> type; | |
34 | |
35 // The character encoding. Possible values are "UTF-8" or "UTF-16". | |
36 // This property is only valid for Text and SmartPoster's title records. | |
37 // Read-only. | |
38 dbus::Property<std::string> encoding; | |
39 | |
40 // The ISO/IANA language code (For example "en" or "jp"). This property is | |
41 // only valid for Text and SmartPoster's title records. | |
42 dbus::Property<std::string> language; | |
43 | |
44 // The human readable representation of a text or title record. | |
45 // This property is only valid for Text and SmartPoster's title records. | |
46 // Read-only. | |
47 dbus::Property<std::string> representation; | |
48 | |
49 // The record URI (for example https://nfc-forum.org). This is the complete | |
50 // URI, including the scheme and the resource. This property is only valid | |
51 // for SmartPoster's URI type records. | |
52 // Read-only. | |
53 dbus::Property<std::string> uri; | |
54 | |
55 // The URI object MIME type. This is a description of the MIME type of the | |
56 // object the URI points at. This is not a mandatory field and is only | |
57 // valid for SmartPosters carrying a URI record. | |
58 // Read-only. | |
59 dbus::Property<std::string> mime_type; | |
60 | |
61 // The URI object size. This is the size of the object the URI points at. | |
62 // It should be used by applications to decide if they can afford to fetch | |
63 // the object or not. This is not a mandatory field and is only valid for | |
64 // Smart Posters carrying a URI record. | |
65 // Read-only. | |
66 dbus::Property<uint32_t> size; | |
67 | |
68 // The suggested course of action. This one is only valid for Smart Posters | |
69 // and is a suggestion only. It can be ignored, and the possible values are | |
70 // "Do" (for example launch the browser), "Save" (for example save the URI | |
71 // in the bookmarks folder), or "Edit" (for example open the URI in an URI | |
72 // editor for the user to modify it). | |
73 dbus::Property<std::string> action; | |
74 | |
75 Properties(dbus::ObjectProxy* object_proxy, | |
76 const PropertyChangedCallback& callback); | |
77 ~Properties() override; | |
78 }; | |
79 | |
80 // Interface for observing changes from a remote NFC NDEF record. | |
81 class Observer { | |
82 public: | |
83 virtual ~Observer() {} | |
84 | |
85 // Called when a remote NFC record with the object path |object_path| is | |
86 // added to the set of known records. | |
87 virtual void RecordAdded(const dbus::ObjectPath& object_path) {} | |
88 | |
89 // Called when a remote NFC record with the object path |object_path| is | |
90 // removed from the set of known records. | |
91 virtual void RecordRemoved(const dbus::ObjectPath& object_path) {} | |
92 | |
93 // Called when the record property with the name |property_name| on record | |
94 // with object path |object_path| has acquired a new value. | |
95 virtual void RecordPropertyChanged(const dbus::ObjectPath& object_path, | |
96 const std::string& property_name) {} | |
97 | |
98 // Called when all properties for the record with object path |object_path| | |
99 // have been received. This method will be called after | |
100 // Observer::RecordPropertyChanged has been called for all properties that | |
101 // were received through the initial property fetch that is done when the | |
102 // object proxy is first created or after a call to | |
103 // dbus::PropertySet::GetAll Observers can use this method to be notified | |
104 // when all existing properties of a record are available for use. | |
105 virtual void RecordPropertiesReceived( | |
106 const dbus::ObjectPath& object_path) {} | |
107 }; | |
108 | |
109 ~NfcRecordClient() override; | |
110 | |
111 // Adds and removes observers for events on all remote NFC records. Check the | |
112 // |object_path| parameter of observer methods to determine which record is | |
113 // issuing the event. | |
114 virtual void AddObserver(Observer* observer) = 0; | |
115 virtual void RemoveObserver(Observer* observer) = 0; | |
116 | |
117 // Returns the list of record object paths associated with the given device | |
118 // identified by the D-Bus object path |device_path|. | |
119 virtual std::vector<dbus::ObjectPath> GetRecordsForDevice( | |
120 const dbus::ObjectPath& device_path) = 0; | |
121 | |
122 // Returns the list of record object paths associated with the given tag | |
123 // identified by the D-Bus object path |tag_path|. | |
124 virtual std::vector<dbus::ObjectPath> GetRecordsForTag( | |
125 const dbus::ObjectPath& tag_path) = 0; | |
126 | |
127 // Obtain the properties for the NFC record with object path |object_path|; | |
128 // any values should be copied if needed. | |
129 virtual Properties* GetProperties(const dbus::ObjectPath& object_path) = 0; | |
130 | |
131 // Creates the instance. | |
132 static NfcRecordClient* Create(NfcDeviceClient* device_client, | |
133 NfcTagClient* tag_client); | |
134 | |
135 protected: | |
136 friend class NfcClientTest; | |
137 | |
138 NfcRecordClient(); | |
139 | |
140 private: | |
141 DISALLOW_COPY_AND_ASSIGN(NfcRecordClient); | |
142 }; | |
143 | |
144 } // namespace chromeos | |
145 | |
146 #endif // CHROMEOS_DBUS_NFC_RECORD_CLIENT_H_ | |
OLD | NEW |