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 // Called when all properties for the tag with object path |object_path| 71 // have been received. This method will be called after 72 // Observer::TagPropertyChanged has been called for all properties that 73 // were received through the initial property fetch that is done when the 74 // object proxy is first created or after a call to 75 // dbus::PropertySet::GetAll. Observers can use this method to be notified 76 // when all existing properties of a tag are available for use. 77 virtual void TagPropertiesReceived(const dbus::ObjectPath& object_path) {} 78 }; 79 80 virtual ~NfcTagClient(); 81 82 // Adds and removes observers for events on all remote NFC tags. Check the 83 // |object_path| parameter of observer methods to determine which tag is 84 // issuing the event. 85 virtual void AddObserver(Observer* observer) = 0; 86 virtual void RemoveObserver(Observer* observer) = 0; 87 88 // Returns the list of tag object paths associated with the given adapter 89 // identified by the D-Bus object path |adapter_path|. 90 virtual std::vector<dbus::ObjectPath> GetTagsForAdapter( 91 const dbus::ObjectPath& adapter_path) = 0; 92 93 // Obtain the properties for the NFC tag with object path |object_path|; any 94 // values should be copied if needed. 95 virtual Properties* GetProperties(const dbus::ObjectPath& object_path) = 0; 96 97 // Creates an NDEF record for the NFC tag with object path |object_path| 98 // using the parameters in |attributes|. |attributes| is a dictionary, 99 // containing the NFC Record properties which will be assigned to the 100 // resulting record object and written to the tag. The properties are defined 101 // by the NFC Record interface (see namespace "nfc_record" in 102 // third_party/cros_system_api/dbus/service_constants.h and 103 // NfcRecordClient::Properties). |attributes| should at least contain a 104 // "Type" plus any other properties associated with that type. For example: 105 // 106 // { 107 // "Type": "Text", 108 // "Encoding": "UTF-8", 109 // "Language": "en", 110 // "Representation": "Chrome OS rulez!" 111 // }, 112 // { 113 // "Type": "URI", 114 // "URI": "http://www.chromium.org" 115 // }, 116 // etc. 117 virtual void Write( 118 const dbus::ObjectPath& object_path, 119 const base::DictionaryValue& attributes, 120 const base::Closure& callback, 121 const nfc_client_helpers::ErrorCallback& error_callback) = 0; 122 123 // Creates the instance. 124 static NfcTagClient* Create(NfcAdapterClient* adapter_client); 125 126 protected: 127 friend class NfcClientTest; 128 129 NfcTagClient(); 130 131 private: 132 DISALLOW_COPY_AND_ASSIGN(NfcTagClient); 133}; 134 135} // namespace chromeos 136 137#endif // CHROMEOS_DBUS_NFC_TAG_CLIENT_H_ 138