Index: device/bluetooth/bluetooth_device.h |
diff --git a/device/bluetooth/bluetooth_device.h b/device/bluetooth/bluetooth_device.h |
index 5e1e6059d68536832a667295211077d07ed101f3..86bce2129b84e037a860371c707bd578fd96df14 100644 |
--- a/device/bluetooth/bluetooth_device.h |
+++ b/device/bluetooth/bluetooth_device.h |
@@ -6,11 +6,13 @@ |
#define DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_H_ |
#include <map> |
+#include <set> |
#include <string> |
#include <vector> |
#include "base/callback.h" |
#include "base/memory/ref_counted.h" |
+#include "base/numerics/safe_math.h" |
#include "base/strings/string16.h" |
#include "device/bluetooth/bluetooth_export.h" |
#include "device/bluetooth/bluetooth_uuid.h" |
@@ -239,6 +241,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; |
@@ -406,9 +411,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; |
@@ -430,11 +434,37 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothDevice { |
static std::string CanonicalizeAddress(const std::string& address); |
protected: |
+ // BluetoothGattConnection is a friend to call Add/RemoveGattConnection. |
+ 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 |
+ // changes. |
+ virtual void CreateGattConnectionImpl() = 0; |
+ |
+ // Disconnects GATT connection on platforms that maintain a specific GATT |
+ // connection. |
+ virtual void DisconnectGatt() = 0; |
+ |
+ // Calls any pending callbacks for CreateGattConnection based on result of |
+ // subclasses actions initiated in CreateGattConnectionImpl or related |
+ // disconnection events. These may be called at any time, even multiple times, |
Jeffrey Yasskin
2015/09/16 00:45:39
The implementation says DidDisconnectGatt() should
scheib
2015/09/16 21:19:08
Done.
|
+ // to ensure a change in platform state is correctly tracked. |
+ void DidConnectGatt(); |
+ void DidFailToConnectGatt(ConnectErrorCode); |
+ void DidDisconnectGatt(); |
+ |
+ // Maintains GattConnection reference count by tracking friend class |
+ // BluetoothGattConnection instances. |
Jeffrey Yasskin
2015/09/16 00:45:39
Is it too obvious to say that the BluetoothGattCon
scheib
2015/09/16 21:19:08
Done.
|
+ void AddGattConnection(BluetoothGattConnection*); |
+ void RemoveGattConnection(BluetoothGattConnection*); |
+ |
// Clears the list of service data. |
void ClearServiceData(); |
@@ -446,6 +476,13 @@ 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_; |
+ |
+ // BluetoothGattConnection objects keeping the GATT connection alive. |
+ std::set<BluetoothGattConnection*> gatt_connections_; |
+ |
// Mapping from the platform-specific GATT service identifiers to |
// BluetoothGattService objects. |
typedef std::map<std::string, BluetoothGattService*> GattServiceMap; |