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

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: 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 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/connection.h"
20 #include "components/proximity_auth/remote_device.h"
21 #include "components/proximity_auth/wire_message.h"
22 #include "device/bluetooth/bluetooth_local_gatt_characteristic.h"
23
24 namespace proximity_auth {
25 namespace weave {
26 namespace {
27
28 using BluetoothDevice = device::BluetoothDevice;
29 using BluetoothLocalGattCharacteristic =
30 device::BluetoothLocalGattCharacteristic;
31
32 } // namespace
33
34 // Creates GATT connection on top of the BLE connection and act as a Server.
35 // uWeave communication follows the flow:
36 // Client | Server
37 // ---------------------------------|--------------------------------
38 // send connection request |
39 // | receive connection request
40 // | send connection response
41 // receive connection response |
42 // opt: send data | opt: send data
43 // receive data | receive data
44 // opt: close connection | opt: close connection
45 class BluetoothLowEnergyWeaveServerConnection : public Connection {
46 public:
47 class Factory {
48 public:
49 static std::unique_ptr<BluetoothLowEnergyWeaveServerConnection> NewInstance(
50 const RemoteDevice& remote_device,
51 const BluetoothDevice* bluetooth_device,
52 base::WeakPtr<BluetoothLocalGattCharacteristic> rx_characteristic);
53
54 // Exposed for testing.
55 static void SetInstanceForTesting(Factory* factory);
56
57 protected:
58 // Exposed for testing.
59 virtual std::unique_ptr<BluetoothLowEnergyWeaveServerConnection>
60 BuildInstance(
61 const RemoteDevice& remote_device,
62 const BluetoothDevice* bluetooth_device,
63 base::WeakPtr<BluetoothLocalGattCharacteristic> rx_characteristic);
64
65 private:
66 static Factory* factory_instance_;
67 };
68
69 // Constructs a Bluetooth low energy conceptual connection to
70 // |remote_device|.
71 // The RX characteristic must be ready and registered onto a service on the
72 // bluetooth adapter.
73 // A subsequent call to Connect() must be made.
74 BluetoothLowEnergyWeaveServerConnection(
75 const RemoteDevice& remote_device,
76 const BluetoothDevice* bluetooth_device,
77 base::WeakPtr<BluetoothLocalGattCharacteristic> rx_characteristic);
78
79 ~BluetoothLowEnergyWeaveServerConnection() override;
80
81 // proximity_auth::Connection:
82 void Connect() override;
83 void Disconnect() override;
84 std::string GetDeviceAddress() override;
85
86 // TODO(jingxuy): this function doesn't exist in connection interface since
87 // the connection interface is tailored to the client. Resolve this somehow.
88 // Receive a packet directed for this connection.
89 void ReceivePacket(Packet packet);
90
91 protected:
92 // Exposed for testing.
93 // proximity_auth::Connection:
94 void SendMessageImpl(std::unique_ptr<WireMessage> message) override;
95
96 private:
97 void OnReceiverError();
98 void OnConnected();
99
100 std::string GetReasonForClose();
101
102 const RemoteDevice& remote_device_;
103
104 const BluetoothDevice* bluetooth_device_;
105
106 base::WeakPtr<BluetoothLocalGattCharacteristic> rx_characteristic_;
107
108 // uWeave packet generator.
109 std::unique_ptr<BluetoothLowEnergyWeavePacketGenerator> packet_generator_;
110
111 // uWeave packet receiver.
112 std::unique_ptr<BluetoothLowEnergyWeavePacketReceiver> packet_receiver_;
113
114 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyWeaveServerConnection);
115 };
116
117 } // namespace weave
118
119 } // namespace proximity_auth
120
121 #endif // COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_WEAVE_SERVER_CONNE CTION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698