| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_BLUETOOTH_DEVICE_H_ | 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_ |
| 6 #define DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_ | 6 #define DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | |
| 10 | 9 |
| 11 #include "base/callback.h" | 10 #include "base/callback.h" |
| 12 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
| 14 #include "base/string16.h" | 13 #include "base/string16.h" |
| 15 | 14 |
| 16 namespace device { | 15 namespace device { |
| 17 | 16 |
| 18 class BluetoothServiceRecord; | 17 class BluetoothServiceRecord; |
| 19 class BluetoothSocket; | 18 class BluetoothSocket; |
| 20 | 19 |
| 21 struct BluetoothOutOfBandPairingData; | 20 struct BluetoothOutOfBandPairingData; |
| 22 | 21 |
| 23 // BluetoothDevice represents a remote Bluetooth device, both its properties and | 22 // BluetoothDevice represents a remote Bluetooth device, both its properties and |
| 24 // capabilities as discovered by a local adapter and actions that may be | 23 // capabilities as discovered by a local adapter and actions that may be |
| 25 // performed on the remove device such as pairing, connection and disconnection. | 24 // performed on the remove device such as pairing, connection and disconnection. |
| 26 // | 25 // |
| 27 // The class is instantiated and managed by the BluetoothAdapter class | 26 // The class is instantiated and managed by the BluetoothAdapter class |
| 28 // and pointers should only be obtained from that class and not cached, | 27 // and pointers should only be obtained from that class and not cached, |
| 29 // instead use the address() method as a unique key for a device. | 28 // instead use the GetAddress() method as a unique key for a device. |
| 30 // | 29 // |
| 31 // Since the lifecycle of BluetoothDevice instances is managed by | 30 // Since the lifecycle of BluetoothDevice instances is managed by |
| 32 // BluetoothAdapter, that class rather than this provides observer methods | 31 // BluetoothAdapter, that class rather than this provides observer methods |
| 33 // for devices coming and going, as well as properties being updated. | 32 // for devices coming and going, as well as properties being updated. |
| 34 class BluetoothDevice { | 33 class BluetoothDevice { |
| 35 public: | 34 public: |
| 36 // Possible values that may be returned by GetDeviceType(), representing | 35 // Possible values that may be returned by GetDeviceType(), representing |
| 37 // different types of bluetooth device that we support or are aware of | 36 // different types of bluetooth device that we support or are aware of |
| 38 // decoded from the bluetooth class information. | 37 // decoded from the bluetooth class information. |
| 39 enum DeviceType { | 38 enum DeviceType { |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 }; | 145 }; |
| 147 | 146 |
| 148 // Returns true if uuid is in a a valid canonical format | 147 // Returns true if uuid is in a a valid canonical format |
| 149 // (see utils::CanonicalUuid). | 148 // (see utils::CanonicalUuid). |
| 150 static bool IsUUIDValid(const std::string& uuid); | 149 static bool IsUUIDValid(const std::string& uuid); |
| 151 | 150 |
| 152 virtual ~BluetoothDevice(); | 151 virtual ~BluetoothDevice(); |
| 153 | 152 |
| 154 // Returns the Bluetooth of address the device. This should be used as | 153 // Returns the Bluetooth of address the device. This should be used as |
| 155 // a unique key to identify the device and copied where needed. | 154 // a unique key to identify the device and copied where needed. |
| 156 virtual const std::string& address() const; | 155 virtual std::string GetAddress() const = 0; |
| 157 | 156 |
| 158 // Returns the name of the device suitable for displaying, this may | 157 // Returns the name of the device suitable for displaying, this may |
| 159 // be a synthesied string containing the address and localized type name | 158 // be a synthesied string containing the address and localized type name |
| 160 // if the device has no obtained name. | 159 // if the device has no obtained name. |
| 161 virtual string16 GetName() const; | 160 virtual string16 GetName() const; |
| 162 | 161 |
| 163 // Returns the type of the device, limited to those we support or are | 162 // Returns the type of the device, limited to those we support or are |
| 164 // aware of, by decoding the bluetooth class information. The returned | 163 // aware of, by decoding the bluetooth class information. The returned |
| 165 // values are unique, and do not overlap, so DEVICE_KEYBOARD is not also | 164 // values are unique, and do not overlap, so DEVICE_KEYBOARD is not also |
| 166 // DEVICE_PERIPHERAL. | 165 // DEVICE_PERIPHERAL. |
| 167 DeviceType GetDeviceType() const; | 166 DeviceType GetDeviceType() const; |
| 168 | 167 |
| 169 // Indicates whether the device is paired to the adapter, whether or not | 168 // Indicates whether the device is paired with the adapter. |
| 170 // that pairing is permanent or temporary. | |
| 171 virtual bool IsPaired() const = 0; | 169 virtual bool IsPaired() const = 0; |
| 172 | 170 |
| 173 // Indicates whether the device is visible to the adapter, this is not | 171 // Indicates whether the device is currently connected to the adapter. |
| 174 // mutually exclusive to being paired. | 172 virtual bool IsConnected() const = 0; |
| 175 virtual bool IsVisible() const; | |
| 176 | 173 |
| 177 // Indicates whether the device is bonded to the adapter, bonding is | 174 // Indicates whether the paired device accepts connections initiated from the |
| 178 // formed by pairing and exchanging high-security link keys so that | 175 // adapter. This value is undefined for unpaired devices. |
| 179 // connections may be encrypted. | 176 virtual bool IsConnectable() const = 0; |
| 180 virtual bool IsBonded() const; | |
| 181 | |
| 182 // Indicates whether the device is currently connected to the adapter | |
| 183 // and at least one service available for use. | |
| 184 virtual bool IsConnected() const; | |
| 185 | |
| 186 // Indicates whether the bonded device accepts connections initiated from the | |
| 187 // adapter. This value is undefined for unbonded devices. | |
| 188 virtual bool IsConnectable() const; | |
| 189 | 177 |
| 190 // Indicates whether there is a call to Connect() ongoing. For this attribute, | 178 // Indicates whether there is a call to Connect() ongoing. For this attribute, |
| 191 // we consider a call is ongoing if none of the callbacks passed to Connect() | 179 // we consider a call is ongoing if none of the callbacks passed to Connect() |
| 192 // were called after the corresponding call to Connect(). | 180 // were called after the corresponding call to Connect(). |
| 193 virtual bool IsConnecting() const; | 181 virtual bool IsConnecting() const = 0; |
| 194 | 182 |
| 195 // Returns the services (as UUID strings) that this device provides. | 183 // Returns the services (as UUID strings) that this device provides. |
| 196 typedef std::vector<std::string> ServiceList; | 184 typedef std::vector<std::string> ServiceList; |
| 197 virtual const ServiceList& GetServices() const = 0; | 185 virtual ServiceList GetServices() const = 0; |
| 198 | 186 |
| 199 // The ErrorCallback is used for methods that can fail in which case it | 187 // The ErrorCallback is used for methods that can fail in which case it |
| 200 // is called, in the success case the callback is simply not called. | 188 // is called, in the success case the callback is simply not called. |
| 201 typedef base::Callback<void()> ErrorCallback; | 189 typedef base::Callback<void()> ErrorCallback; |
| 202 | 190 |
| 203 // The ConnectErrorCallback is used for methods that can fail with an error, | 191 // The ConnectErrorCallback is used for methods that can fail with an error, |
| 204 // passed back as an error code argument to this callback. | 192 // passed back as an error code argument to this callback. |
| 205 // In the success case this callback is not called. | 193 // In the success case this callback is not called. |
| 206 typedef base::Callback<void(enum ConnectErrorCode)> ConnectErrorCallback; | 194 typedef base::Callback<void(enum ConnectErrorCode)> ConnectErrorCallback; |
| 207 | 195 |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 | 307 |
| 320 // Clears the Out Of Band pairing data for this device. Exactly one of | 308 // Clears the Out Of Band pairing data for this device. Exactly one of |
| 321 // |callback| or |error_callback| will be run. | 309 // |callback| or |error_callback| will be run. |
| 322 virtual void ClearOutOfBandPairingData( | 310 virtual void ClearOutOfBandPairingData( |
| 323 const base::Closure& callback, | 311 const base::Closure& callback, |
| 324 const ErrorCallback& error_callback) = 0; | 312 const ErrorCallback& error_callback) = 0; |
| 325 | 313 |
| 326 protected: | 314 protected: |
| 327 BluetoothDevice(); | 315 BluetoothDevice(); |
| 328 | 316 |
| 329 // The Bluetooth class of the device, a bitmask that may be decoded using | 317 // Returns the Bluetooth class of the device, used by GetDeviceType(). |
| 330 // https://www.bluetooth.org/Technical/AssignedNumbers/baseband.htm | 318 virtual uint32 GetBluetoothClass() const = 0; |
| 331 uint32 bluetooth_class_; | |
| 332 | 319 |
| 333 // The name of the device, as supplied by the remote device. | 320 // Returns the internal name of the Bluetooth device, used by GetName(). |
| 334 std::string name_; | 321 virtual std::string GetDeviceName() const = 0; |
| 335 | |
| 336 // The Bluetooth address of the device. | |
| 337 std::string address_; | |
| 338 | |
| 339 // Tracked device state, updated by the adapter managing the lifecyle of | |
| 340 // the device. | |
| 341 bool visible_; | |
| 342 bool bonded_; | |
| 343 bool connected_; | |
| 344 | |
| 345 // Indicates whether the device normally accepts connections initiated from | |
| 346 // the adapter once paired. | |
| 347 bool connectable_; | |
| 348 | |
| 349 // Indicated whether the device is in a connecting status. | |
| 350 bool connecting_; | |
| 351 | |
| 352 // The services (identified by UUIDs) that this device provides. | |
| 353 ServiceList service_uuids_; | |
| 354 | 322 |
| 355 private: | 323 private: |
| 356 // Returns a localized string containing the device's bluetooth address and | 324 // Returns a localized string containing the device's bluetooth address and |
| 357 // a device type for display when |name_| is empty. | 325 // a device type for display when |name_| is empty. |
| 358 string16 GetAddressWithLocalizedDeviceTypeName() const; | 326 string16 GetAddressWithLocalizedDeviceTypeName() const; |
| 359 }; | 327 }; |
| 360 | 328 |
| 361 } // namespace device | 329 } // namespace device |
| 362 | 330 |
| 363 #endif // DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_ | 331 #endif // DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_ |
| OLD | NEW |