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_
11 #include "base/callback.h"
12 #include "chromeos/chromeos_export.h"
13 #include "chromeos/dbus/dbus_client.h"
14 #include "chromeos/dbus/dbus_client_implementation_type.h"
15 #include "chromeos/dbus/nfc_client_helpers.h"
16 #include "chromeos/dbus/nfc_property_set.h"
17 #include "dbus/object_path.h"
18 #include "dbus/object_proxy.h"
19 #include "dbus/property.h"
23 class NfcManagerClient;
25 // NfcAdapterClient is used to communicate with objects representing local NFC
27 class CHROMEOS_EXPORT NfcAdapterClient : public DBusClient {
29 // Structure of properties associated with an NFC adapter.
30 struct Properties : public NfcPropertySet {
31 // The adapter NFC radio mode. One of "Initiator", "Target", and "Idle".
32 // The NFC adapter will usually be in the "Idle" mode. The mode will change
33 // to "Initiator" or "Target" based on how a pairing is established with a
34 // remote tag or device.
35 dbus::Property<std::string> mode;
37 // The adapter's current power state.
38 dbus::Property<bool> powered;
40 // Indicates whether or not the adapter is currently polling for targets.
41 // This property is only valid when |mode| is "Initiator".
42 dbus::Property<bool> polling;
44 // The NFC protocols that are supported by the adapter. Possible values
45 // are: "Felica", "MIFARE", "Jewel", "ISO-DEP", and "NFC-DEP".
46 dbus::Property<std::vector<std::string> > protocols;
48 // The object paths of the NFC tags that are known to the local adapter.
49 // These are tags that have been "tapped" on the local adapter.
50 dbus::Property<std::vector<dbus::ObjectPath> > tags;
52 // The object paths of the remote NFC devices that have been found by the
53 // local adapter. These are NFC adapters that were "tapped" on the local
55 dbus::Property<std::vector<dbus::ObjectPath> > devices;
57 Properties(dbus::ObjectProxy* object_proxy,
58 const PropertyChangedCallback& callback);
59 virtual ~Properties();
62 // Interface for observing changes from a local NFC adapter.
65 virtual ~Observer() {}
67 // Called when a new adapter with object path |object_path| is added to the
69 virtual void AdapterAdded(const dbus::ObjectPath& object_path) {}
71 // Called when an adapter with object path |object_path| is removed from the
73 virtual void AdapterRemoved(const dbus::ObjectPath& object_path) {}
75 // Called when the adapter property with the name |property_name| on adapter
76 // with object path |object_path| has acquired a new value.
77 virtual void AdapterPropertyChanged(const dbus::ObjectPath& object_path,
78 const std::string& property_name) {}
81 virtual ~NfcAdapterClient();
83 // Adds and removes observers for events on all local bluetooth adapters.
84 // Check the |object_path| parameter of the observer methods to determine
85 // which adapter is issuing the event.
86 virtual void AddObserver(Observer* observer) = 0;
87 virtual void RemoveObserver(Observer* observer) = 0;
89 // Obtains the properties for the adapter with object path |object_path|, any
90 // values should be copied if needed. A NULL pointer will be returned, if no
91 // adapter with the given object path is known to exist.
92 virtual Properties* GetProperties(const dbus::ObjectPath& object_path) = 0;
94 // Starts the polling loop for the adapter with object path |object_path|.
95 // Depending on the mode, the adapter will start polling for targets,
96 // listening to NFC devices, or both. The |mode| parameter should be one of
97 // "Initiator", "Target", or "Dual". The "Dual" mode will have the adapter
98 // alternate between "Initiator" and "Target" modes during the polling loop.
99 // For any other value, the adapter will default to "Initiator" mode.
100 virtual void StartPollLoop(
101 const dbus::ObjectPath& object_path,
102 const std::string& mode,
103 const base::Closure& callback,
104 const nfc_client_helpers::ErrorCallback& error_callback) = 0;
106 // Stops the polling loop for the adapter with object_path |object_path|.
107 virtual void StopPollLoop(
108 const dbus::ObjectPath& object_path,
109 const base::Closure& callback,
110 const nfc_client_helpers::ErrorCallback& error_callback) = 0;
112 // Creates the instance.
113 static NfcAdapterClient* Create(DBusClientImplementationType type,
114 NfcManagerClient* manager_client);
117 friend class NfcClientTest;
122 DISALLOW_COPY_AND_ASSIGN(NfcAdapterClient);
125 } // namespace chromeos
127 #endif // CHROMEOS_DBUS_NFC_ADAPTER_CLIENT_H_