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 virtual base::Optional<int8_t> GetInquiryRSSI() const; |
335 | 338 |
336 // The transmitted power level. This field is avaliable only for LE devices | 339 // 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 | 340 // that include this field in AD. It is avaliable and valid only during |
338 // discovery. | 341 // discovery. |
339 virtual base::Optional<int8_t> GetInquiryTxPower() const = 0; | 342 virtual base::Optional<int8_t> GetInquiryTxPower() const; |
340 | 343 |
341 // The ErrorCallback is used for methods that can fail in which case it | 344 // 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. | 345 // is called, in the success case the callback is simply not called. |
343 typedef base::Callback<void()> ErrorCallback; | 346 typedef base::Callback<void()> ErrorCallback; |
344 | 347 |
345 // The ConnectErrorCallback is used for methods that can fail with an error, | 348 // The ConnectErrorCallback is used for methods that can fail with an error, |
346 // passed back as an error code argument to this callback. | 349 // passed back as an error code argument to this callback. |
347 // In the success case this callback is not called. | 350 // In the success case this callback is not called. |
348 typedef base::Callback<void(enum ConnectErrorCode)> ConnectErrorCallback; | 351 typedef base::Callback<void(enum ConnectErrorCode)> ConnectErrorCallback; |
349 | 352 |
(...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 | 508 // 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 | 509 // each 'X' is a hex digit. If the input |address| is invalid, returns an |
507 // empty string. | 510 // empty string. |
508 static std::string CanonicalizeAddress(const std::string& address); | 511 static std::string CanonicalizeAddress(const std::string& address); |
509 | 512 |
510 // Return the timestamp for when this device was last seen. | 513 // Return the timestamp for when this device was last seen. |
511 base::Time GetLastUpdateTime() const { return last_update_time_; } | 514 base::Time GetLastUpdateTime() const { return last_update_time_; } |
512 | 515 |
513 // Called by BluetoothAdapter when a new Advertisement is seen for this | 516 // Called by BluetoothAdapter when a new Advertisement is seen for this |
514 // device. This replaces previously seen Advertisement Data. | 517 // device. This replaces previously seen Advertisement Data. |
515 void UpdateAdvertisementData(UUIDList advertised_uuids, | 518 void UpdateAdvertisementData(int8_t rssi, |
516 ServiceDataMap service_data); | 519 UUIDList advertised_uuids, |
| 520 ServiceDataMap service_data, |
| 521 const int8_t* tx_power); |
517 | 522 |
518 // Called by BluetoothAdapter when it stops discoverying. | 523 // Called by BluetoothAdapter when it stops discoverying. |
519 void ClearAdvertisementData(); | 524 void ClearAdvertisementData(); |
520 | 525 |
521 // Return associated BluetoothAdapter. | 526 // Return associated BluetoothAdapter. |
522 BluetoothAdapter* GetAdapter() { return adapter_; } | 527 BluetoothAdapter* GetAdapter() { return adapter_; } |
523 | 528 |
524 protected: | 529 protected: |
525 // BluetoothGattConnection is a friend to call Add/RemoveGattConnection. | 530 // BluetoothGattConnection is a friend to call Add/RemoveGattConnection. |
526 friend BluetoothGattConnection; | 531 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. | 615 // Callbacks for pending success and error result of CreateGattConnection. |
611 std::vector<GattConnectionCallback> create_gatt_connection_success_callbacks_; | 616 std::vector<GattConnectionCallback> create_gatt_connection_success_callbacks_; |
612 std::vector<ConnectErrorCallback> create_gatt_connection_error_callbacks_; | 617 std::vector<ConnectErrorCallback> create_gatt_connection_error_callbacks_; |
613 | 618 |
614 // BluetoothGattConnection objects keeping the GATT connection alive. | 619 // BluetoothGattConnection objects keeping the GATT connection alive. |
615 std::set<BluetoothGattConnection*> gatt_connections_; | 620 std::set<BluetoothGattConnection*> gatt_connections_; |
616 | 621 |
617 GattServiceMap gatt_services_; | 622 GattServiceMap gatt_services_; |
618 bool gatt_services_discovery_complete_; | 623 bool gatt_services_discovery_complete_; |
619 | 624 |
| 625 // Received Signal Strength Indicator of the advertisement received. |
| 626 base::Optional<int8_t> inquiry_rssi_; |
| 627 |
| 628 // Tx Power advertised by the device. |
| 629 base::Optional<int8_t> inquiry_tx_power_; |
| 630 |
620 // Class that holds the union of Advertised UUIDs and Service UUIDs. | 631 // Class that holds the union of Advertised UUIDs and Service UUIDs. |
621 DeviceUUIDs device_uuids_; | 632 DeviceUUIDs device_uuids_; |
622 | 633 |
623 // Map of BluetoothUUIDs to their advertised Service Data. | 634 // Map of BluetoothUUIDs to their advertised Service Data. |
624 ServiceDataMap service_data_; | 635 ServiceDataMap service_data_; |
625 | 636 |
626 // Timestamp for when an advertisement was last seen. | 637 // Timestamp for when an advertisement was last seen. |
627 base::Time last_update_time_; | 638 base::Time last_update_time_; |
628 | 639 |
629 private: | 640 private: |
630 // Returns a localized string containing the device's bluetooth address and | 641 // Returns a localized string containing the device's bluetooth address and |
631 // a device type for display when |name_| is empty. | 642 // a device type for display when |name_| is empty. |
632 base::string16 GetAddressWithLocalizedDeviceTypeName() const; | 643 base::string16 GetAddressWithLocalizedDeviceTypeName() const; |
633 }; | 644 }; |
634 | 645 |
635 } // namespace device | 646 } // namespace device |
636 | 647 |
637 #endif // DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_ | 648 #endif // DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_ |
OLD | NEW |