Chromium Code Reviews| 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 |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <set> | 12 #include <set> |
| 13 #include <string> | 13 #include <string> |
| 14 #include <unordered_map> | |
| 14 #include <unordered_set> | 15 #include <unordered_set> |
| 15 #include <vector> | 16 #include <vector> |
| 16 | 17 |
| 17 #include "base/callback.h" | 18 #include "base/callback.h" |
| 18 #include "base/containers/scoped_ptr_hash_map.h" | 19 #include "base/containers/scoped_ptr_hash_map.h" |
| 19 #include "base/gtest_prod_util.h" | 20 #include "base/gtest_prod_util.h" |
| 20 #include "base/memory/ref_counted.h" | 21 #include "base/memory/ref_counted.h" |
| 21 #include "base/optional.h" | 22 #include "base/optional.h" |
| 22 #include "base/strings/string16.h" | 23 #include "base/strings/string16.h" |
| 23 #include "base/time/time.h" | 24 #include "base/time/time.h" |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 ERROR_WRITE_NOT_PERMITTED, | 96 ERROR_WRITE_NOT_PERMITTED, |
| 96 NUM_CONNECT_ERROR_CODES // Keep as last enum. | 97 NUM_CONNECT_ERROR_CODES // Keep as last enum. |
| 97 }; | 98 }; |
| 98 | 99 |
| 99 typedef std::vector<BluetoothUUID> UUIDList; | 100 typedef std::vector<BluetoothUUID> UUIDList; |
| 100 typedef std::unordered_set<BluetoothUUID, BluetoothUUIDHash> UUIDSet; | 101 typedef std::unordered_set<BluetoothUUID, BluetoothUUIDHash> UUIDSet; |
| 101 typedef std::unordered_map<BluetoothUUID, | 102 typedef std::unordered_map<BluetoothUUID, |
| 102 std::vector<uint8_t>, | 103 std::vector<uint8_t>, |
| 103 BluetoothUUIDHash> | 104 BluetoothUUIDHash> |
| 104 ServiceDataMap; | 105 ServiceDataMap; |
| 106 typedef uint16_t ManufacturerID; | |
|
ortuno
2016/10/18 01:41:18
nit: s/ID/Id/ here and below. Though it really doe
puthik_chromium
2016/11/02 23:20:38
Done.
| |
| 107 typedef std::unordered_map<ManufacturerID, std::vector<uint8_t>> | |
| 108 ManufacturerDataMap; | |
| 109 typedef std::unordered_set<ManufacturerID> ManufacturerIDSet; | |
| 105 | 110 |
| 106 // Mapping from the platform-specific GATT service identifiers to | 111 // Mapping from the platform-specific GATT service identifiers to |
| 107 // BluetoothRemoteGattService objects. | 112 // BluetoothRemoteGattService objects. |
| 108 typedef base::ScopedPtrHashMap<std::string, | 113 typedef base::ScopedPtrHashMap<std::string, |
| 109 std::unique_ptr<BluetoothRemoteGattService>> | 114 std::unique_ptr<BluetoothRemoteGattService>> |
| 110 GattServiceMap; | 115 GattServiceMap; |
| 111 | 116 |
| 112 // Interface for negotiating pairing of bluetooth devices. | 117 // Interface for negotiating pairing of bluetooth devices. |
| 113 class PairingDelegate { | 118 class PairingDelegate { |
| 114 public: | 119 public: |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 312 | 317 |
| 313 // Returns the UUIDs of services for which the device advertises Service Data. | 318 // Returns the UUIDs of services for which the device advertises Service Data. |
| 314 // Returns an empty set if the adapter is not discovering. | 319 // Returns an empty set if the adapter is not discovering. |
| 315 UUIDSet GetServiceDataUUIDs() const; | 320 UUIDSet GetServiceDataUUIDs() const; |
| 316 | 321 |
| 317 // Returns a pointer to the Service Data for Service with |uuid|. Returns | 322 // Returns a pointer to the Service Data for Service with |uuid|. Returns |
| 318 // nullptr if |uuid| has no Service Data. | 323 // nullptr if |uuid| has no Service Data. |
| 319 const std::vector<uint8_t>* GetServiceDataForUUID( | 324 const std::vector<uint8_t>* GetServiceDataForUUID( |
| 320 const BluetoothUUID& uuid) const; | 325 const BluetoothUUID& uuid) const; |
| 321 | 326 |
| 327 // Returns advertised Manufacturer Data. Keys are 16 bits Manufacturer IDs | |
| 328 // followed by its byte array value. Returns an empty map if the device | |
| 329 // does not advertise any Manufacturer Data. | |
| 330 // Returns cached value if the adapter is not discovering. | |
|
ortuno
2016/10/18 01:41:18
What about changing Manufacturer Data? Does BlueZ
puthik_chromium
2016/11/02 23:20:38
Done.
| |
| 331 // | |
| 332 // Note that only BlueZ supports this now. This method returns an empty map | |
| 333 // on platforms that don't use BlueZ. | |
|
ortuno
2016/10/18 01:41:18
Could you open an issue to implement this on other
puthik_chromium
2016/11/02 23:20:38
Done.
| |
| 334 const ManufacturerDataMap& GetManufacturerData() const; | |
| 335 | |
| 336 // Returns the Manufacturer Data IDs of Manufacturers for which the device | |
| 337 // advertises Manufacturer Data. | |
| 338 // Returns cached value if the adapter is not discovering. | |
| 339 ManufacturerIDSet GetManufacturerDataIDs() const; | |
| 340 | |
| 341 // Returns a pointer to the Manufacturer Data for Manufacturer with | |
| 342 // |manufacturerID|. Returns nullptr if |manufacturerID| has no Manufacturer | |
| 343 // Data. Returns cached value if the adapter is not discovering. | |
| 344 const std::vector<uint8_t>* GetManufacturerDataForID( | |
| 345 const ManufacturerID manufacturerID) const; | |
| 346 | |
| 322 // The received signal strength, in dBm. This field is avaliable and valid | 347 // The received signal strength, in dBm. This field is avaliable and valid |
| 323 // only during discovery. | 348 // only during discovery. |
| 324 // TODO(http://crbug.com/580406): Devirtualize once BlueZ sets inquiry_rssi_. | 349 // TODO(http://crbug.com/580406): Devirtualize once BlueZ sets inquiry_rssi_. |
| 325 virtual base::Optional<int8_t> GetInquiryRSSI() const; | 350 virtual base::Optional<int8_t> GetInquiryRSSI() const; |
| 326 | 351 |
| 327 // The transmitted power level. This field is avaliable only for LE devices | 352 // The transmitted power level. This field is avaliable only for LE devices |
| 328 // that include this field in AD. It is avaliable and valid only during | 353 // that include this field in AD. It is avaliable and valid only during |
| 329 // discovery. | 354 // discovery. |
| 330 // TODO(http://crbug.com/580406): Devirtualize once BlueZ sets | 355 // TODO(http://crbug.com/580406): Devirtualize once BlueZ sets |
| 331 // inquiry_tx_power_. | 356 // inquiry_tx_power_. |
| 332 virtual base::Optional<int8_t> GetInquiryTxPower() const; | 357 virtual base::Optional<int8_t> GetInquiryTxPower() const; |
| 333 | 358 |
| 359 // Returns Advertising Data Flags. | |
| 360 // Returns cached value if the adapter is not discovering. | |
| 361 // | |
| 362 // Note that only BlueZ supports this now. This method returns base::nullopt | |
|
ortuno
2016/10/18 01:41:18
s/BlueZ/Chrome OS/ Also could you open an issue re
puthik_chromium
2016/11/02 23:20:38
Done.
| |
| 363 // on platforms that don't use BlueZ. | |
| 364 virtual base::Optional<uint8_t> GetAdvertisingDataFlags() const; | |
| 365 | |
| 334 // The ErrorCallback is used for methods that can fail in which case it | 366 // The ErrorCallback is used for methods that can fail in which case it |
| 335 // is called, in the success case the callback is simply not called. | 367 // is called, in the success case the callback is simply not called. |
| 336 typedef base::Callback<void()> ErrorCallback; | 368 typedef base::Callback<void()> ErrorCallback; |
| 337 | 369 |
| 338 // The ConnectErrorCallback is used for methods that can fail with an error, | 370 // The ConnectErrorCallback is used for methods that can fail with an error, |
| 339 // passed back as an error code argument to this callback. | 371 // passed back as an error code argument to this callback. |
| 340 // In the success case this callback is not called. | 372 // In the success case this callback is not called. |
| 341 typedef base::Callback<void(enum ConnectErrorCode)> ConnectErrorCallback; | 373 typedef base::Callback<void(enum ConnectErrorCode)> ConnectErrorCallback; |
| 342 | 374 |
| 343 typedef base::Callback<void(const ConnectionInfo&)> ConnectionInfoCallback; | 375 typedef base::Callback<void(const ConnectionInfo&)> ConnectionInfoCallback; |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 618 | 650 |
| 619 // Tx Power advertised by the device. | 651 // Tx Power advertised by the device. |
| 620 base::Optional<int8_t> inquiry_tx_power_; | 652 base::Optional<int8_t> inquiry_tx_power_; |
| 621 | 653 |
| 622 // Class that holds the union of Advertised UUIDs and Service UUIDs. | 654 // Class that holds the union of Advertised UUIDs and Service UUIDs. |
| 623 DeviceUUIDs device_uuids_; | 655 DeviceUUIDs device_uuids_; |
| 624 | 656 |
| 625 // Map of BluetoothUUIDs to their advertised Service Data. | 657 // Map of BluetoothUUIDs to their advertised Service Data. |
| 626 ServiceDataMap service_data_; | 658 ServiceDataMap service_data_; |
| 627 | 659 |
| 660 // Map of Manufacturer IDs to their advertised Manufacturer Data. | |
| 661 ManufacturerDataMap manufacturer_data_; | |
| 662 | |
| 628 // Timestamp for when an advertisement was last seen. | 663 // Timestamp for when an advertisement was last seen. |
| 629 base::Time last_update_time_; | 664 base::Time last_update_time_; |
| 630 | 665 |
| 631 private: | 666 private: |
| 632 // Returns a localized string containing the device's bluetooth address and | 667 // Returns a localized string containing the device's bluetooth address and |
| 633 // a device type for display when |name_| is empty. | 668 // a device type for display when |name_| is empty. |
| 634 base::string16 GetAddressWithLocalizedDeviceTypeName() const; | 669 base::string16 GetAddressWithLocalizedDeviceTypeName() const; |
| 635 }; | 670 }; |
| 636 | 671 |
| 637 } // namespace device | 672 } // namespace device |
| 638 | 673 |
| 639 #endif // DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_ | 674 #endif // DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_ |
| OLD | NEW |