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

Unified Diff: device/bluetooth/bluetooth_device.h

Issue 1292263002: bluetooth: Create base class BluetoothDevice::CreateGattConnection impl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bt-adapter-
Patch Set: Updated patchset dependency Created 5 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: device/bluetooth/bluetooth_device.h
diff --git a/device/bluetooth/bluetooth_device.h b/device/bluetooth/bluetooth_device.h
index 67948f800b92fb36ca8e046a080e3717b5652435..0eae80850c2d9999a87c61b91c2c8756a2662b43 100644
--- a/device/bluetooth/bluetooth_device.h
+++ b/device/bluetooth/bluetooth_device.h
@@ -240,6 +240,9 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothDevice {
// they could be connected to the adapter but not to an application.
virtual bool IsConnected() const = 0;
+ // Indicates whether an active GATT connection exists to the device.
+ virtual bool IsGattConnected() const = 0;
+
// Indicates whether the paired device accepts connections initiated from the
// adapter. This value is undefined for unpaired devices.
virtual bool IsConnectable() const = 0;
@@ -407,9 +410,8 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothDevice {
// BluetoothAdapter::Observer::DeviceChanged method.
typedef base::Callback<void(scoped_ptr<BluetoothGattConnection>)>
GattConnectionCallback;
- virtual void CreateGattConnection(
- const GattConnectionCallback& callback,
- const ConnectErrorCallback& error_callback) = 0;
+ virtual void CreateGattConnection(const GattConnectionCallback& callback,
+ const ConnectErrorCallback& error_callback);
// Returns the list of discovered GATT services.
virtual std::vector<BluetoothGattService*> GetGattServices() const;
@@ -431,11 +433,37 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothDevice {
static std::string CanonicalizeAddress(const std::string& address);
protected:
+ // BluetoothGattConnection is a friend to call
+ // In/DecrementGattConnectionReferenceCount.
Jeffrey Yasskin 2015/08/19 22:49:45 "Inc/Decrement", I think.
scheib 2015/09/13 02:40:27 Done.
+ friend BluetoothGattConnection;
+
BluetoothDevice(BluetoothAdapter* adapter);
// Returns the internal name of the Bluetooth device, used by GetName().
virtual std::string GetDeviceName() const = 0;
+ // Implements platform specific operations to initiate a GATT connection.
+ // Subclasses must also call DidConnectGatt, DidFailToConnectGatt, or
+ // DidDisconnectGatt immediately or asynchronously as the connection state
Jeffrey Yasskin 2015/08/19 22:49:45 "immediately or asynchronously" covers all the opt
scheib 2015/09/13 02:40:27 Done. I was trying to communicate that these may b
Jeffrey Yasskin 2015/09/16 00:45:39 Ah, yeah, I like the explicit statement you've add
+ // changes.
+ virtual void CreateGattConnectionImpl() = 0;
Jeffrey Yasskin 2015/08/19 22:49:45 If you intend to only call this from BluetoothDevi
scheib 2015/09/13 02:40:28 Doesn't overriding for implementation then defeat
Jeffrey Yasskin 2015/09/16 00:45:39 Yeah, good point: subclasses will be able to call
+
+ // Disconnects GATT connection on platforms that maintain a specific GATT
+ // connection.
+ virtual void DisconnectGatt() = 0;
+
+ // Calls pending callbacks for CreateGattConnection based on result of
Jeffrey Yasskin 2015/08/19 22:49:45 Say something about how Did*Gatt() calls need to m
scheib 2015/09/13 02:40:27 Done. Regarding out of range, there isn't anything
+ // subclasses actions initiated in CreateGattConnectionImpl or related
+ // disconnection event.
+ void DidConnectGatt();
+ void DidFailToConnectGatt(ConnectErrorCode);
+ void DidDisconnectGatt();
+
+ // Maintains GattConnection reference count. Called by friend class
+ // BluetoothGattConnection.
+ void IncrementGattConnectionReferenceCount();
+ void DecrementGattConnectionReferenceCount();
+
// Clears the list of service data.
void ClearServiceData();
@@ -447,6 +475,14 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothDevice {
// specific pointers via adapter_.
BluetoothAdapter* adapter_;
+ // Callbacks for pending success and error result of CreateGattConnection.
+ std::vector<GattConnectionCallback> create_gatt_connection_success_callbacks_;
+ std::vector<ConnectErrorCallback> create_gatt_connection_error_callbacks_;
+
+ // Represents the number of BluetoothGattConnection objects keeping the
+ // Gatt connection alive to the device.
+ uint32_t gatt_connection_reference_count_ = 0;
+
// Mapping from the platform-specific GATT service identifiers to
// BluetoothGattService objects.
typedef std::map<std::string, BluetoothGattService*> GattServiceMap;

Powered by Google App Engine
This is Rietveld 408576698