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

Side by Side 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: 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_WEAVE_SERVER_CONNECTI ON_H_
6 #define COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_WEAVE_SERVER_CONNECTI ON_H_
7
8 #include <stddef.h>
9 #include <stdint.h>
10
11 #include <map>
12 #include <memory>
13 #include <queue>
14 #include <string>
15
16 #include "base/memory/weak_ptr.h"
17 #include "components/proximity_auth/ble/bluetooth_low_energy_weave_packet_genera tor.h"
18 #include "components/proximity_auth/ble/bluetooth_low_energy_weave_packet_receiv er.h"
19 #include "components/proximity_auth/ble/bluetooth_low_energy_weave_server.h"
20 #include "components/proximity_auth/connection.h"
21 #include "components/proximity_auth/remote_device.h"
22 #include "components/proximity_auth/wire_message.h"
23 #include "device/bluetooth/bluetooth_device.h"
24 #include "device/bluetooth/bluetooth_local_gatt_characteristic.h"
25
26 namespace proximity_auth {
27 namespace weave {
28 namespace {
29
30 typedef device::BluetoothDevice BluetoothDevice;
31 typedef device::BluetoothLocalGattCharacteristic
32 BluetoothLocalGattCharacteristic;
33
34 } // namespace
35
36 class BluetoothLowEnergyWeaveServer;
37
38 // Creates GATT connection on top of the BLE connection and act as a Server.
39 // uWeave communication follows the flow:
40 // Client | Server
41 // ---------------------------------|--------------------------------
42 // send connection request |
43 // | receive connection request
44 // | send connection response
45 // receive connection response |
46 // opt: send data | opt: send data
47 // receive data | receive data
48 // opt: close connection | opt: close connection
49 class BluetoothLowEnergyWeaveServerConnection : public Connection {
50 public:
51 class Factory {
52 public:
53 static std::unique_ptr<BluetoothLowEnergyWeaveServerConnection> NewInstance(
54 const BluetoothDevice* bluetooth_device,
55 base::WeakPtr<BluetoothLowEnergyWeaveServer> server,
56 base::WeakPtr<BluetoothLocalGattCharacteristic> rx_characteristic);
57
58 // Exposed for testing.
59 static void SetInstanceForTesting(Factory* factory);
60
61 protected:
62 // Exposed for testing.
63 virtual std::unique_ptr<BluetoothLowEnergyWeaveServerConnection>
64 BuildInstance(
65 const BluetoothDevice* bluetooth_device,
66 base::WeakPtr<BluetoothLowEnergyWeaveServer> server,
67 base::WeakPtr<BluetoothLocalGattCharacteristic> rx_characteristic);
68
69 private:
70 static Factory* factory_instance_;
71 };
72
73 // Constructs a Bluetooth low energy conceptual connection to
74 // |bluetooth_device|.
75 // The characteristics must be ready and registered onto a service on the
76 // bluetooth adapter.
77 // A subsequent call to Connect() must be made.
78 BluetoothLowEnergyWeaveServerConnection(
79 const BluetoothDevice* bluetooth_device,
80 base::WeakPtr<BluetoothLowEnergyWeaveServer> server,
81 base::WeakPtr<BluetoothLocalGattCharacteristic> rx_characteristic);
82
83 ~BluetoothLowEnergyWeaveServerConnection() override;
84
85 // proximity_auth::Connection:
86 void Connect() override;
87 void Disconnect() override;
88 std::string GetDeviceAddress() override;
89
90 // TODO(jingxuy): this function doesn't exist in connection interface since
91 // the connection interface is tailored to the client. Resolve this somehow.
92 bool ReceivePacket(Packet packet);
93
94 protected:
95 // proximity_auth::Connection:
96 void SendMessageImpl(std::unique_ptr<WireMessage> message) override;
97
98 private:
99 const RemoteDevice& remote_device_;
100
101 const BluetoothDevice* bluetooth_device_;
102
103 base::WeakPtr<BluetoothLowEnergyWeaveServer> server_;
104 base::WeakPtr<BluetoothLocalGattCharacteristic> rx_characteristic_;
105
106 // uWeave packet generator.
107 std::unique_ptr<BluetoothLowEnergyWeavePacketGenerator> packet_generator_;
108
109 // uWeave packet receiver.
110 std::unique_ptr<BluetoothLowEnergyWeavePacketReceiver> packet_receiver_;
111
112 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyWeaveServerConnection);
113 };
114
115 } // namespace weave
116
117 } // namespace proximity_auth
118
119 #endif // COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_WEAVE_SERVER_CONNE CTION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698