Adding Peter Thatcher to the owners file.
[chromium-blink-merge.git] / chromeos / dbus / bluetooth_device_client.h
blob353fd5b53eeb82416865965b6a333e3e6e14aa98
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_DEVICE_CLIENT_H_
6 #define CHROMEOS_DBUS_BLUETOOTH_DEVICE_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 // BluetoothDeviceClient is used to communicate with objects representing
22 // remote Bluetooth Devices.
23 class CHROMEOS_EXPORT BluetoothDeviceClient : public DBusClient {
24 public:
25 // Structure of properties associated with bluetooth devices.
26 struct Properties : public dbus::PropertySet {
27 // The Bluetooth device address of the device. Read-only.
28 dbus::Property<std::string> address;
30 // The Bluetooth friendly name of the device. Read-only, to give a
31 // different local name, use the |alias| property.
32 dbus::Property<std::string> name;
34 // Proposed icon name for the device according to the freedesktop.org
35 // icon naming specification. Read-only.
36 dbus::Property<std::string> icon;
38 // The Bluetooth class of the device. Read-only.
39 dbus::Property<uint32> bluetooth_class;
41 // The GAP external appearance of the device. Read-only.
42 dbus::Property<uint16> appearance;
44 // Unique numeric identifier for the vendor of the device. Read-only.
45 dbus::Property<uint16> vendor;
47 // List of 128-bit UUIDs that represent the available remote services.
48 // Read-only.
49 dbus::Property<std::vector<std::string> > uuids;
51 // Indicates that the device is currently paired. Read-only.
52 dbus::Property<bool> paired;
54 // Indicates that the device is currently connected. Read-only.
55 dbus::Property<bool> connected;
57 // Whether the device is trusted, and connections should be always
58 // accepted and attempted when the device is visible.
59 dbus::Property<bool> trusted;
61 // Whether the device is blocked, connections will be always rejected
62 // and the device will not be visible.
63 dbus::Property<bool> blocked;
65 // Local alias for the device, if not set, is equal to |name|.
66 dbus::Property<std::string> alias;
68 // Object path of the adapter the device belongs to. Read-only.
69 dbus::Property<dbus::ObjectPath> adapter;
71 // Indicates whether the device is likely to only support pre-2.1
72 // PIN Code pairing rather than 2.1 Secure Simple Pairing, this can
73 // give false positives. Read-only.
74 dbus::Property<bool> legacy_pairing;
76 // Remote Device ID information in Linux kernel modalias format. Read-only.
77 dbus::Property<std::string> modalias;
79 // Received signal strength indicator that is set when the device is
80 // discovered during inquiry. Read-only.
81 dbus::Property<int16> rssi;
83 Properties(dbus::ObjectProxy* object_proxy,
84 const std::string& interface_name,
85 const PropertyChangedCallback& callback);
86 ~Properties() override;
89 // Interface for observing changes from a remote bluetooth device.
90 class Observer {
91 public:
92 virtual ~Observer() {}
94 // Called when the remote device with object path |object_path| is added
95 // to the set of known devices.
96 virtual void DeviceAdded(const dbus::ObjectPath& object_path) {}
98 // Called when the remote device with object path |object_path| is removed
99 // from the set of known devices.
100 virtual void DeviceRemoved(const dbus::ObjectPath& object_path) {}
102 // Called when the device with object path |object_path| has a
103 // change in value of the property named |property_name|.
104 virtual void DevicePropertyChanged(const dbus::ObjectPath& object_path,
105 const std::string& property_name) {}
108 ~BluetoothDeviceClient() override;
110 // Adds and removes observers for events on all remote bluetooth
111 // devices. Check the |object_path| parameter of observer methods to
112 // determine which device is issuing the event.
113 virtual void AddObserver(Observer* observer) = 0;
114 virtual void RemoveObserver(Observer* observer) = 0;
116 // Returns the list of device object paths associated with the given adapter
117 // identified by the D-Bus object path |adapter_path|.
118 virtual std::vector<dbus::ObjectPath> GetDevicesForAdapter(
119 const dbus::ObjectPath& adapter_path) = 0;
121 // Obtain the properties for the device 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 device 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 // Connects to the device with object path |object_path|, connecting any
132 // profiles that can be connected to and have been flagged as auto-connected;
133 // may be used to connect additional profiles for an already connected device,
134 // and succeeds if at least one profile is connected.
135 virtual void Connect(const dbus::ObjectPath& object_path,
136 const base::Closure& callback,
137 const ErrorCallback& error_callback) = 0;
139 // Disconnects the device with object path |object_path|, terminating
140 // the low-level ACL connection and any profiles using it.
141 virtual void Disconnect(const dbus::ObjectPath& object_path,
142 const base::Closure& callback,
143 const ErrorCallback& error_callback) = 0;
145 // Connects to the profile |uuid| on the device with object path
146 // |object_path|, provided that the profile has been registered with a
147 // handler on the local device.
148 virtual void ConnectProfile(const dbus::ObjectPath& object_path,
149 const std::string& uuid,
150 const base::Closure& callback,
151 const ErrorCallback& error_callback) = 0;
153 // Disconnects from the profile |uuid| on the device with object path
154 // |object_path|.
155 virtual void DisconnectProfile(const dbus::ObjectPath& object_path,
156 const std::string& uuid,
157 const base::Closure& callback,
158 const ErrorCallback& error_callback) = 0;
160 // Initiates pairing with the device with object path |object_path| and
161 // retrieves all SDP records or GATT primary services. An agent must be
162 // registered to handle the pairing request.
163 virtual void Pair(const dbus::ObjectPath& object_path,
164 const base::Closure& callback,
165 const ErrorCallback& error_callback) = 0;
167 // Cancels an in-progress pairing with the device with object path
168 // |object_path| initiated by Pair().
169 virtual void CancelPairing(const dbus::ObjectPath& object_path,
170 const base::Closure& callback,
171 const ErrorCallback& error_callback) = 0;
173 // The callback invoked for a successful GetConnInfo API call with the
174 // RSSI, TX power, and maximum TX power of the current connection.
175 typedef base::Callback<void(int16 rssi,
176 int16 transmit_power,
177 int16 max_transmit_power)> ConnInfoCallback;
179 // Returns the RSSI, TX power, and maximum TX power of a connection to the
180 // device with object path |object_path|. If the device is not connected, then
181 // an error will be returned.
182 virtual void GetConnInfo(const dbus::ObjectPath& object_path,
183 const ConnInfoCallback& callback,
184 const ErrorCallback& error_callback) = 0;
186 // Creates the instance.
187 static BluetoothDeviceClient* Create();
189 // Constants used to indicate exceptional error conditions.
190 static const char kNoResponseError[];
191 static const char kUnknownDeviceError[];
193 protected:
194 BluetoothDeviceClient();
196 private:
197 DISALLOW_COPY_AND_ASSIGN(BluetoothDeviceClient);
200 } // namespace chromeos
202 #endif // CHROMEOS_DBUS_BLUETOOTH_DEVICE_CLIENT_H_