- add sources.
[platform/framework/web/crosswalk.git] / src / chromeos / dbus / nfc_device_client.h
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 "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"
20
21 namespace chromeos {
22
23 class NfcAdapterClient;
24
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 {
28  public:
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;
33
34     Properties(dbus::ObjectProxy* object_proxy,
35                const PropertyChangedCallback& callback);
36     virtual ~Properties();
37   };
38
39   // Interface for observing changes from a remote NFC device.
40   class Observer {
41    public:
42     virtual ~Observer() {}
43
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) {}
47
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) {}
51
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) {}
56   };
57
58   // TODO(armansito): Move this typedef to the NFC Record client, once
59   // implemented.
60   typedef std::map<std::string, std::string> RecordAttributes;
61
62   virtual ~NfcDeviceClient();
63
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
66   // issuing the event.
67   virtual void AddObserver(Observer* observer) = 0;
68   virtual void RemoveObserver(Observer* observer) = 0;
69
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;
73
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:
82   //
83   //    {
84   //      "Type": "Text",
85   //      "Encoding": "UTF-8",
86   //      "Language": "en",
87   //      "Representation": "Chrome OS rulez!"
88   //    },
89   //    {
90   //      "Type": "URI",
91   //      "URI": "http://www.chromium.org"
92   //    },
93   //    etc.
94   virtual void Push(
95       const dbus::ObjectPath& object_path,
96       const RecordAttributes& attributes,
97       const base::Closure& callback,
98       const nfc_client_helpers::ErrorCallback& error_callback) = 0;
99
100   // Creates the instance.
101   static NfcDeviceClient* Create(DBusClientImplementationType type,
102                                  NfcAdapterClient* adapter_client);
103
104  protected:
105   friend class NfcClientTest;
106
107   NfcDeviceClient();
108
109  private:
110   DISALLOW_COPY_AND_ASSIGN(NfcDeviceClient);
111 };
112
113 }  // namespace chromeos
114
115 #endif  // CHROMEOS_DBUS_NFC_DEVICE_CLIENT_H_