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

Side by Side Diff: device/bluetooth/bluetooth_gatt_connection.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 unified diff | Download patch
OLDNEW
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;
16
15 // BluetoothGattConnection represents a GATT connection to a Bluetooth device 17 // BluetoothGattConnection represents a GATT connection to a Bluetooth device
16 // that has GATT services. Instances are obtained from a BluetoothDevice, 18 // that has GATT services. Instances are obtained from a BluetoothDevice,
17 // and the connection is kept alive as long as there is at least one 19 // and the connection is kept alive as long as there is at least one
18 // active BluetoothGattConnection object. BluetoothGattConnection objects 20 // active BluetoothGattConnection object. BluetoothGattConnection objects
19 // automatically update themselves, when the connection is terminated by the 21 // automatically update themselves, when the connection is terminated by the
20 // operating system (e.g. due to user action). 22 // operating system (e.g. due to user action).
21 class DEVICE_BLUETOOTH_EXPORT BluetoothGattConnection { 23 class DEVICE_BLUETOOTH_EXPORT BluetoothGattConnection {
22 public: 24 public:
25 BluetoothGattConnection(BluetoothAdapter* adapter,
Jeffrey Yasskin 2015/08/19 22:49:46 Take this as a scoped_refptr<> to make it clear th
scheib 2015/09/13 02:40:28 Done.
26 const std::string& device_address);
27
23 // Destructor automatically closes this GATT connection. If this is the last 28 // Destructor automatically closes this GATT connection. If this is the last
24 // remaining GATT connection and this results in a call to the OS, that call 29 // remaining GATT connection and this results in a call to the OS, that call
25 // may not always succeed. Users can make an explicit call to 30 // may not always succeed. Users can make an explicit call to
26 // BluetoothGattConnection::Close to make sure that they are notified of 31 // BluetoothGattConnection::Close to make sure that they are notified of
27 // a possible error via the callback. 32 // a possible error via the callback.
28 virtual ~BluetoothGattConnection(); 33 virtual ~BluetoothGattConnection();
29 34
30 // Returns the Bluetooth address of the device that this connection is open 35 // Returns the Bluetooth address of the device that this connection is open
31 // to. 36 // to.
32 virtual std::string GetDeviceAddress() const = 0; 37 std::string GetDeviceAddress() const;
33 38
34 // Returns true if this connection is open. 39 // Returns true if this GATT connection is open.
35 virtual bool IsConnected() = 0; 40 virtual bool IsConnected();
36 41
37 // Disconnects this GATT connection. The device may still remain connected due 42 // Disconnects this GATT connection. The device may still remain connected due
38 // to other GATT connections. 43 // to other GATT connections.
39 virtual void Disconnect() = 0; 44 virtual void Disconnect();
40 45
41 protected: 46 protected:
42 BluetoothGattConnection(); 47 // The Bluetooth adapter that this connection is associated with. A reference
48 // is held because BluetoothGattConnection keeps the connection alive.
49 scoped_refptr<BluetoothAdapter> adapter_;
Jeffrey Yasskin 2015/08/19 22:49:46 I'm nervous about holding a reference to Bluetooth
scheib 2015/09/13 02:40:28 The adapter doesn't own the connections. The conne
50
51 // Bluetooth address of the underlying device.
52 std::string device_address_;
43 53
44 private: 54 private:
55 bool already_decremented_connection_reference_on_device_ = false;
Jeffrey Yasskin 2015/08/19 22:49:46 Call this something like "owns_reference_for_conne
scheib 2015/09/13 02:40:28 Done.
56
45 DISALLOW_COPY_AND_ASSIGN(BluetoothGattConnection); 57 DISALLOW_COPY_AND_ASSIGN(BluetoothGattConnection);
46 }; 58 };
47 59
48 } // namespace device 60 } // namespace device
49 61
50 #endif // DEVICE_BLUETOOTH_BLUETOOTH_GATT_CONNECTION_H_ 62 #endif // DEVICE_BLUETOOTH_BLUETOOTH_GATT_CONNECTION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698