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

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

Issue 2183523006: Chrome OS uWeave Characteristics Server (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@migration
Patch Set: added channel Created 4 years, 4 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_server_connection.h
diff --git a/components/proximity_auth/ble/bluetooth_low_energy_weave_server_connection.h b/components/proximity_auth/ble/bluetooth_low_energy_weave_server_connection.h
new file mode 100644
index 0000000000000000000000000000000000000000..6f3814dcf2e0ddf1e5813c88d52483755e900865
--- /dev/null
+++ b/components/proximity_auth/ble/bluetooth_low_energy_weave_server_connection.h
@@ -0,0 +1,121 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// 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_WEAVE_SERVER_CONNECTION_H_
+#define COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_WEAVE_SERVER_CONNECTION_H_
+
+#include <stddef.h>
+#include <stdint.h>
+
+#include <map>
+#include <memory>
+#include <queue>
+#include <string>
+
+#include "base/memory/weak_ptr.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/connection.h"
+#include "components/proximity_auth/remote_device.h"
+#include "components/proximity_auth/wire_message.h"
+#include "device/bluetooth/bluetooth_local_gatt_characteristic.h"
+
+namespace proximity_auth {
+namespace weave {
+namespace {
+
+using BluetoothDevice = device::BluetoothDevice;
+using BluetoothLocalGattCharacteristic =
+ device::BluetoothLocalGattCharacteristic;
+
+} // namespace
+
+// Creates GATT connection on top of the BLE connection and act as a Server.
+// 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 BluetoothLowEnergyWeaveServerConnection : public Connection {
+ public:
+ class Factory {
+ public:
+ static std::unique_ptr<BluetoothLowEnergyWeaveServerConnection> NewInstance(
+ const RemoteDevice& remote_device,
+ const BluetoothDevice* bluetooth_device,
+ base::WeakPtr<BluetoothLocalGattCharacteristic> rx_characteristic);
+
+ // Exposed for testing.
+ static void SetInstanceForTesting(Factory* factory);
+
+ protected:
+ // Exposed for testing.
+ virtual std::unique_ptr<BluetoothLowEnergyWeaveServerConnection>
+ BuildInstance(
+ const RemoteDevice& remote_device,
+ const BluetoothDevice* bluetooth_device,
+ base::WeakPtr<BluetoothLocalGattCharacteristic> rx_characteristic);
+
+ private:
+ static Factory* factory_instance_;
+ };
+
+ // Constructs a Bluetooth low energy conceptual connection to
+ // |remote_device|.
+ // The RX characteristic must be ready and registered onto a service on the
+ // bluetooth adapter.
+ // A subsequent call to Connect() must be made.
+ BluetoothLowEnergyWeaveServerConnection(
+ const RemoteDevice& remote_device,
+ const BluetoothDevice* bluetooth_device,
+ base::WeakPtr<BluetoothLocalGattCharacteristic> rx_characteristic);
+
+ ~BluetoothLowEnergyWeaveServerConnection() override;
+
+ // proximity_auth::Connection:
+ void Connect() override;
+ void Disconnect() override;
+ std::string GetDeviceAddress() override;
+
+ // TODO(jingxuy): this function doesn't exist in connection interface since
+ // the connection interface is tailored to the client. Resolve this somehow.
+ // Receive a packet directed for this connection.
+ void ReceivePacket(Packet packet);
+
+ protected:
+ // Exposed for testing.
+ // proximity_auth::Connection:
+ void SendMessageImpl(std::unique_ptr<WireMessage> message) override;
+
+ private:
+ void OnReceiverError();
+ void OnConnected();
+
+ std::string GetReasonForClose();
+
+ const RemoteDevice& remote_device_;
+
+ const BluetoothDevice* bluetooth_device_;
+
+ base::WeakPtr<BluetoothLocalGattCharacteristic> rx_characteristic_;
+
+ // uWeave packet generator.
+ std::unique_ptr<BluetoothLowEnergyWeavePacketGenerator> packet_generator_;
+
+ // uWeave packet receiver.
+ std::unique_ptr<BluetoothLowEnergyWeavePacketReceiver> packet_receiver_;
+
+ DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyWeaveServerConnection);
+};
+
+} // namespace weave
+
+} // namespace proximity_auth
+
+#endif // COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_WEAVE_SERVER_CONNECTION_H_

Powered by Google App Engine
This is Rietveld 408576698