10f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved. 20f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 30f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)// found in the LICENSE file. 40f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 50f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#ifndef CHROMEOS_DBUS_NFC_TAG_CLIENT_H_ 60f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#define CHROMEOS_DBUS_NFC_TAG_CLIENT_H_ 70f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 80f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include <map> 90f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include <string> 100f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include <vector> 110f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 12a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "base/values.h" 130f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "chromeos/chromeos_export.h" 140f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "chromeos/dbus/dbus_client.h" 150f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "chromeos/dbus/nfc_client_helpers.h" 160f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "chromeos/dbus/nfc_property_set.h" 17f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "chromeos/dbus/nfc_record_client.h" 180f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "dbus/object_path.h" 190f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "dbus/object_proxy.h" 200f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "dbus/property.h" 210f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 220f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)namespace chromeos { 230f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 240f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)class NfcAdapterClient; 250f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 260f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)// NfcTagClient is used to communicate with objects representing remote NFC 270f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)// tags. 280f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)class CHROMEOS_EXPORT NfcTagClient : public DBusClient { 290f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) public: 300f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // Structure of properties associated with an NFC tag. 310f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) struct Properties : public NfcPropertySet { 320f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // The NFC tag type. Possible values are "Type 1", "Type 2", "Type 3", 33f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // and "Type 4". Read-only. 340f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) dbus::Property<std::string> type; 350f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 360f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // The NFC tag radio protocol. Possible values are "Felica", "MIFARE", 37f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // "Jewel", "ISO-DEP", and "NFC-DEP". Read-only. 380f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) dbus::Property<std::string> protocol; 390f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 400f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // List of object paths for NDEF Records associated with the NFC tag. 41f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Read-only. 420f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) dbus::Property<std::vector<dbus::ObjectPath> > records; 430f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 44f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // The current status of the tag's read mode. Read-only. 450f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) dbus::Property<bool> read_only; 460f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 470f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) Properties(dbus::ObjectProxy* object_proxy, 480f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) const PropertyChangedCallback& callback); 490f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) virtual ~Properties(); 500f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) }; 510f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 520f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // Interface for observing changes from a remote NFC tag. 530f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) class Observer { 540f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) public: 550f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) virtual ~Observer() {} 560f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 570f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // Called when a remote NFC tag with the object path |object_path| is added 580f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // to the set of known tags. 59f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) virtual void TagAdded(const dbus::ObjectPath& object_path) {} 600f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 610f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // Called when a remote NFC tag with the object path |object_path| is 620f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // removed from the set of known tags. 63f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) virtual void TagRemoved(const dbus::ObjectPath& object_path) {} 640f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 650f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // Called when the tag property with the name |property_name| on tag with 660f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // object path |object_path| has acquired a new value. 670f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) virtual void TagPropertyChanged(const dbus::ObjectPath& object_path, 680f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) const std::string& property_name) {} 690f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) }; 700f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 710f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) virtual ~NfcTagClient(); 720f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 730f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // Adds and removes observers for events on all remote NFC tags. Check the 740f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // |object_path| parameter of observer methods to determine which tag is 750f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // issuing the event. 760f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) virtual void AddObserver(Observer* observer) = 0; 770f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) virtual void RemoveObserver(Observer* observer) = 0; 780f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 790f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // Obtain the properties for the NFC tag with object path |object_path|; any 800f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // values should be copied if needed. 810f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) virtual Properties* GetProperties(const dbus::ObjectPath& object_path) = 0; 820f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 830f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // Creates an NDEF record for the NFC tag with object path |object_path| 840f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // using the parameters in |attributes|. |attributes| is a dictionary, 850f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // containing the NFC Record properties which will be assigned to the 860f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // resulting record object and written to the tag. The properties are defined 870f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // by the NFC Record interface (see namespace "nfc_record" in 880f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // third_party/cros_system_api/dbus/service_constants.h and 890f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // NfcRecordClient::Properties). |attributes| should at least contain a 900f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // "Type" plus any other properties associated with that type. For example: 910f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // 920f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // { 930f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // "Type": "Text", 940f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // "Encoding": "UTF-8", 950f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // "Language": "en", 960f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // "Representation": "Chrome OS rulez!" 970f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // }, 980f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // { 990f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // "Type": "URI", 1000f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // "URI": "http://www.chromium.org" 1010f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // }, 1020f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // etc. 1030f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) virtual void Write( 1040f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) const dbus::ObjectPath& object_path, 105a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const base::DictionaryValue& attributes, 1060f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) const base::Closure& callback, 1070f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) const nfc_client_helpers::ErrorCallback& error_callback) = 0; 1080f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 1090f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // Creates the instance. 110a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) static NfcTagClient* Create(NfcAdapterClient* adapter_client); 1110f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 1120f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) protected: 1130f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) friend class NfcClientTest; 1140f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 1150f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) NfcTagClient(); 1160f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 1170f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) private: 1180f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(NfcTagClient); 1190f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)}; 1200f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 1210f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)} // namespace chromeos 1220f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 1230f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#endif // CHROMEOS_DBUS_NFC_TAG_CLIENT_H_ 124