- add sources.
[platform/framework/web/crosswalk.git] / src / chromeos / dbus / nfc_tag_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_TAG_CLIENT_H_
6 #define CHROMEOS_DBUS_NFC_TAG_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 // NfcTagClient is used to communicate with objects representing remote NFC
26 // tags.
27 class CHROMEOS_EXPORT NfcTagClient : public DBusClient {
28  public:
29   // Structure of properties associated with an NFC tag.
30   struct Properties : public NfcPropertySet {
31     // The NFC tag type. Possible values are "Type 1", "Type 2", "Type 3",
32     // and "Type 4".
33     dbus::Property<std::string> type;
34
35     // The NFC tag radio protocol. Possible values are "Felica", "MIFARE",
36     // "Jewel", "ISO-DEP", and "NFC-DEP".
37     dbus::Property<std::string> protocol;
38
39     // List of object paths for NDEF Records associated with the NFC tag.
40     dbus::Property<std::vector<dbus::ObjectPath> > records;
41
42     // The current status of the tag's read mode.
43     dbus::Property<bool> read_only;
44
45     Properties(dbus::ObjectProxy* object_proxy,
46                const PropertyChangedCallback& callback);
47     virtual ~Properties();
48   };
49
50   // Interface for observing changes from a remote NFC tag.
51   class Observer {
52    public:
53     virtual ~Observer() {}
54
55     // Called when a remote NFC tag with the object path |object_path| is added
56     // to the set of known tags.
57     virtual void TagFound(const dbus::ObjectPath& object_path) {}
58
59     // Called when a remote NFC tag with the object path |object_path| is
60     // removed from the set of known tags.
61     virtual void TagLost(const dbus::ObjectPath& object_path) {}
62
63     // Called when the tag property with the name |property_name| on tag with
64     // object path |object_path| has acquired a new value.
65     virtual void TagPropertyChanged(const dbus::ObjectPath& object_path,
66                                     const std::string& property_name) {}
67   };
68
69   // TODO(armansito): Move this typedef to the NFC Record client, once
70   // implemented.
71   typedef std::map<std::string, std::string> RecordAttributes;
72
73   virtual ~NfcTagClient();
74
75   // Adds and removes observers for events on all remote NFC tags. Check the
76   // |object_path| parameter of observer methods to determine which tag is
77   // issuing the event.
78   virtual void AddObserver(Observer* observer) = 0;
79   virtual void RemoveObserver(Observer* observer) = 0;
80
81   // Obtain the properties for the NFC tag with object path |object_path|; any
82   // values should be copied if needed.
83   virtual Properties* GetProperties(const dbus::ObjectPath& object_path) = 0;
84
85   // Creates an NDEF record for the NFC tag with object path |object_path|
86   // using the parameters in |attributes|. |attributes| is a dictionary,
87   // containing the NFC Record properties which will be assigned to the
88   // resulting record object and written to the tag. The properties are defined
89   // by the NFC Record interface (see namespace "nfc_record" in
90   // third_party/cros_system_api/dbus/service_constants.h and
91   // NfcRecordClient::Properties). |attributes| should at least contain a
92   // "Type" plus any other properties associated with that type. For example:
93   //
94   //    {
95   //      "Type": "Text",
96   //      "Encoding": "UTF-8",
97   //      "Language": "en",
98   //      "Representation": "Chrome OS rulez!"
99   //    },
100   //    {
101   //      "Type": "URI",
102   //      "URI": "http://www.chromium.org"
103   //    },
104   //    etc.
105   virtual void Write(
106       const dbus::ObjectPath& object_path,
107       const RecordAttributes& attributes,
108       const base::Closure& callback,
109       const nfc_client_helpers::ErrorCallback& error_callback) = 0;
110
111   // Creates the instance.
112   static NfcTagClient* Create(DBusClientImplementationType type,
113                               NfcAdapterClient* adapter_client);
114
115  protected:
116   friend class NfcClientTest;
117
118   NfcTagClient();
119
120  private:
121   DISALLOW_COPY_AND_ASSIGN(NfcTagClient);
122 };
123
124 }  // namespace chromeos
125
126 #endif  // CHROMEOS_DBUS_NFC_TAG_CLIENT_H_