| 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) |
| 11 #import <IOBluetooth/IOBluetooth.h> | 11 #import <IOBluetooth/IOBluetooth.h> |
| 12 #endif // defined(OS_IOS) | 12 #endif // defined(OS_IOS) |
| 13 | 13 |
| 14 #include <set> | 14 #include <set> |
| 15 | 15 |
| 16 #include "base/mac/scoped_nsobject.h" | 16 #include "base/mac/scoped_nsobject.h" |
| 17 #include "base/mac/sdk_forward_declarations.h" | 17 #include "base/mac/sdk_forward_declarations.h" |
| 18 #include "crypto/sha2.h" | 18 #include "crypto/sha2.h" |
| 19 #include "device/bluetooth/bluetooth_adapter.h" |
| 19 #include "device/bluetooth/bluetooth_device_mac.h" | 20 #include "device/bluetooth/bluetooth_device_mac.h" |
| 20 | 21 |
| 21 namespace device { | 22 namespace device { |
| 22 | 23 |
| 23 class BluetoothLowEnergyDiscoverManagerMac; | 24 class BluetoothLowEnergyDiscoverManagerMac; |
| 24 | 25 |
| 25 class DEVICE_BLUETOOTH_EXPORT BluetoothLowEnergyDeviceMac | 26 class DEVICE_BLUETOOTH_EXPORT BluetoothLowEnergyDeviceMac |
| 26 : public BluetoothDeviceMac { | 27 : public BluetoothDeviceMac { |
| 27 public: | 28 public: |
| 28 BluetoothLowEnergyDeviceMac(CBPeripheral* peripheral, | 29 BluetoothLowEnergyDeviceMac(CBPeripheral* peripheral, |
| 29 NSDictionary* advertisement_data, | 30 NSDictionary* advertisement_data, |
| 30 int rssi); | 31 int rssi, |
| 32 BluetoothAdapter* adapter, |
| 33 CBCentralManager* central_manager); |
| 31 ~BluetoothLowEnergyDeviceMac() override; | 34 ~BluetoothLowEnergyDeviceMac() override; |
| 32 | 35 |
| 33 int GetRSSI() const; | 36 int GetRSSI() const; |
| 34 | 37 |
| 35 // BluetoothDevice overrides. | 38 // BluetoothDevice overrides. |
| 36 std::string GetIdentifier() const override; | 39 std::string GetIdentifier() const override; |
| 37 uint32 GetBluetoothClass() const override; | 40 uint32 GetBluetoothClass() const override; |
| 38 std::string GetAddress() const override; | 41 std::string GetAddress() const override; |
| 39 BluetoothDevice::VendorIDSource GetVendorIDSource() const override; | 42 BluetoothDevice::VendorIDSource GetVendorIDSource() const override; |
| 40 uint16 GetVendorID() const override; | 43 uint16 GetVendorID() const override; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 | 93 |
| 91 // Hashes and truncates the peripheral identifier to deterministically | 94 // Hashes and truncates the peripheral identifier to deterministically |
| 92 // construct an address. The use of fake addresses is a temporary fix before | 95 // construct an address. The use of fake addresses is a temporary fix before |
| 93 // we switch to using bluetooth identifiers throughout Chrome. | 96 // we switch to using bluetooth identifiers throughout Chrome. |
| 94 // http://crbug.com/507824 | 97 // http://crbug.com/507824 |
| 95 static std::string GetPeripheralHashAddress(CBPeripheral* peripheral); | 98 static std::string GetPeripheralHashAddress(CBPeripheral* peripheral); |
| 96 | 99 |
| 97 private: | 100 private: |
| 98 friend class BluetoothAdapterMac; | 101 friend class BluetoothAdapterMac; |
| 99 friend class BluetoothAdapterMacTest; | 102 friend class BluetoothAdapterMacTest; |
| 103 friend class BluetoothGattConnectionMac; |
| 100 | 104 |
| 101 // Equivalent to [peripheral_ state]. Allows compilation on OS X 10.6. | 105 // Equivalent to [peripheral_ state]. Allows compilation on OS X 10.6. |
| 102 CBPeripheralState GetPeripheralState() const; | 106 CBPeripheralState GetPeripheralState() const; |
| 103 | 107 |
| 104 // CoreBluetooth data structure. | 108 // Convenience method to clear the four callback vectors. |
| 109 void ClearConnectionCallbacks(); |
| 110 |
| 111 // Underylying CoreBluetooth representation of the bluetooth device. |
| 105 base::scoped_nsobject<CBPeripheral> peripheral_; | 112 base::scoped_nsobject<CBPeripheral> peripheral_; |
| 106 | 113 |
| 114 // Underlying CoreBluetooth CBCentralManager. |
| 115 CBCentralManager* central_manager_ = nil; |
| 116 |
| 117 // The adapter that owns this device instance. |
| 118 BluetoothAdapter* adapter_ = NULL; |
| 119 |
| 107 // RSSI value. | 120 // RSSI value. |
| 108 int rssi_; | 121 int rssi_; |
| 109 | 122 |
| 110 // Whether the device is connectable. | 123 // Whether the device is connectable. |
| 111 bool connectable_; | 124 bool connectable_; |
| 112 | 125 |
| 113 // The peripheral's identifier, as returned by [CBPeripheral identifier]. | 126 // The peripheral's identifier, as returned by [CBPeripheral identifier]. |
| 114 std::string identifier_; | 127 std::string identifier_; |
| 115 | 128 |
| 116 // A local address for the device created by hashing the peripheral | 129 // A local address for the device created by hashing the peripheral |
| 117 // identifier. | 130 // identifier. |
| 118 std::string hash_address_; | 131 std::string hash_address_; |
| 119 | 132 |
| 120 // Stores the time of the most recent call to Update(). | 133 // Stores the time of the most recent call to Update(). |
| 121 base::scoped_nsobject<NSDate> last_update_time_; | 134 base::scoped_nsobject<NSDate> last_update_time_; |
| 122 | 135 |
| 123 // The services (identified by UUIDs) that this device provides. | 136 // The services (identified by UUIDs) that this device provides. |
| 124 std::set<BluetoothUUID> advertised_uuids_; | 137 std::set<BluetoothUUID> advertised_uuids_; |
| 125 | 138 |
| 139 // Lists of CreateGattConnection() and Disconnect() callbacks. |
| 140 std::vector<GattConnectionCallback> create_gatt_connection_success_callbacks_; |
| 141 std::vector<ConnectErrorCallback> create_gatt_connection_error_callbacks_; |
| 142 std::vector<base::Closure> disconnect_success_callbacks_; |
| 143 std::vector<ErrorCallback> disconnect_error_callbacks_; |
| 144 |
| 145 // Note: This should remain the last member so it'll be destroyed and |
| 146 // invalidate its weak pointers before any other members are destroyed. |
| 147 base::WeakPtrFactory<BluetoothLowEnergyDeviceMac> weak_ptr_factory_; |
| 148 |
| 126 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyDeviceMac); | 149 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyDeviceMac); |
| 127 }; | 150 }; |
| 128 | 151 |
| 129 } // namespace device | 152 } // namespace device |
| 130 | 153 |
| 131 #endif // DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DEVICE_MAC_H_ | 154 #endif // DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DEVICE_MAC_H_ |
| OLD | NEW |