Revert of Revert of Revert of Revert of Revert of Enable ServiceWorkerPerfTest (servi...
[chromium-blink-merge.git] / chromeos / dbus / nfc_adapter_client.h
blob51cf24d5abbe45057583f5169574d1c8e6d6f4ed
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.
5 #ifndef CHROMEOS_DBUS_NFC_ADAPTER_CLIENT_H_
6 #define CHROMEOS_DBUS_NFC_ADAPTER_CLIENT_H_
8 #include <string>
9 #include <vector>
11 #include "base/callback.h"
12 #include "chromeos/chromeos_export.h"
13 #include "chromeos/dbus/dbus_client.h"
14 #include "chromeos/dbus/nfc_client_helpers.h"
15 #include "chromeos/dbus/nfc_property_set.h"
16 #include "dbus/object_path.h"
17 #include "dbus/object_proxy.h"
18 #include "dbus/property.h"
20 namespace chromeos {
22 class NfcManagerClient;
24 // NfcAdapterClient is used to communicate with objects representing local NFC
25 // adapters.
26 class CHROMEOS_EXPORT NfcAdapterClient : public DBusClient {
27 public:
28 // Structure of properties associated with an NFC adapter.
29 struct Properties : public NfcPropertySet {
30 // The adapter NFC radio mode. One of "Initiator", "Target", and "Idle".
31 // The NFC adapter will usually be in the "Idle" mode. The mode will change
32 // to "Initiator" or "Target" based on how a pairing is established with a
33 // remote tag or device. Read-only.
34 dbus::Property<std::string> mode;
36 // The adapter's current power state. Read-write.
37 dbus::Property<bool> powered;
39 // Indicates whether or not the adapter is currently polling for targets.
40 // This property is only valid when |mode| is "Initiator". Read-only.
41 dbus::Property<bool> polling;
43 // The NFC protocols that are supported by the adapter. Possible values
44 // are: "Felica", "MIFARE", "Jewel", "ISO-DEP", and "NFC-DEP". Read-only.
45 dbus::Property<std::vector<std::string> > protocols;
47 // The object paths of the NFC tags that are known to the local adapter.
48 // These are tags that have been "tapped" on the local adapter. Read-only.
49 dbus::Property<std::vector<dbus::ObjectPath> > tags;
51 // The object paths of the remote NFC devices that have been found by the
52 // local adapter. These are NFC adapters that were "tapped" on the local
53 // adapter. Read-only.
54 dbus::Property<std::vector<dbus::ObjectPath> > devices;
56 Properties(dbus::ObjectProxy* object_proxy,
57 const PropertyChangedCallback& callback);
58 ~Properties() override;
61 // Interface for observing changes from a local NFC adapter.
62 class Observer {
63 public:
64 virtual ~Observer() {}
66 // Called when a new adapter with object path |object_path| is added to the
67 // system.
68 virtual void AdapterAdded(const dbus::ObjectPath& object_path) {}
70 // Called when an adapter with object path |object_path| is removed from the
71 // system.
72 virtual void AdapterRemoved(const dbus::ObjectPath& object_path) {}
74 // Called when the adapter property with the name |property_name| on adapter
75 // with object path |object_path| has acquired a new value.
76 virtual void AdapterPropertyChanged(const dbus::ObjectPath& object_path,
77 const std::string& property_name) {}
80 ~NfcAdapterClient() override;
82 // Adds and removes observers for events on all local bluetooth adapters.
83 // Check the |object_path| parameter of the observer methods to determine
84 // which adapter is issuing the event.
85 virtual void AddObserver(Observer* observer) = 0;
86 virtual void RemoveObserver(Observer* observer) = 0;
88 // Returns the list of adapter object paths known to the system.
89 virtual std::vector<dbus::ObjectPath> GetAdapters() = 0;
91 // Obtains the properties for the adapter with object path |object_path|, any
92 // values should be copied if needed. A NULL pointer will be returned, if no
93 // adapter with the given object path is known to exist.
94 virtual Properties* GetProperties(const dbus::ObjectPath& object_path) = 0;
96 // Starts the polling loop for the adapter with object path |object_path|.
97 // Depending on the mode, the adapter will start polling for targets,
98 // listening to NFC devices, or both. The |mode| parameter should be one of
99 // "Initiator", "Target", or "Dual". The "Dual" mode will have the adapter
100 // alternate between "Initiator" and "Target" modes during the polling loop.
101 // For any other value, the adapter will default to "Initiator" mode.
102 virtual void StartPollLoop(
103 const dbus::ObjectPath& object_path,
104 const std::string& mode,
105 const base::Closure& callback,
106 const nfc_client_helpers::ErrorCallback& error_callback) = 0;
108 // Stops the polling loop for the adapter with object_path |object_path|.
109 virtual void StopPollLoop(
110 const dbus::ObjectPath& object_path,
111 const base::Closure& callback,
112 const nfc_client_helpers::ErrorCallback& error_callback) = 0;
114 // Creates the instance.
115 static NfcAdapterClient* Create(NfcManagerClient* manager_client);
117 protected:
118 friend class NfcClientTest;
120 NfcAdapterClient();
122 private:
123 DISALLOW_COPY_AND_ASSIGN(NfcAdapterClient);
126 } // namespace chromeos
128 #endif // CHROMEOS_DBUS_NFC_ADAPTER_CLIENT_H_