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; |
| 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. |
| 331 // |
| 332 // Note: On ChromeOS and Linux, BlueZ persists all manufacturer data meaning |
| 333 // if a device stops advertising manufacturer data for a Manufacturer Id, this |
| 334 // function will still return the cached value for that Id. |
| 335 // |
| 336 // TODO(crbug.com/661814) Support this on platforms that don't use BlueZ. |
| 337 // Only BlueZ supports this now. This method returns an empty map on platforms |
| 338 // that don't use BlueZ. |
| 339 const ManufacturerDataMap& GetManufacturerData() const; |
| 340 |
| 341 // Returns the Manufacturer Data IDs of Manufacturers for which the device |
| 342 // advertises Manufacturer Data. |
| 343 // Returns cached value if the adapter is not discovering. |
| 344 ManufacturerIDSet GetManufacturerDataIDs() const; |
| 345 |
| 346 // Returns a pointer to the Manufacturer Data for Manufacturer with |
| 347 // |manufacturerID|. Returns nullptr if |manufacturerID| has no Manufacturer |
| 348 // Data. Returns cached value if the adapter is not discovering. |
| 349 const std::vector<uint8_t>* GetManufacturerDataForID( |
| 350 const ManufacturerId manufacturerID) const; |
| 351 |
322 // The received signal strength, in dBm. This field is avaliable and valid | 352 // The received signal strength, in dBm. This field is avaliable and valid |
323 // only during discovery. | 353 // only during discovery. |
324 // TODO(http://crbug.com/580406): Devirtualize once BlueZ sets inquiry_rssi_. | 354 // TODO(http://crbug.com/580406): Devirtualize once BlueZ sets inquiry_rssi_. |
325 virtual base::Optional<int8_t> GetInquiryRSSI() const; | 355 virtual base::Optional<int8_t> GetInquiryRSSI() const; |
326 | 356 |
327 // The transmitted power level. This field is avaliable only for LE devices | 357 // 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 | 358 // that include this field in AD. It is avaliable and valid only during |
329 // discovery. | 359 // discovery. |
330 // TODO(http://crbug.com/580406): Devirtualize once BlueZ sets | 360 // TODO(http://crbug.com/580406): Devirtualize once BlueZ sets |
331 // inquiry_tx_power_. | 361 // inquiry_tx_power_. |
332 virtual base::Optional<int8_t> GetInquiryTxPower() const; | 362 virtual base::Optional<int8_t> GetInquiryTxPower() const; |
333 | 363 |
| 364 // Returns Advertising Data Flags. |
| 365 // Returns cached value if the adapter is not discovering. |
| 366 // |
| 367 // TODO(crbug.com/661814) Support this on platforms that don't use BlueZ. |
| 368 // Only Chrome OS supports this now. Upstream BlueZ has this feature |
| 369 // as experimental. This method returns base::nullopt on platforms that don't |
| 370 // support this feature. |
| 371 base::Optional<uint8_t> GetAdvertisingDataFlags() const; |
| 372 |
334 // The ErrorCallback is used for methods that can fail in which case it | 373 // 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. | 374 // is called, in the success case the callback is simply not called. |
336 typedef base::Callback<void()> ErrorCallback; | 375 typedef base::Callback<void()> ErrorCallback; |
337 | 376 |
338 // The ConnectErrorCallback is used for methods that can fail with an error, | 377 // The ConnectErrorCallback is used for methods that can fail with an error, |
339 // passed back as an error code argument to this callback. | 378 // passed back as an error code argument to this callback. |
340 // In the success case this callback is not called. | 379 // In the success case this callback is not called. |
341 typedef base::Callback<void(enum ConnectErrorCode)> ConnectErrorCallback; | 380 typedef base::Callback<void(enum ConnectErrorCode)> ConnectErrorCallback; |
342 | 381 |
343 typedef base::Callback<void(const ConnectionInfo&)> ConnectionInfoCallback; | 382 typedef base::Callback<void(const ConnectionInfo&)> ConnectionInfoCallback; |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
612 | 651 |
613 GattServiceMap gatt_services_; | 652 GattServiceMap gatt_services_; |
614 bool gatt_services_discovery_complete_; | 653 bool gatt_services_discovery_complete_; |
615 | 654 |
616 // Received Signal Strength Indicator of the advertisement received. | 655 // Received Signal Strength Indicator of the advertisement received. |
617 base::Optional<int8_t> inquiry_rssi_; | 656 base::Optional<int8_t> inquiry_rssi_; |
618 | 657 |
619 // Tx Power advertised by the device. | 658 // Tx Power advertised by the device. |
620 base::Optional<int8_t> inquiry_tx_power_; | 659 base::Optional<int8_t> inquiry_tx_power_; |
621 | 660 |
| 661 // Advertising Data flags of the device. |
| 662 base::Optional<uint8_t> advertising_data_flags_; |
| 663 |
622 // Class that holds the union of Advertised UUIDs and Service UUIDs. | 664 // Class that holds the union of Advertised UUIDs and Service UUIDs. |
623 DeviceUUIDs device_uuids_; | 665 DeviceUUIDs device_uuids_; |
624 | 666 |
625 // Map of BluetoothUUIDs to their advertised Service Data. | 667 // Map of BluetoothUUIDs to their advertised Service Data. |
626 ServiceDataMap service_data_; | 668 ServiceDataMap service_data_; |
627 | 669 |
| 670 // Map of Manufacturer IDs to their advertised Manufacturer Data. |
| 671 ManufacturerDataMap manufacturer_data_; |
| 672 |
628 // Timestamp for when an advertisement was last seen. | 673 // Timestamp for when an advertisement was last seen. |
629 base::Time last_update_time_; | 674 base::Time last_update_time_; |
630 | 675 |
631 private: | 676 private: |
632 // Returns a localized string containing the device's bluetooth address and | 677 // Returns a localized string containing the device's bluetooth address and |
633 // a device type for display when |name_| is empty. | 678 // a device type for display when |name_| is empty. |
634 base::string16 GetAddressWithLocalizedDeviceTypeName() const; | 679 base::string16 GetAddressWithLocalizedDeviceTypeName() const; |
635 }; | 680 }; |
636 | 681 |
637 } // namespace device | 682 } // namespace device |
638 | 683 |
639 #endif // DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_ | 684 #endif // DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_ |
OLD | NEW |