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_CRYPTAUTH_BLE_BLUETOOTH_LOW_ENERGY_CHARACTERISTICS_FINDER_H_ |
6 #define COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_CHARACTERISTICS_FINDE
R_H_ | 6 #define COMPONENTS_CRYPTAUTH_BLE_BLUETOOTH_LOW_ENERGY_CHARACTERISTICS_FINDER_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/cryptauth/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_remote_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_remote_gatt_service.h" |
16 #include "device/bluetooth/bluetooth_uuid.h" | 16 #include "device/bluetooth/bluetooth_uuid.h" |
17 | 17 |
18 namespace proximity_auth { | 18 namespace cryptauth { |
19 | 19 |
20 // 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 |
21 // connection was already established. In the current BLE connection protocol | 21 // connection was already established. In the current BLE connection protocol |
22 // (device::BluetoothDevice::CreateGattConnection), remote characteristic | 22 // (device::BluetoothDevice::CreateGattConnection), remote characteristic |
23 // discovery starts immediatelly after a GATT connection was established. So, | 23 // discovery starts immediatelly after a GATT connection was established. So, |
24 // 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 |
25 // call |success_callback_| once all necessary characteristics were discovered. | 25 // call |success_callback_| once all necessary characteristics were discovered. |
26 class BluetoothLowEnergyCharacteristicsFinder | 26 class BluetoothLowEnergyCharacteristicsFinder |
27 : public device::BluetoothAdapter::Observer { | 27 : public device::BluetoothAdapter::Observer { |
28 public: | 28 public: |
29 // This callbacks takes as arguments (in this order): |remote_service_|, | 29 // This callbacks takes as arguments (in this order): |remote_service_|, |
30 // |to_peripheral_char_| and |from_peripheral_char_|. Note that, since this is | 30 // |to_peripheral_char_| and |from_peripheral_char_|. Note that, since this is |
31 // called after the characteristics were discovered, their id field (e.g. | 31 // called after the characteristics were discovered, their id field (e.g. |
32 // to_peripheral_char_.id) will be non-blank. | 32 // to_peripheral_char_.id) will be non-blank. |
33 typedef base::Callback<void(const RemoteAttribute&, | 33 typedef base::Callback<void(const RemoteAttribute&, |
34 const RemoteAttribute&, | 34 const RemoteAttribute&, |
35 const RemoteAttribute&)> SuccessCallback; | 35 const RemoteAttribute&)> |
| 36 SuccessCallback; |
36 | 37 |
37 // This callback takes as arguments (in this order): |to_peripheral_char_| and | 38 // This callback takes as arguments (in this order): |to_peripheral_char_| and |
38 // |from_peripheral_char_|. A blank id field in the characteristics indicate | 39 // |from_peripheral_char_|. A blank id field in the characteristics indicate |
39 // that the characteristics was not found in the remote service. | 40 // that the characteristics was not found in the remote service. |
40 // TODO(sacomoto): Remove RemoteAttributes and add an error message instead. | 41 // TODO(sacomoto): Remove RemoteAttributes and add an error message instead. |
41 // The caller of this object should not care if only a subset of the | 42 // The caller of this object should not care if only a subset of the |
42 // characteristics was found. See crbug.com/495511. | 43 // characteristics was found. See crbug.com/495511. |
43 typedef base::Callback<void(const RemoteAttribute&, const RemoteAttribute&)> | 44 typedef base::Callback<void(const RemoteAttribute&, const RemoteAttribute&)> |
44 ErrorCallback; | 45 ErrorCallback; |
45 | 46 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 | 107 |
107 // Called when all characteristics were found. | 108 // Called when all characteristics were found. |
108 SuccessCallback success_callback_; | 109 SuccessCallback success_callback_; |
109 | 110 |
110 // Called when there is an error. | 111 // Called when there is an error. |
111 ErrorCallback error_callback_; | 112 ErrorCallback error_callback_; |
112 | 113 |
113 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyCharacteristicsFinder); | 114 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyCharacteristicsFinder); |
114 }; | 115 }; |
115 | 116 |
116 } // namespace proximity_auth | 117 } // namespace cryptauth |
117 | 118 |
118 #endif // COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_CHARACTERISTICS_FINDER_H_ | 119 #endif // COMPONENTS_CRYPTAUTH_BLE_BLUETOOTH_CHARACTERISTICS_FINDER_H_ |
OLD | NEW |