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