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

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

Issue 1116963002: Bluetooth low energy connection. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removing debug messages Created 5 years, 7 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_connection.h
diff --git a/components/proximity_auth/ble/bluetooth_low_energy_connection.h b/components/proximity_auth/ble/bluetooth_low_energy_connection.h
new file mode 100644
index 0000000000000000000000000000000000000000..354553b902e06067e45fcf9ab81012f053d56107
--- /dev/null
+++ b/components/proximity_auth/ble/bluetooth_low_energy_connection.h
@@ -0,0 +1,159 @@
+// Copyright 2015 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_BLUETOOTH_LOW_ENERGY_CONNECTION_H
+#define COMPONENTS_PROXIMITY_AUTH_BLUETOOTH_LOW_ENERGY_CONNECTION_H
+
+#include "base/macros.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
+#include "components/proximity_auth/ble/fake_wire_message.h"
+#include "components/proximity_auth/connection.h"
+#include "device/bluetooth/bluetooth_adapter.h"
+#include "device/bluetooth/bluetooth_device.h"
+#include "device/bluetooth/bluetooth_gatt_characteristic.h"
+#include "device/bluetooth/bluetooth_gatt_notify_session.h"
+#include "device/bluetooth/bluetooth_uuid.h"
+
+namespace proximity_auth {
+
+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.
+ public device::BluetoothAdapter::Observer {
+ public:
+ BluetoothLowEnergyConnection(
+ const RemoteDevice& remote_device,
+ scoped_refptr<device::BluetoothAdapter> adapter,
+ device::BluetoothUUID remote_service_uuid,
+ scoped_ptr<device::BluetoothGattConnection> gatt_connection);
+
+ ~BluetoothLowEnergyConnection();
+
+ 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.
+
+ void Disconnect();
+
+ protected:
+ // proximity_auth::Connection
+ void SendMessageImpl(scoped_ptr<WireMessage> message) override;
+ scoped_ptr<WireMessage> DeserializeWireMessage(
+ bool* is_incomplete_message) override;
+
+ // device::BluetoothAdaptor::Observer
+ void DeviceRemoved(device::BluetoothAdapter* adapter,
+ device::BluetoothDevice* device) override;
+ void GattDiscoveryCompleteForService(
+ device::BluetoothAdapter* adapter,
+ device::BluetoothGattService* service) override;
+ void GattCharacteristicAdded(
+ device::BluetoothAdapter* adapter,
+ device::BluetoothGattCharacteristic* characteristic) override;
+ void GattCharacteristicValueChanged(
+ device::BluetoothAdapter* adapter,
+ device::BluetoothGattCharacteristic* characteristic,
+ const std::vector<uint8>& value) override;
+
+ private:
+ 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.
+ return remote_device().bluetooth_address;
+ }
+
+ // 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.
+ // central.
msarda 2015/05/05 11:56:14 central? Should this be peripheral?
sacomoto 2015/05/06 13:47:58 Done.
+ void SendInviteToConnectSignal();
+
+ // 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.
+ // |to_peripheral_char_|.
+ void OnWriteRemoteCharacteristicError(
+ device::BluetoothGattService::GattErrorCode error);
+
+ // Handles the discovery of a new characteristic.
+ void HandleCharacteristicUpdate(
+ device::BluetoothGattCharacteristic* characteristic);
+
+ // 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.
+ // |from_peripheral_char_| were found, and (ii) |notify_session_| was set for
+ // |from_peripheral_char_|. This function verifies if the connection is
+ // complete and updates the status accordingly. There are two asyncronous
+ // events that can cause the connection to be completed: (i) a new
+ // characteristic is discovered (HandleCharacteristicUpdate) or (ii) a new
+ // notify session is started (OnNotifySessionStarted).
+ void CompleteConnection();
+
+ // Starts a notify session for |from_peripheral_char_|.
+ void StartNotifySession();
+
+ // Called when there is an error starting a notification session for
+ // |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.
+ void OnNotifySessionError(device::BluetoothGattService::GattErrorCode);
+
+ // Called when a notification session is successfully started for
+ // |from_peripheral_char_|.
msarda 2015/05/05 11:56:14 Ditto.
sacomoto 2015/05/06 13:47:58 Done.
+ void OnNotifySessionStarted(
+ scoped_ptr<device::BluetoothGattNotifySession> notify_session);
+
+ // Stops |notify_session_|.
+ void StopNotifySession();
+
+ // Updates the value of |has_to_peripheral_char| and
+ // |has_from_peripheral_char|
+ // when for |characteristic| or characteristics in |service|.
+ void UpdateCharacteristicsStatus(
+ device::BluetoothGattCharacteristic* characteristic);
+
+ // Returns the device corresponding to |remote_device_address_|.
+ device::BluetoothDevice* GetRemoteDevice();
+
+ // Returns the service corresponding to |remote_service_uuid_| in the current
+ // device.
+ device::BluetoothGattService* GetRemoteService();
+
+ // Returns the characteristic corresponding to |identifier| in the current
+ // service.
+ device::BluetoothGattCharacteristic* GetGattCharacteristic(
+ const std::string& identifier);
+
+ // The Bluetooth adapter over which the Bluetooth connection will be made.
+ scoped_refptr<device::BluetoothAdapter> adapter_;
+
+ // The uuid of the service it looks for to establish a GattConnection.
+ const device::BluetoothUUID remote_service_uuid_;
+
+ // The identifier of the service corresponding to |remote_service_uuid|.
+ std::string remote_service_id_;
+
+ // The GATT connection with the remote device.
+ scoped_ptr<device::BluetoothGattConnection> connection_;
+
+ // Characteristic used to send data to the remote device in the peripheral
+ // role.
+ 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.
+ "977c6674-1239-4e72-993b-502369b8bb5a";
+
+ // Internal unique identifier for |to_peripheral_char_|.
+ std::string to_peripheral_char_id_;
+
+ // Characteristic used to receive data from the remote device in the
+ // peripheral role.
+ 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.
+ "f4b904a2-a030-43b3-98a8-221c536c03cb";
+
+ // Internal unique identifier for |from_peripheral_char_|.
+ std::string from_peripheral_char_id_;
+
+ // Indicates if there is a pending notification session. Used to ensure there
+ // is only one pending notify session.
+ bool notify_session_pending_;
+
+ // The notify session for |from_peripheral_char|.
+ scoped_ptr<device::BluetoothGattNotifySession> notify_session_;
+
+ base::WeakPtrFactory<BluetoothLowEnergyConnection> weak_ptr_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyConnection);
+};
+
+} // namespace proximity_auth
+
+#endif // COMPONENTS_PROXIMITY_AUTH_BLUETOOTH_LOW_ENERGY_CONNECTION_H

Powered by Google App Engine
This is Rietveld 408576698