Revert of Revert of Revert of Revert of Revert of Enable ServiceWorkerPerfTest (servi...
[chromium-blink-merge.git] / chromeos / dbus / bluetooth_adapter_client.h
blobdf2dc20098cb14bdca5fee8b162bde3a2abfc3cd
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_BLUETOOTH_ADAPTER_CLIENT_H_
6 #define CHROMEOS_DBUS_BLUETOOTH_ADAPTER_CLIENT_H_
8 #include <string>
9 #include <vector>
11 #include "base/callback.h"
12 #include "base/observer_list.h"
13 #include "base/values.h"
14 #include "chromeos/chromeos_export.h"
15 #include "chromeos/dbus/dbus_client.h"
16 #include "dbus/object_path.h"
17 #include "dbus/property.h"
19 namespace chromeos {
21 // BluetoothAdapterClient is used to communicate with objects representing
22 // local Bluetooth Adapters.
23 class CHROMEOS_EXPORT BluetoothAdapterClient : public DBusClient {
24 public:
25 struct DiscoveryFilter {
26 DiscoveryFilter();
27 ~DiscoveryFilter();
29 scoped_ptr<std::vector<std::string>> uuids;
30 scoped_ptr<int16_t> rssi;
31 scoped_ptr<uint16_t> pathloss;
32 scoped_ptr<std::string> transport;
35 // Structure of properties associated with bluetooth adapters.
36 struct Properties : public dbus::PropertySet {
37 // The Bluetooth device address of the adapter. Read-only.
38 dbus::Property<std::string> address;
40 // The Bluetooth system name, generally derived from the hostname.
41 dbus::Property<std::string> name;
43 // The Bluetooth friendly name of the adapter, unlike remote devices,
44 // this property can be changed to change the presentation for when
45 // the adapter is discoverable.
46 dbus::Property<std::string> alias;
48 // The Bluetooth class of the adapter device. Read-only.
49 dbus::Property<uint32> bluetooth_class;
51 // Whether the adapter radio is powered.
52 dbus::Property<bool> powered;
54 // Whether the adapter is discoverable by other Bluetooth devices.
55 // |discovering_timeout| is used to automatically disable after a time
56 // period.
57 dbus::Property<bool> discoverable;
59 // Whether the adapter accepts incoming pairing requests from other
60 // Bluetooth devices. |pairable_timeout| is used to automatically disable
61 // after a time period.
62 dbus::Property<bool> pairable;
64 // The timeout in seconds to cease accepting incoming pairing requests
65 // after |pairable| is set to true. Zero means adapter remains pairable
66 // forever.
67 dbus::Property<uint32> pairable_timeout;
69 // The timeout in seconds to cease the adapter being discoverable by
70 // other Bluetooth devices after |discoverable| is set to true. Zero
71 // means adapter remains discoverable forever.
72 dbus::Property<uint32> discoverable_timeout;
74 // Indicates that the adapter is discovering other Bluetooth Devices.
75 // Read-only. Use StartDiscovery() to begin discovery.
76 dbus::Property<bool> discovering;
78 // List of 128-bit UUIDs that represent the available local services.
79 // Read-only.
80 dbus::Property<std::vector<std::string> > uuids;
82 // Local Device ID information in Linux kernel modalias format. Read-only.
83 dbus::Property<std::string> modalias;
85 Properties(dbus::ObjectProxy* object_proxy,
86 const std::string& interface_name,
87 const PropertyChangedCallback& callback);
88 ~Properties() override;
91 // Interface for observing changes from a local bluetooth adapter.
92 class Observer {
93 public:
94 virtual ~Observer() {}
96 // Called when the adapter with object path |object_path| is added to the
97 // system.
98 virtual void AdapterAdded(const dbus::ObjectPath& object_path) {}
100 // Called when the adapter with object path |object_path| is removed from
101 // the system.
102 virtual void AdapterRemoved(const dbus::ObjectPath& object_path) {}
104 // Called when the adapter with object path |object_path| has a
105 // change in value of the property named |property_name|.
106 virtual void AdapterPropertyChanged(const dbus::ObjectPath& object_path,
107 const std::string& property_name) {}
110 ~BluetoothAdapterClient() override;
112 // Adds and removes observers for events on all local bluetooth
113 // adapters. Check the |object_path| parameter of observer methods to
114 // determine which adapter is issuing the event.
115 virtual void AddObserver(Observer* observer) = 0;
116 virtual void RemoveObserver(Observer* observer) = 0;
118 // Returns the list of adapter object paths known to the system.
119 virtual std::vector<dbus::ObjectPath> GetAdapters() = 0;
121 // Obtain the properties for the adapter with object path |object_path|,
122 // any values should be copied if needed.
123 virtual Properties* GetProperties(const dbus::ObjectPath& object_path) = 0;
125 // The ErrorCallback is used by adapter methods to indicate failure.
126 // It receives two arguments: the name of the error in |error_name| and
127 // an optional message in |error_message|.
128 typedef base::Callback<void(const std::string& error_name,
129 const std::string& error_message)> ErrorCallback;
131 // Starts a device discovery on the adapter with object path |object_path|.
132 virtual void StartDiscovery(const dbus::ObjectPath& object_path,
133 const base::Closure& callback,
134 const ErrorCallback& error_callback) = 0;
136 // Cancels any previous device discovery on the adapter with object path
137 // |object_path|.
138 virtual void StopDiscovery(const dbus::ObjectPath& object_path,
139 const base::Closure& callback,
140 const ErrorCallback& error_callback) = 0;
142 // Removes from the adapter with object path |object_path| the remote
143 // device with object path |object_path| from the list of known devices
144 // and discards any pairing information.
145 virtual void RemoveDevice(const dbus::ObjectPath& object_path,
146 const dbus::ObjectPath& device_path,
147 const base::Closure& callback,
148 const ErrorCallback& error_callback) = 0;
150 // Sets the device discovery filter on the adapter with object path
151 // |object_path|. When this method is called with no filter parameter, filter
152 // is removed.
153 // SetDiscoveryFilter can be called before StartDiscovery. It is useful when
154 // client will create first discovery session, to ensure that proper scan
155 // will be started right after call to StartDiscovery.
156 virtual void SetDiscoveryFilter(const dbus::ObjectPath& object_path,
157 const DiscoveryFilter& discovery_filter,
158 const base::Closure& callback,
159 const ErrorCallback& error_callback) = 0;
161 // Creates the instance.
162 static BluetoothAdapterClient* Create();
164 // Constants used to indicate exceptional error conditions.
165 static const char kNoResponseError[];
166 static const char kUnknownAdapterError[];
168 protected:
169 BluetoothAdapterClient();
171 private:
172 DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterClient);
175 } // namespace chromeos
177 #endif // CHROMEOS_DBUS_BLUETOOTH_ADAPTER_CLIENT_H_