OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 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_BLUETOOTH_LOW_ENERGY_CONNECTION_H | |
6 #define COMPONENTS_PROXIMITY_AUTH_BLUETOOTH_LOW_ENERGY_CONNECTION_H | |
7 | |
8 #include "base/macros.h" | |
9 #include "base/memory/ref_counted.h" | |
10 #include "base/memory/scoped_ptr.h" | |
11 #include "base/memory/weak_ptr.h" | |
12 #include "components/proximity_auth/ble/fake_wire_message.h" | |
13 #include "components/proximity_auth/connection.h" | |
14 #include "device/bluetooth/bluetooth_adapter.h" | |
15 #include "device/bluetooth/bluetooth_device.h" | |
16 #include "device/bluetooth/bluetooth_gatt_characteristic.h" | |
17 #include "device/bluetooth/bluetooth_gatt_notify_session.h" | |
18 #include "device/bluetooth/bluetooth_uuid.h" | |
19 | |
20 namespace proximity_auth { | |
21 | |
22 class BluetoothLowEnergyConnection : public Connection, | |
msarda
2015/05/05 11:56:14
Comment this class. It should ideally describe the
sacomoto
2015/05/06 13:47:58
Done.
| |
23 public device::BluetoothAdapter::Observer { | |
24 public: | |
25 BluetoothLowEnergyConnection( | |
26 const RemoteDevice& remote_device, | |
27 scoped_refptr<device::BluetoothAdapter> adapter, | |
28 device::BluetoothUUID remote_service_uuid, | |
29 scoped_ptr<device::BluetoothGattConnection> gatt_connection); | |
30 | |
31 ~BluetoothLowEnergyConnection(); | |
32 | |
33 void Connect(); | |
msarda
2015/05/05 11:56:14
Are these methods overriding Connection? If so, th
sacomoto
2015/05/06 13:47:58
Done.
| |
34 | |
35 void Disconnect(); | |
36 | |
37 protected: | |
38 // proximity_auth::Connection | |
39 void SendMessageImpl(scoped_ptr<WireMessage> message) override; | |
40 scoped_ptr<WireMessage> DeserializeWireMessage( | |
41 bool* is_incomplete_message) override; | |
42 | |
43 // device::BluetoothAdaptor::Observer | |
44 void DeviceRemoved(device::BluetoothAdapter* adapter, | |
45 device::BluetoothDevice* device) override; | |
46 void GattDiscoveryCompleteForService( | |
47 device::BluetoothAdapter* adapter, | |
48 device::BluetoothGattService* service) override; | |
49 void GattCharacteristicAdded( | |
50 device::BluetoothAdapter* adapter, | |
51 device::BluetoothGattCharacteristic* characteristic) override; | |
52 void GattCharacteristicValueChanged( | |
53 device::BluetoothAdapter* adapter, | |
54 device::BluetoothGattCharacteristic* characteristic, | |
55 const std::vector<uint8>& value) override; | |
56 | |
57 private: | |
58 std::string remote_device_address() { | |
msarda
2015/05/05 11:56:14
This is not a trivial method. It should be GetRemo
msarda
2015/05/05 11:56:14
Change return type to const std::string&
sacomoto
2015/05/06 13:47:58
Done.
sacomoto
2015/05/06 13:47:58
Done.
| |
59 return remote_device().bluetooth_address; | |
60 } | |
61 | |
62 // Send a invite to connect signal (defined in Socketeer library) to the | |
msarda
2015/05/05 11:56:14
s/Send a invite/Sends an invite
msarda
2015/05/05 11:56:14
Remote reference to Socketeer library. That is not
sacomoto
2015/05/06 13:47:58
Done.
sacomoto
2015/05/06 13:47:58
Done.
| |
63 // central. | |
msarda
2015/05/05 11:56:14
central? Should this be peripheral?
sacomoto
2015/05/06 13:47:58
Done.
| |
64 void SendInviteToConnectSignal(); | |
65 | |
66 // Called when there is an error writing the remote characteristic | |
msarda
2015/05/05 11:56:14
s/writing the/writing to the
sacomoto
2015/05/06 13:47:58
Done.
| |
67 // |to_peripheral_char_|. | |
68 void OnWriteRemoteCharacteristicError( | |
69 device::BluetoothGattService::GattErrorCode error); | |
70 | |
71 // Handles the discovery of a new characteristic. | |
72 void HandleCharacteristicUpdate( | |
73 device::BluetoothGattCharacteristic* characteristic); | |
74 | |
75 // The connection is complete when: (i) |to_peripheral_char_| and | |
msarda
2015/05/05 11:56:14
Maybe move (i) and (ii) on different lines (like b
sacomoto
2015/05/06 13:47:58
Done.
| |
76 // |from_peripheral_char_| were found, and (ii) |notify_session_| was set for | |
77 // |from_peripheral_char_|. This function verifies if the connection is | |
78 // complete and updates the status accordingly. There are two asyncronous | |
79 // events that can cause the connection to be completed: (i) a new | |
80 // characteristic is discovered (HandleCharacteristicUpdate) or (ii) a new | |
81 // notify session is started (OnNotifySessionStarted). | |
82 void CompleteConnection(); | |
83 | |
84 // Starts a notify session for |from_peripheral_char_|. | |
85 void StartNotifySession(); | |
86 | |
87 // Called when there is an error starting a notification session for | |
88 // |from_peripheral_char_|. | |
msarda
2015/05/05 11:56:14
s/|from_peripheral_char_|/|from_peripheral_char_|
sacomoto
2015/05/06 13:47:58
Done.
| |
89 void OnNotifySessionError(device::BluetoothGattService::GattErrorCode); | |
90 | |
91 // Called when a notification session is successfully started for | |
92 // |from_peripheral_char_|. | |
msarda
2015/05/05 11:56:14
Ditto.
sacomoto
2015/05/06 13:47:58
Done.
| |
93 void OnNotifySessionStarted( | |
94 scoped_ptr<device::BluetoothGattNotifySession> notify_session); | |
95 | |
96 // Stops |notify_session_|. | |
97 void StopNotifySession(); | |
98 | |
99 // Updates the value of |has_to_peripheral_char| and | |
100 // |has_from_peripheral_char| | |
101 // when for |characteristic| or characteristics in |service|. | |
102 void UpdateCharacteristicsStatus( | |
103 device::BluetoothGattCharacteristic* characteristic); | |
104 | |
105 // Returns the device corresponding to |remote_device_address_|. | |
106 device::BluetoothDevice* GetRemoteDevice(); | |
107 | |
108 // Returns the service corresponding to |remote_service_uuid_| in the current | |
109 // device. | |
110 device::BluetoothGattService* GetRemoteService(); | |
111 | |
112 // Returns the characteristic corresponding to |identifier| in the current | |
113 // service. | |
114 device::BluetoothGattCharacteristic* GetGattCharacteristic( | |
115 const std::string& identifier); | |
116 | |
117 // The Bluetooth adapter over which the Bluetooth connection will be made. | |
118 scoped_refptr<device::BluetoothAdapter> adapter_; | |
119 | |
120 // The uuid of the service it looks for to establish a GattConnection. | |
121 const device::BluetoothUUID remote_service_uuid_; | |
122 | |
123 // The identifier of the service corresponding to |remote_service_uuid|. | |
124 std::string remote_service_id_; | |
125 | |
126 // The GATT connection with the remote device. | |
127 scoped_ptr<device::BluetoothGattConnection> connection_; | |
128 | |
129 // Characteristic used to send data to the remote device in the peripheral | |
130 // role. | |
131 const std::string to_peripheral_char_ = | |
msarda
2015/05/05 11:56:14
Same as for from_peripheral_char_
sacomoto
2015/05/06 13:47:59
Done.
| |
132 "977c6674-1239-4e72-993b-502369b8bb5a"; | |
133 | |
134 // Internal unique identifier for |to_peripheral_char_|. | |
135 std::string to_peripheral_char_id_; | |
136 | |
137 // Characteristic used to receive data from the remote device in the | |
138 // peripheral role. | |
139 const std::string from_peripheral_char_ = | |
msarda
2015/05/05 11:56:14
This is a characteristic UUID. This is not clear f
msarda
2015/05/05 11:56:14
These should be constants received from the outsid
sacomoto
2015/05/06 13:47:58
Done.
sacomoto
2015/05/06 13:47:58
Done.
| |
140 "f4b904a2-a030-43b3-98a8-221c536c03cb"; | |
141 | |
142 // Internal unique identifier for |from_peripheral_char_|. | |
143 std::string from_peripheral_char_id_; | |
144 | |
145 // Indicates if there is a pending notification session. Used to ensure there | |
146 // is only one pending notify session. | |
147 bool notify_session_pending_; | |
148 | |
149 // The notify session for |from_peripheral_char|. | |
150 scoped_ptr<device::BluetoothGattNotifySession> notify_session_; | |
151 | |
152 base::WeakPtrFactory<BluetoothLowEnergyConnection> weak_ptr_factory_; | |
153 | |
154 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyConnection); | |
155 }; | |
156 | |
157 } // namespace proximity_auth | |
158 | |
159 #endif // COMPONENTS_PROXIMITY_AUTH_BLUETOOTH_LOW_ENERGY_CONNECTION_H | |
OLD | NEW |