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 static int8_t ClampPower(int power); | |
Jeffrey Yasskin
2016/08/24 04:32:02
Comment what this does.
ortuno
2016/08/24 21:29:09
Done.
| |
220 | |
219 // Returns the Bluetooth class of the device, used by GetDeviceType() | 221 // Returns the Bluetooth class of the device, used by GetDeviceType() |
220 // and metrics logging, | 222 // and metrics logging, |
221 virtual uint32_t GetBluetoothClass() const = 0; | 223 virtual uint32_t GetBluetoothClass() const = 0; |
222 | 224 |
223 #if defined(OS_CHROMEOS) || defined(OS_LINUX) | 225 #if defined(OS_CHROMEOS) || defined(OS_LINUX) |
224 // Returns the transport type of the device. Some devices only support one | 226 // Returns the transport type of the device. Some devices only support one |
225 // of BR/EDR or LE, and some support both. | 227 // of BR/EDR or LE, and some support both. |
226 virtual BluetoothTransport GetType() const = 0; | 228 virtual BluetoothTransport GetType() const = 0; |
227 #endif | 229 #endif |
228 | 230 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
324 // Returns an empty set if the adapter is not discovering. | 326 // Returns an empty set if the adapter is not discovering. |
325 UUIDSet GetServiceDataUUIDs() const; | 327 UUIDSet GetServiceDataUUIDs() const; |
326 | 328 |
327 // Returns a pointer to the Service Data for Service with |uuid|. Returns | 329 // Returns a pointer to the Service Data for Service with |uuid|. Returns |
328 // nullptr if |uuid| has no Service Data. | 330 // nullptr if |uuid| has no Service Data. |
329 const std::vector<uint8_t>* GetServiceDataForUUID( | 331 const std::vector<uint8_t>* GetServiceDataForUUID( |
330 const BluetoothUUID& uuid) const; | 332 const BluetoothUUID& uuid) const; |
331 | 333 |
332 // The received signal strength, in dBm. This field is avaliable and valid | 334 // The received signal strength, in dBm. This field is avaliable and valid |
333 // only during discovery. | 335 // only during discovery. |
334 virtual base::Optional<int8_t> GetInquiryRSSI() const = 0; | 336 virtual base::Optional<int8_t> GetInquiryRSSI() const; |
Jeffrey Yasskin
2016/08/24 04:32:02
Now that these have concrete implementations, does
ortuno
2016/08/24 21:29:09
BlueZ still has a different implementation. I was
Jeffrey Yasskin
2016/08/24 22:32:07
Yep. Maybe a TODO to devirtualize once BlueZ is up
ortuno
2016/08/25 16:42:34
Done.
| |
335 | 337 |
336 // The transmitted power level. This field is avaliable only for LE devices | 338 // 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 | 339 // that include this field in AD. It is avaliable and valid only during |
338 // discovery. | 340 // discovery. |
339 virtual base::Optional<int8_t> GetInquiryTxPower() const = 0; | 341 virtual base::Optional<int8_t> GetInquiryTxPower() const; |
340 | 342 |
341 // The ErrorCallback is used for methods that can fail in which case it | 343 // 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. | 344 // is called, in the success case the callback is simply not called. |
343 typedef base::Callback<void()> ErrorCallback; | 345 typedef base::Callback<void()> ErrorCallback; |
344 | 346 |
345 // The ConnectErrorCallback is used for methods that can fail with an error, | 347 // The ConnectErrorCallback is used for methods that can fail with an error, |
346 // passed back as an error code argument to this callback. | 348 // passed back as an error code argument to this callback. |
347 // In the success case this callback is not called. | 349 // In the success case this callback is not called. |
348 typedef base::Callback<void(enum ConnectErrorCode)> ConnectErrorCallback; | 350 typedef base::Callback<void(enum ConnectErrorCode)> ConnectErrorCallback; |
349 | 351 |
(...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 | 507 // 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 | 508 // each 'X' is a hex digit. If the input |address| is invalid, returns an |
507 // empty string. | 509 // empty string. |
508 static std::string CanonicalizeAddress(const std::string& address); | 510 static std::string CanonicalizeAddress(const std::string& address); |
509 | 511 |
510 // Return the timestamp for when this device was last seen. | 512 // Return the timestamp for when this device was last seen. |
511 base::Time GetLastUpdateTime() const { return last_update_time_; } | 513 base::Time GetLastUpdateTime() const { return last_update_time_; } |
512 | 514 |
513 // Called by BluetoothAdapter when a new Advertisement is seen for this | 515 // Called by BluetoothAdapter when a new Advertisement is seen for this |
514 // device. This replaces previously seen Advertisement Data. | 516 // device. This replaces previously seen Advertisement Data. |
515 void UpdateAdvertisementData(UUIDList advertised_uuids, | 517 void UpdateAdvertisementData(int8_t rssi, |
516 ServiceDataMap service_data); | 518 UUIDList advertised_uuids, |
519 ServiceDataMap service_data, | |
520 const int8_t* tx_power); | |
517 | 521 |
518 // Called by BluetoothAdapter when it stops discoverying. | 522 // Called by BluetoothAdapter when it stops discoverying. |
519 void ClearAdvertisementData(); | 523 void ClearAdvertisementData(); |
520 | 524 |
521 // Return associated BluetoothAdapter. | 525 // Return associated BluetoothAdapter. |
522 BluetoothAdapter* GetAdapter() { return adapter_; } | 526 BluetoothAdapter* GetAdapter() { return adapter_; } |
523 | 527 |
524 protected: | 528 protected: |
525 // BluetoothGattConnection is a friend to call Add/RemoveGattConnection. | 529 // BluetoothGattConnection is a friend to call Add/RemoveGattConnection. |
526 friend BluetoothGattConnection; | 530 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. | 614 // Callbacks for pending success and error result of CreateGattConnection. |
611 std::vector<GattConnectionCallback> create_gatt_connection_success_callbacks_; | 615 std::vector<GattConnectionCallback> create_gatt_connection_success_callbacks_; |
612 std::vector<ConnectErrorCallback> create_gatt_connection_error_callbacks_; | 616 std::vector<ConnectErrorCallback> create_gatt_connection_error_callbacks_; |
613 | 617 |
614 // BluetoothGattConnection objects keeping the GATT connection alive. | 618 // BluetoothGattConnection objects keeping the GATT connection alive. |
615 std::set<BluetoothGattConnection*> gatt_connections_; | 619 std::set<BluetoothGattConnection*> gatt_connections_; |
616 | 620 |
617 GattServiceMap gatt_services_; | 621 GattServiceMap gatt_services_; |
618 bool gatt_services_discovery_complete_; | 622 bool gatt_services_discovery_complete_; |
619 | 623 |
624 // Received Signal Strength Indicator of the advertisement received. | |
625 base::Optional<int8_t> inquiry_rssi_; | |
626 | |
627 // Tx Power advertised by the device. | |
628 base::Optional<int8_t> inquiry_tx_power_; | |
629 | |
620 // Class that holds the union of Advertised UUIDs and Service UUIDs. | 630 // Class that holds the union of Advertised UUIDs and Service UUIDs. |
621 DeviceUUIDs device_uuids_; | 631 DeviceUUIDs device_uuids_; |
622 | 632 |
623 // Map of BluetoothUUIDs to their advertised Service Data. | 633 // Map of BluetoothUUIDs to their advertised Service Data. |
624 ServiceDataMap service_data_; | 634 ServiceDataMap service_data_; |
625 | 635 |
626 // Timestamp for when an advertisement was last seen. | 636 // Timestamp for when an advertisement was last seen. |
627 base::Time last_update_time_; | 637 base::Time last_update_time_; |
628 | 638 |
629 private: | 639 private: |
630 // Returns a localized string containing the device's bluetooth address and | 640 // Returns a localized string containing the device's bluetooth address and |
631 // a device type for display when |name_| is empty. | 641 // a device type for display when |name_| is empty. |
632 base::string16 GetAddressWithLocalizedDeviceTypeName() const; | 642 base::string16 GetAddressWithLocalizedDeviceTypeName() const; |
633 }; | 643 }; |
634 | 644 |
635 } // namespace device | 645 } // namespace device |
636 | 646 |
637 #endif // DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_ | 647 #endif // DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_ |
OLD | NEW |