11e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved. 21e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 31e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// found in the LICENSE file. 41e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 51e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#ifndef CHROMEOS_DBUS_NFC_ADAPTER_CLIENT_H_ 61e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#define CHROMEOS_DBUS_NFC_ADAPTER_CLIENT_H_ 71e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 81e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include <string> 91e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include <vector> 101e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "base/callback.h" 121e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "chromeos/chromeos_export.h" 131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "chromeos/dbus/dbus_client.h" 141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "chromeos/dbus/nfc_client_helpers.h" 151e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "chromeos/dbus/nfc_property_set.h" 161e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "dbus/object_path.h" 171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "dbus/object_proxy.h" 181e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "dbus/property.h" 191e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)namespace chromeos { 211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class NfcManagerClient; 231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// NfcAdapterClient is used to communicate with objects representing local NFC 251e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// adapters. 261e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class CHROMEOS_EXPORT NfcAdapterClient : public DBusClient { 271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) public: 281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Structure of properties associated with an NFC adapter. 291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) struct Properties : public NfcPropertySet { 301e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // The adapter NFC radio mode. One of "Initiator", "Target", and "Idle". 311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // The NFC adapter will usually be in the "Idle" mode. The mode will change 321e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // to "Initiator" or "Target" based on how a pairing is established with a 33f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // remote tag or device. Read-only. 341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) dbus::Property<std::string> mode; 351e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 36f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // The adapter's current power state. Read-write. 371e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) dbus::Property<bool> powered; 381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 391e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Indicates whether or not the adapter is currently polling for targets. 40f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // This property is only valid when |mode| is "Initiator". Read-only. 411e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) dbus::Property<bool> polling; 421e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 431e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // The NFC protocols that are supported by the adapter. Possible values 44f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // are: "Felica", "MIFARE", "Jewel", "ISO-DEP", and "NFC-DEP". Read-only. 451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) dbus::Property<std::vector<std::string> > protocols; 461e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 471e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // The object paths of the NFC tags that are known to the local adapter. 48f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // These are tags that have been "tapped" on the local adapter. Read-only. 491e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) dbus::Property<std::vector<dbus::ObjectPath> > tags; 501e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 511e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // The object paths of the remote NFC devices that have been found by the 521e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // local adapter. These are NFC adapters that were "tapped" on the local 53f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // adapter. Read-only. 541e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) dbus::Property<std::vector<dbus::ObjectPath> > devices; 551e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 561e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) Properties(dbus::ObjectProxy* object_proxy, 571e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) const PropertyChangedCallback& callback); 581e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) virtual ~Properties(); 591e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) }; 601e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 611e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Interface for observing changes from a local NFC adapter. 621e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) class Observer { 631e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) public: 641e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) virtual ~Observer() {} 651e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 661e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Called when a new adapter with object path |object_path| is added to the 671e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // system. 681e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) virtual void AdapterAdded(const dbus::ObjectPath& object_path) {} 691e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 701e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Called when an adapter with object path |object_path| is removed from the 711e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // system. 721e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) virtual void AdapterRemoved(const dbus::ObjectPath& object_path) {} 731e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 741e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Called when the adapter property with the name |property_name| on adapter 751e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // with object path |object_path| has acquired a new value. 761e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) virtual void AdapterPropertyChanged(const dbus::ObjectPath& object_path, 771e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) const std::string& property_name) {} 781e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) }; 791e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 801e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) virtual ~NfcAdapterClient(); 811e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 821e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Adds and removes observers for events on all local bluetooth adapters. 831e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Check the |object_path| parameter of the observer methods to determine 841e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // which adapter is issuing the event. 851e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) virtual void AddObserver(Observer* observer) = 0; 861e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) virtual void RemoveObserver(Observer* observer) = 0; 871e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 88a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Returns the list of adapter object paths known to the system. 89a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) virtual std::vector<dbus::ObjectPath> GetAdapters() = 0; 90a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 911e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Obtains the properties for the adapter with object path |object_path|, any 921e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // values should be copied if needed. A NULL pointer will be returned, if no 931e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // adapter with the given object path is known to exist. 941e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) virtual Properties* GetProperties(const dbus::ObjectPath& object_path) = 0; 951e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 961e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Starts the polling loop for the adapter with object path |object_path|. 971e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Depending on the mode, the adapter will start polling for targets, 981e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // listening to NFC devices, or both. The |mode| parameter should be one of 991e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // "Initiator", "Target", or "Dual". The "Dual" mode will have the adapter 1001e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // alternate between "Initiator" and "Target" modes during the polling loop. 1011e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // For any other value, the adapter will default to "Initiator" mode. 1021e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) virtual void StartPollLoop( 1031e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) const dbus::ObjectPath& object_path, 1041e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) const std::string& mode, 1051e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) const base::Closure& callback, 1061e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) const nfc_client_helpers::ErrorCallback& error_callback) = 0; 1071e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1081e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Stops the polling loop for the adapter with object_path |object_path|. 1091e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) virtual void StopPollLoop( 1101e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) const dbus::ObjectPath& object_path, 1111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) const base::Closure& callback, 1121e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) const nfc_client_helpers::ErrorCallback& error_callback) = 0; 1131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Creates the instance. 115a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) static NfcAdapterClient* Create(NfcManagerClient* manager_client); 1161e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) protected: 1181e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) friend class NfcClientTest; 1191e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) NfcAdapterClient(); 1211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) private: 1231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(NfcAdapterClient); 1241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}; 1251e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1261e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} // namespace chromeos 1271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#endif // CHROMEOS_DBUS_NFC_ADAPTER_CLIENT_H_ 129