Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef DEVICE_BLUETOOTH_DBUS_BLUETOOTH_DEVICE_CLIENT_H_ | 5 #ifndef DEVICE_BLUETOOTH_DBUS_BLUETOOTH_DEVICE_CLIENT_H_ |
| 6 #define DEVICE_BLUETOOTH_DBUS_BLUETOOTH_DEVICE_CLIENT_H_ | 6 #define DEVICE_BLUETOOTH_DBUS_BLUETOOTH_DEVICE_CLIENT_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/observer_list.h" | 15 #include "base/observer_list.h" |
| 16 #include "base/values.h" | 16 #include "base/values.h" |
| 17 #include "dbus/object_path.h" | 17 #include "dbus/object_path.h" |
| 18 #include "dbus/property.h" | 18 #include "dbus/property.h" |
| 19 #include "device/bluetooth/bluetooth_export.h" | 19 #include "device/bluetooth/bluetooth_export.h" |
| 20 #include "device/bluetooth/bluez/bluetooth_service_record_bluez.h" | |
| 20 #include "device/bluetooth/dbus/bluez_dbus_client.h" | 21 #include "device/bluetooth/dbus/bluez_dbus_client.h" |
| 21 | 22 |
| 22 namespace bluez { | 23 namespace bluez { |
| 23 | 24 |
| 24 // BluetoothDeviceClient is used to communicate with objects representing | 25 // BluetoothDeviceClient is used to communicate with objects representing |
| 25 // remote Bluetooth Devices. | 26 // remote Bluetooth Devices. |
| 26 class DEVICE_BLUETOOTH_EXPORT BluetoothDeviceClient : public BluezDBusClient { | 27 class DEVICE_BLUETOOTH_EXPORT BluetoothDeviceClient : public BluezDBusClient { |
| 27 public: | 28 public: |
| 29 using ServiceRecordList = std::vector<BluetoothServiceRecordBlueZ>; | |
| 30 | |
| 31 // This callback invoked for a successful GetConnInfo API call with the | |
| 32 // RSSI, TX power, and maximum TX power of the current connection. | |
| 33 using ConnInfoCallback = base::Callback< | |
| 34 void(int16_t rssi, int16_t transmit_power, int16_t max_transmit_power)>; | |
| 35 | |
| 36 // This callback invoked for a successful GetServiceRecords API call with the | |
| 37 // currently discovered service records. | |
| 38 using ServiceRecordsCallback = base::Callback<void(ServiceRecordList)>; | |
|
xiyuan
2016/06/29 22:43:08
Do we want to use ServiceRecordList& or std::uniqu
rkc
2016/06/30 20:02:24
Done.
| |
| 39 | |
| 40 // The ErrorCallback is used by device methods to indicate failure. | |
| 41 // It receives two arguments: the name of the error in |error_name| and | |
| 42 // an optional message in |error_message|. | |
| 43 using ErrorCallback = base::Callback<void(const std::string& error_name, | |
| 44 const std::string& error_message)>; | |
| 45 | |
| 28 // Structure of properties associated with bluetooth devices. | 46 // Structure of properties associated with bluetooth devices. |
| 29 struct Properties : public dbus::PropertySet { | 47 struct Properties : public dbus::PropertySet { |
| 30 // The Bluetooth device address of the device. Read-only. | 48 // The Bluetooth device address of the device. Read-only. |
| 31 dbus::Property<std::string> address; | 49 dbus::Property<std::string> address; |
| 32 | 50 |
| 33 // The Bluetooth friendly name of the device. Read-only, to give a | 51 // The Bluetooth friendly name of the device. Read-only, to give a |
| 34 // different local name, use the |alias| property. | 52 // different local name, use the |alias| property. |
| 35 dbus::Property<std::string> name; | 53 dbus::Property<std::string> name; |
| 36 | 54 |
| 37 // Proposed icon name for the device according to the freedesktop.org | 55 // Proposed icon name for the device according to the freedesktop.org |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 128 | 146 |
| 129 // Returns the list of device object paths associated with the given adapter | 147 // Returns the list of device object paths associated with the given adapter |
| 130 // identified by the D-Bus object path |adapter_path|. | 148 // identified by the D-Bus object path |adapter_path|. |
| 131 virtual std::vector<dbus::ObjectPath> GetDevicesForAdapter( | 149 virtual std::vector<dbus::ObjectPath> GetDevicesForAdapter( |
| 132 const dbus::ObjectPath& adapter_path) = 0; | 150 const dbus::ObjectPath& adapter_path) = 0; |
| 133 | 151 |
| 134 // Obtain the properties for the device with object path |object_path|, | 152 // Obtain the properties for the device with object path |object_path|, |
| 135 // any values should be copied if needed. | 153 // any values should be copied if needed. |
| 136 virtual Properties* GetProperties(const dbus::ObjectPath& object_path) = 0; | 154 virtual Properties* GetProperties(const dbus::ObjectPath& object_path) = 0; |
| 137 | 155 |
| 138 // The ErrorCallback is used by device methods to indicate failure. | |
| 139 // It receives two arguments: the name of the error in |error_name| and | |
| 140 // an optional message in |error_message|. | |
| 141 typedef base::Callback<void(const std::string& error_name, | |
| 142 const std::string& error_message)> ErrorCallback; | |
| 143 | |
| 144 // Connects to the device with object path |object_path|, connecting any | 156 // Connects to the device with object path |object_path|, connecting any |
| 145 // profiles that can be connected to and have been flagged as auto-connected; | 157 // profiles that can be connected to and have been flagged as auto-connected; |
| 146 // may be used to connect additional profiles for an already connected device, | 158 // may be used to connect additional profiles for an already connected device, |
| 147 // and succeeds if at least one profile is connected. | 159 // and succeeds if at least one profile is connected. |
| 148 virtual void Connect(const dbus::ObjectPath& object_path, | 160 virtual void Connect(const dbus::ObjectPath& object_path, |
| 149 const base::Closure& callback, | 161 const base::Closure& callback, |
| 150 const ErrorCallback& error_callback) = 0; | 162 const ErrorCallback& error_callback) = 0; |
| 151 | 163 |
| 152 // Disconnects the device with object path |object_path|, terminating | 164 // Disconnects the device with object path |object_path|, terminating |
| 153 // the low-level ACL connection and any profiles using it. | 165 // the low-level ACL connection and any profiles using it. |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 176 virtual void Pair(const dbus::ObjectPath& object_path, | 188 virtual void Pair(const dbus::ObjectPath& object_path, |
| 177 const base::Closure& callback, | 189 const base::Closure& callback, |
| 178 const ErrorCallback& error_callback) = 0; | 190 const ErrorCallback& error_callback) = 0; |
| 179 | 191 |
| 180 // Cancels an in-progress pairing with the device with object path | 192 // Cancels an in-progress pairing with the device with object path |
| 181 // |object_path| initiated by Pair(). | 193 // |object_path| initiated by Pair(). |
| 182 virtual void CancelPairing(const dbus::ObjectPath& object_path, | 194 virtual void CancelPairing(const dbus::ObjectPath& object_path, |
| 183 const base::Closure& callback, | 195 const base::Closure& callback, |
| 184 const ErrorCallback& error_callback) = 0; | 196 const ErrorCallback& error_callback) = 0; |
| 185 | 197 |
| 186 // The callback invoked for a successful GetConnInfo API call with the | |
| 187 // RSSI, TX power, and maximum TX power of the current connection. | |
| 188 typedef base::Callback<void(int16_t rssi, | |
| 189 int16_t transmit_power, | |
| 190 int16_t max_transmit_power)> ConnInfoCallback; | |
| 191 | |
| 192 // Returns the RSSI, TX power, and maximum TX power of a connection to the | 198 // Returns the RSSI, TX power, and maximum TX power of a connection to the |
| 193 // device with object path |object_path|. If the device is not connected, then | 199 // device with object path |object_path|. If the device is not connected, then |
| 194 // an error will be returned. | 200 // an error will be returned. |
| 195 virtual void GetConnInfo(const dbus::ObjectPath& object_path, | 201 virtual void GetConnInfo(const dbus::ObjectPath& object_path, |
| 196 const ConnInfoCallback& callback, | 202 const ConnInfoCallback& callback, |
| 197 const ErrorCallback& error_callback) = 0; | 203 const ErrorCallback& error_callback) = 0; |
| 198 | 204 |
| 205 // Returns the currently discovered service records for the device with | |
| 206 // object path |object_path|. If the device is not connected, then an error | |
| 207 // will be returned. | |
| 208 virtual void GetServiceRecords(const dbus::ObjectPath& object_path, | |
| 209 const ServiceRecordsCallback& callback, | |
| 210 const ErrorCallback& error_callback) = 0; | |
| 211 | |
| 199 // Creates the instance. | 212 // Creates the instance. |
| 200 static BluetoothDeviceClient* Create(); | 213 static BluetoothDeviceClient* Create(); |
| 201 | 214 |
| 202 // Constants used to indicate exceptional error conditions. | 215 // Constants used to indicate exceptional error conditions. |
| 203 static const char kNoResponseError[]; | 216 static const char kNoResponseError[]; |
| 204 static const char kUnknownDeviceError[]; | 217 static const char kUnknownDeviceError[]; |
| 205 | 218 |
| 206 // Strings used by BlueZ for the transport type of the remote device. | 219 // Strings used by BlueZ for the transport type of the remote device. |
| 207 // See https://chromium-review.googlesource.com/c/351512/ | 220 // See https://chromium-review.googlesource.com/c/351512/ |
| 208 static const char kTypeBredr[]; | 221 static const char kTypeBredr[]; |
| 209 static const char kTypeLe[]; | 222 static const char kTypeLe[]; |
| 210 static const char kTypeDual[]; | 223 static const char kTypeDual[]; |
| 211 | 224 |
| 212 protected: | 225 protected: |
| 213 BluetoothDeviceClient(); | 226 BluetoothDeviceClient(); |
| 214 | 227 |
| 215 private: | 228 private: |
| 216 DISALLOW_COPY_AND_ASSIGN(BluetoothDeviceClient); | 229 DISALLOW_COPY_AND_ASSIGN(BluetoothDeviceClient); |
| 217 }; | 230 }; |
| 218 | 231 |
| 219 } // namespace bluez | 232 } // namespace bluez |
| 220 | 233 |
| 221 #endif // DEVICE_BLUETOOTH_DBUS_BLUETOOTH_DEVICE_CLIENT_H_ | 234 #endif // DEVICE_BLUETOOTH_DBUS_BLUETOOTH_DEVICE_CLIENT_H_ |
| OLD | NEW |