| 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 <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 // authorized. The delegate should decide whether the user should confirm | 209 // authorized. The delegate should decide whether the user should confirm |
| 210 // or not, then call ConfirmPairing() on the device to confirm the pairing | 210 // or not, then call ConfirmPairing() on the device to confirm the pairing |
| 211 // (whether by user action or by default), RejectPairing() on the device to | 211 // (whether by user action or by default), RejectPairing() on the device to |
| 212 // reject or CancelPairing() on the device to cancel authorization for | 212 // reject or CancelPairing() on the device to cancel authorization for |
| 213 // any other reason. | 213 // any other reason. |
| 214 virtual void AuthorizePairing(BluetoothDevice* device) = 0; | 214 virtual void AuthorizePairing(BluetoothDevice* device) = 0; |
| 215 }; | 215 }; |
| 216 | 216 |
| 217 virtual ~BluetoothDevice(); | 217 virtual ~BluetoothDevice(); |
| 218 | 218 |
| 219 // Clamps numbers less than -128 to -128 and numbers greater than 127 to 127. |
| 220 static int8_t ClampPower(int power); |
| 221 |
| 219 // Returns the Bluetooth class of the device, used by GetDeviceType() | 222 // Returns the Bluetooth class of the device, used by GetDeviceType() |
| 220 // and metrics logging, | 223 // and metrics logging, |
| 221 virtual uint32_t GetBluetoothClass() const = 0; | 224 virtual uint32_t GetBluetoothClass() const = 0; |
| 222 | 225 |
| 223 #if defined(OS_CHROMEOS) || defined(OS_LINUX) | 226 #if defined(OS_CHROMEOS) || defined(OS_LINUX) |
| 224 // Returns the transport type of the device. Some devices only support one | 227 // Returns the transport type of the device. Some devices only support one |
| 225 // of BR/EDR or LE, and some support both. | 228 // of BR/EDR or LE, and some support both. |
| 226 virtual BluetoothTransport GetType() const = 0; | 229 virtual BluetoothTransport GetType() const = 0; |
| 227 #endif | 230 #endif |
| 228 | 231 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 // Returns an empty set if the adapter is not discovering. | 327 // Returns an empty set if the adapter is not discovering. |
| 325 UUIDSet GetServiceDataUUIDs() const; | 328 UUIDSet GetServiceDataUUIDs() const; |
| 326 | 329 |
| 327 // Returns a pointer to the Service Data for Service with |uuid|. Returns | 330 // Returns a pointer to the Service Data for Service with |uuid|. Returns |
| 328 // nullptr if |uuid| has no Service Data. | 331 // nullptr if |uuid| has no Service Data. |
| 329 const std::vector<uint8_t>* GetServiceDataForUUID( | 332 const std::vector<uint8_t>* GetServiceDataForUUID( |
| 330 const BluetoothUUID& uuid) const; | 333 const BluetoothUUID& uuid) const; |
| 331 | 334 |
| 332 // The received signal strength, in dBm. This field is avaliable and valid | 335 // The received signal strength, in dBm. This field is avaliable and valid |
| 333 // only during discovery. | 336 // only during discovery. |
| 334 virtual base::Optional<int8_t> GetInquiryRSSI() const = 0; | 337 // TODO(http://crbug.com/580406): Devirtualize once BlueZ sets inquiry_rssi_. |
| 338 virtual base::Optional<int8_t> GetInquiryRSSI() const; |
| 335 | 339 |
| 336 // The transmitted power level. This field is avaliable only for LE devices | 340 // The transmitted power level. This field is avaliable only for LE devices |
| 337 // that include this field in AD. It is avaliable and valid only during | 341 // that include this field in AD. It is avaliable and valid only during |
| 338 // discovery. | 342 // discovery. |
| 339 virtual base::Optional<int8_t> GetInquiryTxPower() const = 0; | 343 // TODO(http://crbug.com/580406): Devirtualize once BlueZ sets |
| 344 // inquiry_tx_power_. |
| 345 virtual base::Optional<int8_t> GetInquiryTxPower() const; |
| 340 | 346 |
| 341 // The ErrorCallback is used for methods that can fail in which case it | 347 // The ErrorCallback is used for methods that can fail in which case it |
| 342 // is called, in the success case the callback is simply not called. | 348 // is called, in the success case the callback is simply not called. |
| 343 typedef base::Callback<void()> ErrorCallback; | 349 typedef base::Callback<void()> ErrorCallback; |
| 344 | 350 |
| 345 // The ConnectErrorCallback is used for methods that can fail with an error, | 351 // The ConnectErrorCallback is used for methods that can fail with an error, |
| 346 // passed back as an error code argument to this callback. | 352 // passed back as an error code argument to this callback. |
| 347 // In the success case this callback is not called. | 353 // In the success case this callback is not called. |
| 348 typedef base::Callback<void(enum ConnectErrorCode)> ConnectErrorCallback; | 354 typedef base::Callback<void(enum ConnectErrorCode)> ConnectErrorCallback; |
| 349 | 355 |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 // Returns the |address| in the canonical format: XX:XX:XX:XX:XX:XX, where | 511 // Returns the |address| in the canonical format: XX:XX:XX:XX:XX:XX, where |
| 506 // each 'X' is a hex digit. If the input |address| is invalid, returns an | 512 // each 'X' is a hex digit. If the input |address| is invalid, returns an |
| 507 // empty string. | 513 // empty string. |
| 508 static std::string CanonicalizeAddress(const std::string& address); | 514 static std::string CanonicalizeAddress(const std::string& address); |
| 509 | 515 |
| 510 // Return the timestamp for when this device was last seen. | 516 // Return the timestamp for when this device was last seen. |
| 511 base::Time GetLastUpdateTime() const { return last_update_time_; } | 517 base::Time GetLastUpdateTime() const { return last_update_time_; } |
| 512 | 518 |
| 513 // Called by BluetoothAdapter when a new Advertisement is seen for this | 519 // Called by BluetoothAdapter when a new Advertisement is seen for this |
| 514 // device. This replaces previously seen Advertisement Data. | 520 // device. This replaces previously seen Advertisement Data. |
| 515 void UpdateAdvertisementData(UUIDList advertised_uuids, | 521 void UpdateAdvertisementData(int8_t rssi, |
| 516 ServiceDataMap service_data); | 522 UUIDList advertised_uuids, |
| 523 ServiceDataMap service_data, |
| 524 const int8_t* tx_power); |
| 517 | 525 |
| 518 // Called by BluetoothAdapter when it stops discoverying. | 526 // Called by BluetoothAdapter when it stops discoverying. |
| 519 void ClearAdvertisementData(); | 527 void ClearAdvertisementData(); |
| 520 | 528 |
| 521 // Return associated BluetoothAdapter. | 529 // Return associated BluetoothAdapter. |
| 522 BluetoothAdapter* GetAdapter() { return adapter_; } | 530 BluetoothAdapter* GetAdapter() { return adapter_; } |
| 523 | 531 |
| 524 protected: | 532 protected: |
| 525 // BluetoothGattConnection is a friend to call Add/RemoveGattConnection. | 533 // BluetoothGattConnection is a friend to call Add/RemoveGattConnection. |
| 526 friend BluetoothGattConnection; | 534 friend BluetoothGattConnection; |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 610 // Callbacks for pending success and error result of CreateGattConnection. | 618 // Callbacks for pending success and error result of CreateGattConnection. |
| 611 std::vector<GattConnectionCallback> create_gatt_connection_success_callbacks_; | 619 std::vector<GattConnectionCallback> create_gatt_connection_success_callbacks_; |
| 612 std::vector<ConnectErrorCallback> create_gatt_connection_error_callbacks_; | 620 std::vector<ConnectErrorCallback> create_gatt_connection_error_callbacks_; |
| 613 | 621 |
| 614 // BluetoothGattConnection objects keeping the GATT connection alive. | 622 // BluetoothGattConnection objects keeping the GATT connection alive. |
| 615 std::set<BluetoothGattConnection*> gatt_connections_; | 623 std::set<BluetoothGattConnection*> gatt_connections_; |
| 616 | 624 |
| 617 GattServiceMap gatt_services_; | 625 GattServiceMap gatt_services_; |
| 618 bool gatt_services_discovery_complete_; | 626 bool gatt_services_discovery_complete_; |
| 619 | 627 |
| 628 // Received Signal Strength Indicator of the advertisement received. |
| 629 base::Optional<int8_t> inquiry_rssi_; |
| 630 |
| 631 // Tx Power advertised by the device. |
| 632 base::Optional<int8_t> inquiry_tx_power_; |
| 633 |
| 620 // Class that holds the union of Advertised UUIDs and Service UUIDs. | 634 // Class that holds the union of Advertised UUIDs and Service UUIDs. |
| 621 DeviceUUIDs device_uuids_; | 635 DeviceUUIDs device_uuids_; |
| 622 | 636 |
| 623 // Map of BluetoothUUIDs to their advertised Service Data. | 637 // Map of BluetoothUUIDs to their advertised Service Data. |
| 624 ServiceDataMap service_data_; | 638 ServiceDataMap service_data_; |
| 625 | 639 |
| 626 // Timestamp for when an advertisement was last seen. | 640 // Timestamp for when an advertisement was last seen. |
| 627 base::Time last_update_time_; | 641 base::Time last_update_time_; |
| 628 | 642 |
| 629 private: | 643 private: |
| 630 // Returns a localized string containing the device's bluetooth address and | 644 // Returns a localized string containing the device's bluetooth address and |
| 631 // a device type for display when |name_| is empty. | 645 // a device type for display when |name_| is empty. |
| 632 base::string16 GetAddressWithLocalizedDeviceTypeName() const; | 646 base::string16 GetAddressWithLocalizedDeviceTypeName() const; |
| 633 }; | 647 }; |
| 634 | 648 |
| 635 } // namespace device | 649 } // namespace device |
| 636 | 650 |
| 637 #endif // DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_ | 651 #endif // DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_ |
| OLD | NEW |