OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_LOW_ENERGY_DEVICE_MAC_H_ | 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DEVICE_MAC_H_ |
6 #define DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DEVICE_MAC_H_ | 6 #define DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DEVICE_MAC_H_ |
7 | 7 |
8 #if defined(OS_IOS) | 8 #if defined(OS_IOS) |
9 #import <CoreBluetooth/CoreBluetooth.h> | 9 #import <CoreBluetooth/CoreBluetooth.h> |
10 #else // !defined(OS_IOS) | 10 #else // !defined(OS_IOS) |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 void Forget(const base::Closure& callback, | 72 void Forget(const base::Closure& callback, |
73 const ErrorCallback& error_callback) override; | 73 const ErrorCallback& error_callback) override; |
74 void ConnectToService( | 74 void ConnectToService( |
75 const BluetoothUUID& uuid, | 75 const BluetoothUUID& uuid, |
76 const ConnectToServiceCallback& callback, | 76 const ConnectToServiceCallback& callback, |
77 const ConnectToServiceErrorCallback& error_callback) override; | 77 const ConnectToServiceErrorCallback& error_callback) override; |
78 void ConnectToServiceInsecurely( | 78 void ConnectToServiceInsecurely( |
79 const device::BluetoothUUID& uuid, | 79 const device::BluetoothUUID& uuid, |
80 const ConnectToServiceCallback& callback, | 80 const ConnectToServiceCallback& callback, |
81 const ConnectToServiceErrorCallback& error_callback) override; | 81 const ConnectToServiceErrorCallback& error_callback) override; |
82 void CreateGattConnection( | |
83 const GattConnectionCallback& callback, | |
84 const ConnectErrorCallback& error_callback) override; | |
85 | 82 |
86 // BluetoothDeviceMac override. | 83 // BluetoothDeviceMac override. |
87 NSDate* GetLastUpdateTime() const override; | 84 NSDate* GetLastUpdateTime() const override; |
88 | 85 |
89 protected: | 86 protected: |
90 // BluetoothDevice override. | 87 // BluetoothDevice override. |
91 std::string GetDeviceName() const override; | 88 std::string GetDeviceName() const override; |
92 void CreateGattConnectionImpl() override; | 89 void CreateGattConnectionImpl() override; |
93 void DisconnectGatt() override; | 90 void DisconnectGatt() override; |
94 | 91 |
95 // Updates information about the device. | 92 // Updates information about the device. |
96 virtual void Update(CBPeripheral* peripheral, | 93 virtual void Update(CBPeripheral* peripheral, |
97 NSDictionary* advertisement_data, | 94 NSDictionary* advertisement_data, |
98 int rssi); | 95 int rssi); |
99 | 96 |
100 static std::string GetPeripheralIdentifier(CBPeripheral* peripheral); | 97 static std::string GetPeripheralIdentifier(CBPeripheral* peripheral); |
101 | 98 |
102 // Hashes and truncates the peripheral identifier to deterministically | 99 // Hashes and truncates the peripheral identifier to deterministically |
103 // construct an address. The use of fake addresses is a temporary fix before | 100 // construct an address. The use of fake addresses is a temporary fix before |
104 // we switch to using bluetooth identifiers throughout Chrome. | 101 // we switch to using bluetooth identifiers throughout Chrome. |
105 // http://crbug.com/507824 | 102 // http://crbug.com/507824 |
106 static std::string GetPeripheralHashAddress(CBPeripheral* peripheral); | 103 static std::string GetPeripheralHashAddress(CBPeripheral* peripheral); |
107 | 104 |
108 private: | 105 private: |
109 friend class BluetoothAdapterMac; | 106 friend class BluetoothAdapterMac; |
110 friend class BluetoothAdapterMacTest; | 107 friend class BluetoothAdapterMacTest; |
| 108 friend class BluetoothTestMac; |
| 109 |
| 110 // Returns the Bluetooth adapter. |
| 111 BluetoothAdapterMac* GetMacAdapter(); |
| 112 |
| 113 // Returns the CoreBluetooth Peripheral. |
| 114 CBPeripheral* GetPeripheral(); |
| 115 |
| 116 // Callback used when the CoreBluetooth Peripheral is disconnected. |
| 117 void DidDisconnectPeripheral(); |
111 | 118 |
112 // CoreBluetooth data structure. | 119 // CoreBluetooth data structure. |
113 base::scoped_nsobject<CBPeripheral> peripheral_; | 120 base::scoped_nsobject<CBPeripheral> peripheral_; |
114 | 121 |
115 // RSSI value. | 122 // RSSI value. |
116 int rssi_; | 123 int rssi_; |
117 | 124 |
118 // Whether the device is connectable. | 125 // Whether the device is connectable. |
119 bool connectable_; | 126 bool connectable_; |
120 | 127 |
121 // The peripheral's identifier, as returned by [CBPeripheral identifier]. | 128 // The peripheral's identifier, as returned by [CBPeripheral identifier]. |
122 std::string identifier_; | 129 std::string identifier_; |
123 | 130 |
124 // A local address for the device created by hashing the peripheral | 131 // A local address for the device created by hashing the peripheral |
125 // identifier. | 132 // identifier. |
126 std::string hash_address_; | 133 std::string hash_address_; |
127 | 134 |
128 // Stores the time of the most recent call to Update(). | 135 // Stores the time of the most recent call to Update(). |
129 base::scoped_nsobject<NSDate> last_update_time_; | 136 base::scoped_nsobject<NSDate> last_update_time_; |
130 | 137 |
131 // The services (identified by UUIDs) that this device provides. | 138 // The services (identified by UUIDs) that this device provides. |
132 std::set<BluetoothUUID> advertised_uuids_; | 139 std::set<BluetoothUUID> advertised_uuids_; |
133 | 140 |
134 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyDeviceMac); | 141 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyDeviceMac); |
135 }; | 142 }; |
136 | 143 |
137 } // namespace device | 144 } // namespace device |
138 | 145 |
139 #endif // DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DEVICE_MAC_H_ | 146 #endif // DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DEVICE_MAC_H_ |
OLD | NEW |