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