Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(571)

Unified Diff: components/proximity_auth/ble/bluetooth_low_energy_weave_connection.h

Issue 2075313002: Substituting legacy protocol with uWeave protocol (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tested and working version of the weave connection Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/proximity_auth/ble/bluetooth_low_energy_weave_connection.h
diff --git a/components/proximity_auth/ble/bluetooth_low_energy_connection.h b/components/proximity_auth/ble/bluetooth_low_energy_weave_connection.h
similarity index 74%
copy from components/proximity_auth/ble/bluetooth_low_energy_connection.h
copy to components/proximity_auth/ble/bluetooth_low_energy_weave_connection.h
index dec8d419655c3ba270aa455089345cb644fa5be7..b3af3ae6c0c2e1ec16535829c00dec1abc3e5f65 100644
--- a/components/proximity_auth/ble/bluetooth_low_energy_connection.h
+++ b/components/proximity_auth/ble/bluetooth_low_energy_weave_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_CONNECTION_H_
+#define COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_WEAVE_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,9 @@ 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 {
+class BluetoothLowEnergyWeaveConnection
Kyle Horimoto 2016/06/24 00:14:09 Please add an in-depth description to this class.
jingxuy 2016/06/25 00:23:27 Done.
+ : public Connection,
+ public device::BluetoothAdapter::Observer {
public:
// Signals sent to the remote device to indicate connection related events.
enum class ControlSignal : uint32_t {
@@ -69,9 +48,9 @@ class BluetoothLowEnergyConnection : public Connection,
kDisconnectSignal = 3,
};
- // The sub-state of a proximity_auth::BluetoothLowEnergyConnection class
+ // The sub-state of a proximity_auth::BluetoothLowEnergyWeaveConnection class
// extends the IN_PROGRESS state of proximity_auth::Connection::Status.
- enum class SubStatus {
+ enum SubStatus {
DISCONNECTED,
WAITING_GATT_CONNECTION,
WAITING_CHARACTERISTICS,
@@ -87,14 +66,14 @@ class BluetoothLowEnergyConnection : public Connection,
// initaalized and ready. The GATT connection may alreaady be established and
// pass through |gatt_connection|. A subsequent call to Connect() must be
// made.
- BluetoothLowEnergyConnection(
+ BluetoothLowEnergyWeaveConnection(
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;
+ ~BluetoothLowEnergyWeaveConnection() override;
// proximity_auth::Connection:
void Connect() override;
@@ -157,7 +136,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,
@@ -168,17 +147,17 @@ class BluetoothLowEnergyConnection : public Connection,
const RemoteAttribute& to_peripheral_char,
const RemoteAttribute& from_peripheral_char);
- // 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 +181,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 +192,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();
@@ -251,11 +224,17 @@ class BluetoothLowEnergyConnection : public Connection,
// 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 +255,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 +268,14 @@ 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<BluetoothLowEnergyWeaveConnection> weak_ptr_factory_;
- DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyConnection);
+ DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyWeaveConnection);
};
} // namespace proximity_auth
-#endif // COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_CONNECTION_H_
+#endif // COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_WEAVE_CONNECTION_H_
« no previous file with comments | « components/proximity_auth/ble/BUILD.gn ('k') | components/proximity_auth/ble/bluetooth_low_energy_weave_connection.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698