| 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_BLUETOOTH_LOW_ENERGY_CONNECTION_H | 5 #ifndef COMPONENTS_PROXIMITY_AUTH_BLUETOOTH_LOW_ENERGY_CONNECTION_H |
| 6 #define COMPONENTS_PROXIMITY_AUTH_BLUETOOTH_LOW_ENERGY_CONNECTION_H | 6 #define COMPONENTS_PROXIMITY_AUTH_BLUETOOTH_LOW_ENERGY_CONNECTION_H |
| 7 | 7 |
| 8 #include <queue> | 8 #include <queue> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 public device::BluetoothAdapter::Observer { | 52 public device::BluetoothAdapter::Observer { |
| 53 public: | 53 public: |
| 54 // Signals sent to the remote device to indicate connection related events. | 54 // Signals sent to the remote device to indicate connection related events. |
| 55 enum class ControlSignal : uint32 { | 55 enum class ControlSignal : uint32 { |
| 56 kInviteToConnectSignal = 0, | 56 kInviteToConnectSignal = 0, |
| 57 kInvitationResponseSignal = 1, | 57 kInvitationResponseSignal = 1, |
| 58 kSendSignal = 2, | 58 kSendSignal = 2, |
| 59 kDisconnectSignal = 3, | 59 kDisconnectSignal = 3, |
| 60 }; | 60 }; |
| 61 | 61 |
| 62 // The sub-state of a proximity_auth::BluetoothLowEnergyConnection class |
| 63 // extends the IN_PROGRESS state of proximity_auth::Connection::Status. |
| 64 enum class SubStatus { |
| 65 DISCONNECTED, |
| 66 WAITING_GATT_CONNECTION, |
| 67 GATT_CONNECTION_ESTABLISHED, |
| 68 WAITING_CHARACTERISTICS, |
| 69 CHARACTERISTICS_FOUND, |
| 70 WAITING_NOTIFY_SESSION, |
| 71 NOTIFY_SESSION_READY, |
| 72 WAITING_RESPONSE_SIGNAL, |
| 73 CONNECTED, |
| 74 }; |
| 75 |
| 62 // Constructs a Bluetooth low energy connection to the service with | 76 // Constructs a Bluetooth low energy connection to the service with |
| 63 // |remote_service_| on the |remote_device|. The |adapter| must be already | 77 // |remote_service_| on the |remote_device|. The |adapter| must be already |
| 64 // initaalized and ready. The GATT connection may alreaady be established and | 78 // initaalized and ready. The GATT connection may alreaady be established and |
| 65 // pass through |gatt_connection|. If |gatt_connection| is NULL, a subsequent | 79 // pass through |gatt_connection|. A subsequent call to Connect() must be |
| 66 // call to Connect() must be made. | 80 // made. |
| 67 BluetoothLowEnergyConnection( | 81 BluetoothLowEnergyConnection( |
| 68 const RemoteDevice& remote_device, | 82 const RemoteDevice& remote_device, |
| 69 scoped_refptr<device::BluetoothAdapter> adapter, | 83 scoped_refptr<device::BluetoothAdapter> adapter, |
| 70 const device::BluetoothUUID remote_service_uuid, | 84 const device::BluetoothUUID remote_service_uuid, |
| 71 const device::BluetoothUUID to_peripheral_char_uuid, | 85 const device::BluetoothUUID to_peripheral_char_uuid, |
| 72 const device::BluetoothUUID from_peripheral_char_uuid, | 86 const device::BluetoothUUID from_peripheral_char_uuid, |
| 73 scoped_ptr<device::BluetoothGattConnection> gatt_connection, | 87 scoped_ptr<device::BluetoothGattConnection> gatt_connection, |
| 74 int max_number_of_write_attempts); | 88 int max_number_of_write_attempts); |
| 75 | 89 |
| 76 ~BluetoothLowEnergyConnection() override; | 90 ~BluetoothLowEnergyConnection() override; |
| 77 | 91 |
| 78 // proximity_auth::Connection | 92 // proximity_auth::Connection |
| 79 void Connect() override; | 93 void Connect() override; |
| 80 void Disconnect() override; | 94 void Disconnect() override; |
| 81 | 95 |
| 82 protected: | 96 protected: |
| 83 // The sub-state of a proximity_auth::BluetoothLowEnergyConnection class | 97 // Exposed for testing. |
| 84 // extends the IN_PROGRESS state of proximity_auth::Connection::Status. | |
| 85 enum class SubStatus { | |
| 86 DISCONNECTED, | |
| 87 WAITING_GATT_CONNECTION, | |
| 88 GATT_CONNECTION_ESTABLISHED, | |
| 89 WAITING_CHARACTERISTICS, | |
| 90 CHARACTERISTICS_FOUND, | |
| 91 WAITING_NOTIFY_SESSION, | |
| 92 NOTIFY_SESSION_READY, | |
| 93 WAITING_RESPONSE_SIGNAL, | |
| 94 CONNECTED, | |
| 95 }; | |
| 96 | |
| 97 void SetSubStatus(SubStatus status); | 98 void SetSubStatus(SubStatus status); |
| 98 SubStatus sub_status() { return sub_status_; } | 99 SubStatus sub_status() { return sub_status_; } |
| 99 | 100 |
| 101 // Virtual for testing. |
| 102 virtual BluetoothLowEnergyCharacteristicsFinder* CreateCharacteristicsFinder( |
| 103 const BluetoothLowEnergyCharacteristicsFinder::SuccessCallback& |
| 104 success_callback, |
| 105 const BluetoothLowEnergyCharacteristicsFinder::ErrorCallback& |
| 106 error_callback); |
| 107 |
| 100 // proximity_auth::Connection | 108 // proximity_auth::Connection |
| 101 void SendMessageImpl(scoped_ptr<WireMessage> message) override; | 109 void SendMessageImpl(scoped_ptr<WireMessage> message) override; |
| 102 scoped_ptr<WireMessage> DeserializeWireMessage( | 110 scoped_ptr<WireMessage> DeserializeWireMessage( |
| 103 bool* is_incomplete_message) override; | 111 bool* is_incomplete_message) override; |
| 104 | 112 |
| 105 // device::BluetoothAdapter::Observer | 113 // device::BluetoothAdapter::Observer |
| 106 void DeviceRemoved(device::BluetoothAdapter* adapter, | 114 void DeviceRemoved(device::BluetoothAdapter* adapter, |
| 107 device::BluetoothDevice* device) override; | 115 device::BluetoothDevice* device) override; |
| 108 void GattCharacteristicValueChanged( | 116 void GattCharacteristicValueChanged( |
| 109 device::BluetoothAdapter* adapter, | 117 device::BluetoothAdapter* adapter, |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 base::TimeTicks start_time_; | 275 base::TimeTicks start_time_; |
| 268 | 276 |
| 269 base::WeakPtrFactory<BluetoothLowEnergyConnection> weak_ptr_factory_; | 277 base::WeakPtrFactory<BluetoothLowEnergyConnection> weak_ptr_factory_; |
| 270 | 278 |
| 271 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyConnection); | 279 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyConnection); |
| 272 }; | 280 }; |
| 273 | 281 |
| 274 } // namespace proximity_auth | 282 } // namespace proximity_auth |
| 275 | 283 |
| 276 #endif // COMPONENTS_PROXIMITY_AUTH_BLUETOOTH_LOW_ENERGY_CONNECTION_H | 284 #endif // COMPONENTS_PROXIMITY_AUTH_BLUETOOTH_LOW_ENERGY_CONNECTION_H |
| OLD | NEW |