OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_GATT_CONNECTION_H_ | 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_GATT_CONNECTION_H_ |
6 #define DEVICE_BLUETOOTH_BLUETOOTH_GATT_CONNECTION_H_ | 6 #define DEVICE_BLUETOOTH_BLUETOOTH_GATT_CONNECTION_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "device/bluetooth/bluetooth_export.h" | 11 #include "device/bluetooth/bluetooth_export.h" |
12 | 12 |
13 namespace device { | 13 namespace device { |
14 | 14 |
15 class BluetoothAdapter; | 15 class BluetoothAdapter; |
16 class BluetoothDevice; | 16 class BluetoothDevice; |
17 | 17 |
18 // BluetoothGattConnection represents a GATT connection to a Bluetooth device | 18 // BluetoothGattConnection represents a GATT connection to a Bluetooth device |
19 // that has GATT services. Instances are obtained from a BluetoothDevice, | 19 // that has GATT services. Instances are obtained from a BluetoothDevice, |
20 // and the connection is kept alive as long as there is at least one | 20 // and the connection is kept alive as long as there is at least one |
21 // active BluetoothGattConnection object. BluetoothGattConnection objects | 21 // active BluetoothGattConnection object. BluetoothGattConnection objects |
22 // automatically update themselves, when the connection is terminated by the | 22 // automatically update themselves, when the connection is terminated by the |
23 // operating system (e.g. due to user action). | 23 // operating system (e.g. due to user action). |
24 class DEVICE_BLUETOOTH_EXPORT BluetoothGattConnection { | 24 class DEVICE_BLUETOOTH_EXPORT BluetoothGattConnection { |
25 public: | 25 public: |
26 BluetoothGattConnection(scoped_refptr<device::BluetoothAdapter> adapter, | 26 BluetoothGattConnection(scoped_refptr<device::BluetoothAdapter> adapter, |
27 const std::string& device_address); | 27 const std::string& device_address, |
| 28 bool in_progress); |
28 | 29 |
29 // Destructor automatically closes this GATT connection. If this is the last | 30 // Destructor automatically closes this GATT connection. If this is the last |
30 // remaining GATT connection and this results in a call to the OS, that call | 31 // remaining GATT connection and this results in a call to the OS, that call |
31 // may not always succeed. Users can make an explicit call to | 32 // may not always succeed. Users can make an explicit call to |
32 // BluetoothGattConnection::Close to make sure that they are notified of | 33 // BluetoothGattConnection::Close to make sure that they are notified of |
33 // a possible error via the callback. | 34 // a possible error via the callback. |
34 virtual ~BluetoothGattConnection(); | 35 virtual ~BluetoothGattConnection(); |
35 | 36 |
36 // Returns the Bluetooth address of the device that this connection is open | 37 // Returns the Bluetooth address of the device that this connection is open |
37 // to. | 38 // to. |
38 const std::string& GetDeviceAddress() const; | 39 const std::string& GetDeviceAddress() const; |
39 | 40 |
40 // Returns true if this GATT connection is open. | 41 // Returns true if this GATT connection is open. |
41 virtual bool IsConnected(); | 42 virtual bool IsConnected(); |
42 | 43 |
| 44 // Returns true if this GATT connection is still in proggress, that is it was |
| 45 // not established yet. |
| 46 virtual bool InProgress(); |
| 47 |
43 // Disconnects this GATT connection. The device may still remain connected due | 48 // Disconnects this GATT connection. The device may still remain connected due |
44 // to other GATT connections. When all BluetoothGattConnection objects are | 49 // to other GATT connections. When all BluetoothGattConnection objects are |
45 // disconnected the BluetoothDevice object will disconnect GATT. | 50 // disconnected the BluetoothDevice object will disconnect GATT. |
46 virtual void Disconnect(); | 51 virtual void Disconnect(); |
47 | 52 |
48 protected: | 53 protected: |
49 friend BluetoothDevice; // For InvalidateConnectionReference. | 54 friend BluetoothDevice; // For InvalidateConnectionReference. |
50 | 55 |
51 // Sets this object to no longer have a reference maintaining the connection. | 56 // Sets this object to no longer have a reference maintaining the connection. |
52 // Only to be called by BluetoothDevice to avoid reentrant code to | 57 // Only to be called by BluetoothDevice to avoid reentrant code to |
53 // RemoveGattConnection in that destructor after BluetoothDevice subclasses | 58 // RemoveGattConnection in that destructor after BluetoothDevice subclasses |
54 // have already been destroyed. | 59 // have already been destroyed. |
55 void InvalidateConnectionReference(); | 60 void InvalidateConnectionReference(); |
56 | 61 |
57 // The Bluetooth adapter that this connection is associated with. A reference | 62 // The Bluetooth adapter that this connection is associated with. A reference |
58 // is held because BluetoothGattConnection keeps the connection alive. | 63 // is held because BluetoothGattConnection keeps the connection alive. |
59 scoped_refptr<BluetoothAdapter> adapter_; | 64 scoped_refptr<BluetoothAdapter> adapter_; |
60 | 65 |
61 // Bluetooth address of the underlying device. | 66 // Bluetooth address of the underlying device. |
62 std::string device_address_; | 67 std::string device_address_; |
63 BluetoothDevice* device_ = nullptr; | 68 BluetoothDevice* device_ = nullptr; |
64 | 69 |
| 70 // true as long as the connection was not established |
| 71 bool in_progress_; |
| 72 |
65 private: | 73 private: |
66 bool owns_reference_for_connection_ = false; | 74 bool owns_reference_for_connection_ = false; |
67 | 75 |
68 DISALLOW_COPY_AND_ASSIGN(BluetoothGattConnection); | 76 DISALLOW_COPY_AND_ASSIGN(BluetoothGattConnection); |
69 }; | 77 }; |
70 | 78 |
71 } // namespace device | 79 } // namespace device |
72 | 80 |
73 #endif // DEVICE_BLUETOOTH_BLUETOOTH_GATT_CONNECTION_H_ | 81 #endif // DEVICE_BLUETOOTH_BLUETOOTH_GATT_CONNECTION_H_ |
OLD | NEW |