Index: components/proximity_auth/ble/bluetooth_low_energy_weave_client_connection.h |
diff --git a/components/proximity_auth/ble/bluetooth_low_energy_connection.h b/components/proximity_auth/ble/bluetooth_low_energy_weave_client_connection.h |
similarity index 72% |
copy from components/proximity_auth/ble/bluetooth_low_energy_connection.h |
copy to components/proximity_auth/ble/bluetooth_low_energy_weave_client_connection.h |
index dec8d419655c3ba270aa455089345cb644fa5be7..7fe3fd3e03a07bd6b6204e4ddedb6cec46e25ed7 100644 |
--- a/components/proximity_auth/ble/bluetooth_low_energy_connection.h |
+++ b/components/proximity_auth/ble/bluetooth_low_energy_weave_client_connection.h |
@@ -2,8 +2,8 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#ifndef COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_CONNECTION_H_ |
-#define COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_CONNECTION_H_ |
+#ifndef COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_WEAVE_CLIENT_CONNECTION_H_ |
+#define COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_WEAVE_CLIENT_CONNECTION_H_ |
#include <stddef.h> |
#include <stdint.h> |
@@ -17,6 +17,8 @@ |
#include "base/memory/weak_ptr.h" |
#include "base/time/time.h" |
#include "components/proximity_auth/ble/bluetooth_low_energy_characteristics_finder.h" |
+#include "components/proximity_auth/ble/bluetooth_low_energy_weave_packet_generator.h" |
+#include "components/proximity_auth/ble/bluetooth_low_energy_weave_packet_receiver.h" |
#include "components/proximity_auth/ble/fake_wire_message.h" |
#include "components/proximity_auth/ble/remote_attribute.h" |
#include "components/proximity_auth/connection.h" |
@@ -34,32 +36,20 @@ namespace proximity_auth { |
class BluetoothThrottler; |
-// Represents a connection with a remote device over Bluetooth low energy. The |
-// connection is a persistent bidirectional channel for sending and receiving |
-// wire messages. The remote device is the peripheral mode and the service |
-// contains two characteristics: one to send data and another to receive it. |
-// |
-// The connection flow is described below. |
-// |
-// Discover Reader and Writer Characteristics |
-// | |
-// | |
-// | |
-// Start Notify Session |
-// | |
-// | |
-// | |
-// Write kInviteToConnectSignal to Writer Characteristic |
-// | |
-// | |
-// | |
-// Read kInvitationResponseSignal from Reader Characteristic |
-// | |
-// | |
-// | |
-// Proximity Auth Connection Established |
-class BluetoothLowEnergyConnection : public Connection, |
- public device::BluetoothAdapter::Observer { |
+// Creates GATT connection on top of the BLE connection and act as a Client. |
+// uWeave communication follows the flow: |
+// Client | Server |
+// ---------------------------------|-------------------------------- |
+// send connection request | |
+// | receive connection request |
+// | send connection response |
+// receive connection response | |
+// opt: send data | opt: send data |
+// receive data | receive data |
+// opt: close connection | opt: close connection |
+class BluetoothLowEnergyWeaveClientConnection |
Kyle Horimoto
2016/06/27 18:06:03
This class will also require a Factory for when we
jingxuy
2016/06/30 00:27:21
Done.
|
+ : public Connection, |
+ public device::BluetoothAdapter::Observer { |
public: |
// Signals sent to the remote device to indicate connection related events. |
enum class ControlSignal : uint32_t { |
Kyle Horimoto
2016/06/27 18:06:02
This class is not needed anymore.
sacomoto
2016/06/29 14:26:58
+1
jingxuy
2016/06/30 00:27:21
Done.
|
@@ -69,9 +59,10 @@ class BluetoothLowEnergyConnection : public Connection, |
kDisconnectSignal = 3, |
}; |
- // The sub-state of a proximity_auth::BluetoothLowEnergyConnection class |
+ // The sub-state of a proximity_auth::BluetoothLowEnergyWeaveClientConnection |
+ // class |
sacomoto
2016/06/29 14:26:58
nit: kill the empty line.
jingxuy
2016/06/30 00:27:21
Done.
|
// extends the IN_PROGRESS state of proximity_auth::Connection::Status. |
- enum class SubStatus { |
+ enum SubStatus { |
DISCONNECTED, |
WAITING_GATT_CONNECTION, |
WAITING_CHARACTERISTICS, |
@@ -87,14 +78,14 @@ class BluetoothLowEnergyConnection : public Connection, |
// initaalized and ready. The GATT connection may alreaady be established and |
Kyle Horimoto
2016/06/27 18:06:02
s/initaalized/initialized/
jingxuy
2016/06/30 00:27:20
Done.
|
// pass through |gatt_connection|. A subsequent call to Connect() must be |
// made. |
- BluetoothLowEnergyConnection( |
+ BluetoothLowEnergyWeaveClientConnection( |
const RemoteDevice& remote_device, |
scoped_refptr<device::BluetoothAdapter> adapter, |
const device::BluetoothUUID remote_service_uuid, |
BluetoothThrottler* bluetooth_throttler, |
int max_number_of_write_attempts); |
- ~BluetoothLowEnergyConnection() override; |
+ ~BluetoothLowEnergyWeaveClientConnection() override; |
// proximity_auth::Connection: |
void Connect() override; |
@@ -157,7 +148,7 @@ class BluetoothLowEnergyConnection : public Connection, |
void OnCreateGattConnectionError( |
device::BluetoothDevice::ConnectErrorCode error_code); |
- // Callback called when |to_peripheral_char_| and |from_peripheral_char_| were |
+ // Callback called when |tx_characteristic_| and |rx_characteristic_| were |
// found. |
void OnCharacteristicsFound(const RemoteAttribute& service, |
const RemoteAttribute& to_peripheral_char, |
sacomoto
2016/06/29 14:26:58
s/to_peripheral_char/tx_chararacteristic/.
jingxuy
2016/06/30 00:27:21
Done.
|
@@ -168,17 +159,17 @@ class BluetoothLowEnergyConnection : public Connection, |
const RemoteAttribute& to_peripheral_char, |
const RemoteAttribute& from_peripheral_char); |
sacomoto
2016/06/29 14:26:58
The same here.
jingxuy
2016/06/30 00:27:20
Done.
|
- // Starts a notify session for |from_peripheral_char_| when ready |
+ // Starts a notify session for |rx_characteristic_| when ready |
// (SubStatus::CHARACTERISTICS_FOUND). |
void StartNotifySession(); |
// Called when a notification session is successfully started for |
- // |from_peripheral_char_| characteristic. |
+ // |rx_characteristic_| characteristic. |
void OnNotifySessionStarted( |
std::unique_ptr<device::BluetoothGattNotifySession> notify_session); |
// Called when there is an error starting a notification session for |
- // |from_peripheral_char_| characteristic. |
+ // |rx_characteristic_| characteristic. |
void OnNotifySessionError(device::BluetoothGattService::GattErrorCode); |
// Stops |notify_session_|. |
@@ -202,7 +193,7 @@ class BluetoothLowEnergyConnection : public Connection, |
// (OnWriteRemoteCharacteristicError()), it remains on the queue and will be |
// retried. |request| will remain on the queue until it succeeds or it |
// triggers a Disconnect() call (after |max_number_of_tries_|). |
- void WriteRemoteCharacteristic(WriteRequest request); |
+ void WriteRemoteCharacteristic(const WriteRequest& request); |
// Processes the next request in |write_requests_queue_|. |
void ProcessNextWriteRequest(); |
@@ -213,17 +204,11 @@ class BluetoothLowEnergyConnection : public Connection, |
void OnRemoteCharacteristicWritten(bool run_did_send_message_callback); |
// Called when there is an error writing to the remote characteristic |
- // |to_peripheral_char_|. |
+ // |tx_characteristic_|. |
void OnWriteRemoteCharacteristicError( |
bool run_did_send_message_callback, |
device::BluetoothRemoteGattService::GattErrorCode error); |
- // Builds the value to be written on |to_peripheral_char_|. The value |
- // corresponds to |signal| concatenated with |payload|. |
- WriteRequest BuildWriteRequest(const std::vector<uint8_t>& signal, |
- const std::vector<uint8_t>& bytes, |
- bool is_last_message_for_wire_message); |
- |
// Prints the time elapsed since |Connect()| was called. |
void PrintTimeElapsed(); |
@@ -239,23 +224,23 @@ class BluetoothLowEnergyConnection : public Connection, |
device::BluetoothRemoteGattCharacteristic* GetGattCharacteristic( |
const std::string& identifier); |
- // Convert the first 4 bytes from a byte vector to a uint32_t. |
- uint32_t ToUint32(const std::vector<uint8_t>& bytes); |
- |
- // Convert an uint32_t to a byte vector. |
- const std::vector<uint8_t> ToByteVector(uint32_t value); |
- |
// The Bluetooth adapter over which the Bluetooth connection will be made. |
scoped_refptr<device::BluetoothAdapter> adapter_; |
// Remote service the |gatt_connection_| was established with. |
RemoteAttribute remote_service_; |
+ // uWeave packet generator. |
+ std::unique_ptr<BluetoothLowEnergyWeavePacketGenerator> packet_generator_; |
+ |
+ // uWeave packet receiver. |
+ std::unique_ptr<BluetoothLowEnergyWeavePacketReceiver> packet_receiver_; |
+ |
// Characteristic used to send data to the remote device. |
- RemoteAttribute to_peripheral_char_; |
+ RemoteAttribute tx_characteristic_; |
// Characteristic used to receive data from the remote device. |
- RemoteAttribute from_peripheral_char_; |
+ RemoteAttribute rx_characteristic_; |
// Throttles repeated connection attempts to the same device. This is a |
// workaround for crbug.com/508919. Not owned, must outlive this instance. |
@@ -276,13 +261,6 @@ class BluetoothLowEnergyConnection : public Connection, |
// Internal connection status |
SubStatus sub_status_; |
- // Indicates a receiving operation is in progress. This is set after a |
- // ControlSignal::kSendSignal was received from the remote device. |
- bool receiving_bytes_; |
- |
- // Total number of bytes expected for the current receive operation. |
- std::size_t expected_number_of_incoming_bytes_; |
- |
// Bytes already received for the current receive operation. |
std::string incoming_bytes_buffer_; |
@@ -296,21 +274,15 @@ class BluetoothLowEnergyConnection : public Connection, |
// Maximum number of tries to send any write request. |
int max_number_of_write_attempts_; |
- // Maximum number of bytes that fit in a single chunk to be written in |
- // |to_peripheral_char_|. Ideally, this should be the maximum value the |
- // peripheral supports and it should be agreed when the GATT connection is |
- // created. Currently, there is no API to find this value. The implementation |
- // uses a hard-coded constant. |
- int max_chunk_size_; |
- |
// Stores when the instace was created. |
base::TimeTicks start_time_; |
- base::WeakPtrFactory<BluetoothLowEnergyConnection> weak_ptr_factory_; |
+ base::WeakPtrFactory<BluetoothLowEnergyWeaveClientConnection> |
+ weak_ptr_factory_; |
- DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyConnection); |
+ DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyWeaveClientConnection); |
}; |
} // namespace proximity_auth |
-#endif // COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_CONNECTION_H_ |
+#endif // COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_WEAVE_CLIENT_CONNECTION_H_ |