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.
5 #ifndef CHROMEOS_DBUS_NFC_DEVICE_CLIENT_H_
6 #define CHROMEOS_DBUS_NFC_DEVICE_CLIENT_H_
12 #include "chromeos/chromeos_export.h"
13 #include "chromeos/dbus/dbus_client.h"
14 #include "chromeos/dbus/dbus_client_implementation_type.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"
23 class NfcAdapterClient;
25 // NfcDeviceClient is used to communicate with objects representing remote NFC
26 // devices that can be communicated with.
27 class CHROMEOS_EXPORT NfcDeviceClient : public DBusClient {
29 // Structure of properties associated with an NFC device.
30 struct Properties : public NfcPropertySet {
31 // List of object paths for NDEF records associated with the NFC device.
32 dbus::Property<std::vector<dbus::ObjectPath> > records;
34 Properties(dbus::ObjectProxy* object_proxy,
35 const PropertyChangedCallback& callback);
36 virtual ~Properties();
39 // Interface for observing changes from a remote NFC device.
42 virtual ~Observer() {}
44 // Called when a remote NFC device with the object |object_path| is added
45 // to the set of known devices.
46 virtual void DeviceFound(const dbus::ObjectPath& object_path) {}
48 // Called when a remote NFC device with the object path |object_path| is
49 // removed from the set of known devices.
50 virtual void DeviceLost(const dbus::ObjectPath& object_path) {}
52 // Called when the device property with the name |property_name| on device
53 // with object path |object_path| has acquired a new value.
54 virtual void DevicePropertyChanged(const dbus::ObjectPath& object_path,
55 const std::string& property_name) {}
58 // TODO(armansito): Move this typedef to the NFC Record client, once
60 typedef std::map<std::string, std::string> RecordAttributes;
62 virtual ~NfcDeviceClient();
64 // Adds and removes observers for events on all remote NFC devices. Check the
65 // |object_path| parameter of observer methods to determine which device is
67 virtual void AddObserver(Observer* observer) = 0;
68 virtual void RemoveObserver(Observer* observer) = 0;
70 // Obtain the properties for the NFC device with object path |object_path|;
71 // any values should be copied if needed.
72 virtual Properties* GetProperties(const dbus::ObjectPath& object_path) = 0;
74 // Creates an NDEF record for the NFC device with object path |object_path|
75 // using the parameters in |attributes|. |attributes| is a dictionary,
76 // containing the NFC Record properties which will be assigned to the
77 // resulting record object and pushed to the device. The properties are
78 // defined by the NFC Record interface (see namespace "nfc_record" in
79 // third_party/cros_system_api/dbus/service_constants.h and
80 // NfcRecordClient::Properties). |attributes| should at least contain a
81 // "Type" plus any other properties associated with that type. For example:
85 // "Encoding": "UTF-8",
87 // "Representation": "Chrome OS rulez!"
91 // "URI": "http://www.chromium.org"
95 const dbus::ObjectPath& object_path,
96 const RecordAttributes& attributes,
97 const base::Closure& callback,
98 const nfc_client_helpers::ErrorCallback& error_callback) = 0;
100 // Creates the instance.
101 static NfcDeviceClient* Create(DBusClientImplementationType type,
102 NfcAdapterClient* adapter_client);
105 friend class NfcClientTest;
110 DISALLOW_COPY_AND_ASSIGN(NfcDeviceClient);
113 } // namespace chromeos
115 #endif // CHROMEOS_DBUS_NFC_DEVICE_CLIENT_H_