| 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 COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_CHARACTERISTICS_FINDE
R_H | 5 #ifndef COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_CHARACTERISTICS_FINDE
R_H_ |
| 6 #define COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_CHARACTERISTICS_FINDE
R_H | 6 #define COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_CHARACTERISTICS_FINDE
R_H_ |
| 7 | 7 |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "components/proximity_auth/ble/remote_attribute.h" | 11 #include "components/proximity_auth/ble/remote_attribute.h" |
| 12 #include "device/bluetooth/bluetooth_adapter.h" | 12 #include "device/bluetooth/bluetooth_adapter.h" |
| 13 #include "device/bluetooth/bluetooth_device.h" | 13 #include "device/bluetooth/bluetooth_device.h" |
| 14 #include "device/bluetooth/bluetooth_gatt_characteristic.h" | 14 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h" |
| 15 #include "device/bluetooth/bluetooth_remote_gatt_service.h" |
| 15 #include "device/bluetooth/bluetooth_uuid.h" | 16 #include "device/bluetooth/bluetooth_uuid.h" |
| 16 | 17 |
| 17 namespace proximity_auth { | 18 namespace proximity_auth { |
| 18 | 19 |
| 19 // Looks for given characteristics in a remote device, for which a GATT | 20 // Looks for given characteristics in a remote device, for which a GATT |
| 20 // connection was already established. In the current BLE connection protocol | 21 // connection was already established. In the current BLE connection protocol |
| 21 // (device::BluetoothDevice::CreateGattConnection), remote characteristic | 22 // (device::BluetoothDevice::CreateGattConnection), remote characteristic |
| 22 // discovery starts immediatelly after a GATT connection was established. So, | 23 // discovery starts immediatelly after a GATT connection was established. So, |
| 23 // this class simply adds an observer for a characteristic discovery event and | 24 // this class simply adds an observer for a characteristic discovery event and |
| 24 // call |success_callback_| once all necessary characteristics were discovered. | 25 // call |success_callback_| once all necessary characteristics were discovered. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 const RemoteAttribute& from_peripheral_char, | 57 const RemoteAttribute& from_peripheral_char, |
| 57 const SuccessCallback& success_callback, | 58 const SuccessCallback& success_callback, |
| 58 const ErrorCallback& error_callback); | 59 const ErrorCallback& error_callback); |
| 59 | 60 |
| 60 ~BluetoothLowEnergyCharacteristicsFinder() override; | 61 ~BluetoothLowEnergyCharacteristicsFinder() override; |
| 61 | 62 |
| 62 protected: | 63 protected: |
| 63 // device::BluetoothAdapter::Observer: | 64 // device::BluetoothAdapter::Observer: |
| 64 void GattDiscoveryCompleteForService( | 65 void GattDiscoveryCompleteForService( |
| 65 device::BluetoothAdapter* adapter, | 66 device::BluetoothAdapter* adapter, |
| 66 device::BluetoothGattService* service) override; | 67 device::BluetoothRemoteGattService* service) override; |
| 67 void GattCharacteristicAdded( | 68 void GattCharacteristicAdded( |
| 68 device::BluetoothAdapter* adapter, | 69 device::BluetoothAdapter* adapter, |
| 69 device::BluetoothGattCharacteristic* characteristic) override; | 70 device::BluetoothRemoteGattCharacteristic* characteristic) override; |
| 70 | 71 |
| 71 // For testing. Used to mock this class. | 72 // For testing. Used to mock this class. |
| 72 BluetoothLowEnergyCharacteristicsFinder(); | 73 BluetoothLowEnergyCharacteristicsFinder(); |
| 73 | 74 |
| 74 private: | 75 private: |
| 75 // Handles the discovery of a new characteristic. | 76 // Handles the discovery of a new characteristic. |
| 76 void HandleCharacteristicUpdate( | 77 void HandleCharacteristicUpdate( |
| 77 device::BluetoothGattCharacteristic* characteristic); | 78 device::BluetoothRemoteGattCharacteristic* characteristic); |
| 78 | 79 |
| 79 // Scans the remote chracteristics of the service with |uuid| in |device| | 80 // Scans the remote chracteristics of the service with |uuid| in |device| |
| 80 // calling HandleCharacteristicUpdate() for each of them. | 81 // calling HandleCharacteristicUpdate() for each of them. |
| 81 void ScanRemoteCharacteristics(device::BluetoothDevice* device, | 82 void ScanRemoteCharacteristics(device::BluetoothDevice* device, |
| 82 const device::BluetoothUUID& uuid); | 83 const device::BluetoothUUID& uuid); |
| 83 | 84 |
| 84 // Updates the value of |to_peripheral_char_| and | 85 // Updates the value of |to_peripheral_char_| and |
| 85 // |from_peripheral_char_| | 86 // |from_peripheral_char_| |
| 86 // when |characteristic| was found. | 87 // when |characteristic| was found. |
| 87 void UpdateCharacteristicsStatus( | 88 void UpdateCharacteristicsStatus( |
| 88 device::BluetoothGattCharacteristic* characteristic); | 89 device::BluetoothRemoteGattCharacteristic* characteristic); |
| 89 | 90 |
| 90 // Resets |success_callback_| and |success_callback_|. This should be called | 91 // Resets |success_callback_| and |success_callback_|. This should be called |
| 91 // whenever a callback is called to avoid multiple callbacks calls. | 92 // whenever a callback is called to avoid multiple callbacks calls. |
| 92 void ResetCallbacks(); | 93 void ResetCallbacks(); |
| 93 | 94 |
| 94 // The Bluetooth adapter where the connection was established. | 95 // The Bluetooth adapter where the connection was established. |
| 95 scoped_refptr<device::BluetoothAdapter> adapter_; | 96 scoped_refptr<device::BluetoothAdapter> adapter_; |
| 96 | 97 |
| 97 // Remote service the |connection_| was established with. | 98 // Remote service the |connection_| was established with. |
| 98 RemoteAttribute remote_service_; | 99 RemoteAttribute remote_service_; |
| 99 | 100 |
| 100 // Characteristic used to receive data from the remote device. | 101 // Characteristic used to receive data from the remote device. |
| 101 RemoteAttribute to_peripheral_char_; | 102 RemoteAttribute to_peripheral_char_; |
| 102 | 103 |
| 103 // Characteristic used to receive data from the remote device. | 104 // Characteristic used to receive data from the remote device. |
| 104 RemoteAttribute from_peripheral_char_; | 105 RemoteAttribute from_peripheral_char_; |
| 105 | 106 |
| 106 // Called when all characteristics were found. | 107 // Called when all characteristics were found. |
| 107 SuccessCallback success_callback_; | 108 SuccessCallback success_callback_; |
| 108 | 109 |
| 109 // Called when there is an error. | 110 // Called when there is an error. |
| 110 ErrorCallback error_callback_; | 111 ErrorCallback error_callback_; |
| 111 | 112 |
| 112 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyCharacteristicsFinder); | 113 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyCharacteristicsFinder); |
| 113 }; | 114 }; |
| 114 | 115 |
| 115 } // namespace proximity_auth | 116 } // namespace proximity_auth |
| 116 | 117 |
| 117 #endif // COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_CHARACTERISTICS_FINDER_H | 118 #endif // COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_CHARACTERISTICS_FINDER_H_ |
| OLD | NEW |