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_map> |
15 #include <unordered_set> | 15 #include <unordered_set> |
16 #include <vector> | 16 #include <vector> |
17 | 17 |
18 #include "base/callback.h" | 18 #include "base/callback.h" |
19 #include "base/containers/scoped_ptr_hash_map.h" | |
20 #include "base/gtest_prod_util.h" | 19 #include "base/gtest_prod_util.h" |
| 20 #include "base/macros.h" |
21 #include "base/memory/ref_counted.h" | 21 #include "base/memory/ref_counted.h" |
22 #include "base/optional.h" | 22 #include "base/optional.h" |
23 #include "base/strings/string16.h" | 23 #include "base/strings/string16.h" |
24 #include "base/time/time.h" | 24 #include "base/time/time.h" |
25 #include "device/bluetooth/bluetooth_common.h" | 25 #include "device/bluetooth/bluetooth_common.h" |
26 #include "device/bluetooth/bluetooth_export.h" | 26 #include "device/bluetooth/bluetooth_export.h" |
| 27 #include "device/bluetooth/bluetooth_remote_gatt_service.h" |
27 #include "device/bluetooth/bluetooth_uuid.h" | 28 #include "device/bluetooth/bluetooth_uuid.h" |
28 | 29 |
29 namespace device { | 30 namespace device { |
30 | 31 |
31 class BluetoothAdapter; | 32 class BluetoothAdapter; |
32 class BluetoothGattConnection; | 33 class BluetoothGattConnection; |
33 class BluetoothRemoteGattService; | |
34 class BluetoothSocket; | 34 class BluetoothSocket; |
35 class BluetoothUUID; | 35 class BluetoothUUID; |
36 | 36 |
37 // BluetoothDevice represents a remote Bluetooth device, both its properties and | 37 // BluetoothDevice represents a remote Bluetooth device, both its properties and |
38 // capabilities as discovered by a local adapter and actions that may be | 38 // capabilities as discovered by a local adapter and actions that may be |
39 // performed on the remove device such as pairing, connection and disconnection. | 39 // performed on the remove device such as pairing, connection and disconnection. |
40 // | 40 // |
41 // The class is instantiated and managed by the BluetoothAdapter class | 41 // The class is instantiated and managed by the BluetoothAdapter class |
42 // and pointers should only be obtained from that class and not cached, | 42 // and pointers should only be obtained from that class and not cached, |
43 // instead use the GetAddress() method as a unique key for a device. | 43 // instead use the GetAddress() method as a unique key for a device. |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 std::vector<uint8_t>, | 99 std::vector<uint8_t>, |
100 BluetoothUUIDHash> | 100 BluetoothUUIDHash> |
101 ServiceDataMap; | 101 ServiceDataMap; |
102 typedef uint16_t ManufacturerId; | 102 typedef uint16_t ManufacturerId; |
103 typedef std::unordered_map<ManufacturerId, std::vector<uint8_t>> | 103 typedef std::unordered_map<ManufacturerId, std::vector<uint8_t>> |
104 ManufacturerDataMap; | 104 ManufacturerDataMap; |
105 typedef std::unordered_set<ManufacturerId> ManufacturerIDSet; | 105 typedef std::unordered_set<ManufacturerId> ManufacturerIDSet; |
106 | 106 |
107 // Mapping from the platform-specific GATT service identifiers to | 107 // Mapping from the platform-specific GATT service identifiers to |
108 // BluetoothRemoteGattService objects. | 108 // BluetoothRemoteGattService objects. |
109 typedef base::ScopedPtrHashMap<std::string, | 109 typedef std::unordered_map<std::string, |
110 std::unique_ptr<BluetoothRemoteGattService>> | 110 std::unique_ptr<BluetoothRemoteGattService>> |
111 GattServiceMap; | 111 GattServiceMap; |
112 | 112 |
113 // Interface for negotiating pairing of bluetooth devices. | 113 // Interface for negotiating pairing of bluetooth devices. |
114 class PairingDelegate { | 114 class PairingDelegate { |
115 public: | 115 public: |
116 virtual ~PairingDelegate() {} | 116 virtual ~PairingDelegate() {} |
117 | 117 |
118 // This method will be called when the Bluetooth daemon requires a | 118 // This method will be called when the Bluetooth daemon requires a |
119 // PIN Code for authentication of the device |device|, the delegate should | 119 // PIN Code for authentication of the device |device|, the delegate should |
120 // obtain the code from the user and call SetPinCode() on the device to | 120 // obtain the code from the user and call SetPinCode() on the device to |
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
572 FRIEND_TEST_ALL_PREFIXES(BluetoothTest, RemoveOutdatedDevices); | 572 FRIEND_TEST_ALL_PREFIXES(BluetoothTest, RemoveOutdatedDevices); |
573 FRIEND_TEST_ALL_PREFIXES(BluetoothTest, RemoveOutdatedDeviceGattConnect); | 573 FRIEND_TEST_ALL_PREFIXES(BluetoothTest, RemoveOutdatedDeviceGattConnect); |
574 | 574 |
575 // Helper class to easily update the sets of UUIDs and keep them in sync with | 575 // Helper class to easily update the sets of UUIDs and keep them in sync with |
576 // the set of all the device's UUIDs. | 576 // the set of all the device's UUIDs. |
577 class DeviceUUIDs { | 577 class DeviceUUIDs { |
578 public: | 578 public: |
579 DeviceUUIDs(); | 579 DeviceUUIDs(); |
580 ~DeviceUUIDs(); | 580 ~DeviceUUIDs(); |
581 | 581 |
| 582 DeviceUUIDs(const DeviceUUIDs& other); |
| 583 DeviceUUIDs& operator=(const DeviceUUIDs& other); |
| 584 |
582 // Advertised Service UUIDs functions | 585 // Advertised Service UUIDs functions |
583 void ReplaceAdvertisedUUIDs(UUIDList new_advertised_uuids); | 586 void ReplaceAdvertisedUUIDs(UUIDList new_advertised_uuids); |
584 | 587 |
585 void ClearAdvertisedUUIDs(); | 588 void ClearAdvertisedUUIDs(); |
586 | 589 |
587 // Service UUIDs functions | 590 // Service UUIDs functions |
588 void ReplaceServiceUUIDs( | 591 void ReplaceServiceUUIDs( |
589 const BluetoothDevice::GattServiceMap& gatt_services); | 592 const BluetoothDevice::GattServiceMap& gatt_services); |
590 | 593 |
591 void ClearServiceUUIDs(); | 594 void ClearServiceUUIDs(); |
592 | 595 |
593 // Returns the union of Advertised UUIDs and Service UUIDs. | 596 // Returns the union of Advertised UUIDs and Service UUIDs. |
594 const UUIDSet& GetUUIDs() const; | 597 const UUIDSet& GetUUIDs() const; |
595 | 598 |
596 private: | 599 private: |
597 void UpdateDeviceUUIDs(); | 600 void UpdateDeviceUUIDs(); |
598 | 601 |
599 BluetoothDevice::UUIDSet advertised_uuids_; | 602 BluetoothDevice::UUIDSet advertised_uuids_; |
600 BluetoothDevice::UUIDSet service_uuids_; | 603 BluetoothDevice::UUIDSet service_uuids_; |
601 BluetoothDevice::UUIDSet device_uuids_; | 604 BluetoothDevice::UUIDSet device_uuids_; |
602 }; | 605 }; |
603 | 606 |
604 BluetoothDevice(BluetoothAdapter* adapter); | 607 explicit BluetoothDevice(BluetoothAdapter* adapter); |
605 | 608 |
606 // Implements platform specific operations to initiate a GATT connection. | 609 // Implements platform specific operations to initiate a GATT connection. |
607 // Subclasses must also call DidConnectGatt, DidFailToConnectGatt, or | 610 // Subclasses must also call DidConnectGatt, DidFailToConnectGatt, or |
608 // DidDisconnectGatt immediately or asynchronously as the connection state | 611 // DidDisconnectGatt immediately or asynchronously as the connection state |
609 // changes. | 612 // changes. |
610 virtual void CreateGattConnectionImpl() = 0; | 613 virtual void CreateGattConnectionImpl() = 0; |
611 | 614 |
612 // Disconnects GATT connection on platforms that maintain a specific GATT | 615 // Disconnects GATT connection on platforms that maintain a specific GATT |
613 // connection. | 616 // connection. |
614 virtual void DisconnectGatt() = 0; | 617 virtual void DisconnectGatt() = 0; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
666 // Map of Manufacturer IDs to their advertised Manufacturer Data. | 669 // Map of Manufacturer IDs to their advertised Manufacturer Data. |
667 ManufacturerDataMap manufacturer_data_; | 670 ManufacturerDataMap manufacturer_data_; |
668 | 671 |
669 // Timestamp for when an advertisement was last seen. | 672 // Timestamp for when an advertisement was last seen. |
670 base::Time last_update_time_; | 673 base::Time last_update_time_; |
671 | 674 |
672 private: | 675 private: |
673 // Returns a localized string containing the device's bluetooth address and | 676 // Returns a localized string containing the device's bluetooth address and |
674 // a device type for display when |name_| is empty. | 677 // a device type for display when |name_| is empty. |
675 base::string16 GetAddressWithLocalizedDeviceTypeName() const; | 678 base::string16 GetAddressWithLocalizedDeviceTypeName() const; |
| 679 |
| 680 DISALLOW_COPY_AND_ASSIGN(BluetoothDevice); |
676 }; | 681 }; |
677 | 682 |
678 } // namespace device | 683 } // namespace device |
679 | 684 |
680 #endif // DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_ | 685 #endif // DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_ |
OLD | NEW |