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

Unified Diff: device/bluetooth/bluetooth_gatt_connection.cc

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_gatt_connection.cc
diff --git a/device/bluetooth/bluetooth_gatt_connection.cc b/device/bluetooth/bluetooth_gatt_connection.cc
index 721391e8d1a803db0aa87aa76d5d89b583a5b950..b0670372479903021e7eafd558aa24277f5489ed 100644
--- a/device/bluetooth/bluetooth_gatt_connection.cc
+++ b/device/bluetooth/bluetooth_gatt_connection.cc
@@ -4,12 +4,43 @@
#include "device/bluetooth/bluetooth_gatt_connection.h"
+#include "device/bluetooth/bluetooth_adapter.h"
+
namespace device {
-BluetoothGattConnection::BluetoothGattConnection() {
+BluetoothGattConnection::BluetoothGattConnection(
+ BluetoothAdapter* adapter,
+ const std::string& device_address)
+ : adapter_(adapter), device_address_(device_address) {
+ DCHECK(adapter_.get());
+ DCHECK(!device_address_.empty());
+
+ BluetoothDevice* device = adapter_->GetDevice(device_address_);
+ if (device)
Jeffrey Yasskin 2015/08/19 22:49:45 If !device, IsConnected() should probably return f
scheib 2015/09/13 02:40:28 Done.
+ device->IncrementGattConnectionReferenceCount();
}
BluetoothGattConnection::~BluetoothGattConnection() {
+ Disconnect();
+}
+
+std::string BluetoothGattConnection::GetDeviceAddress() const {
Jeffrey Yasskin 2015/08/19 22:49:46 Return a const std::string&?
scheib 2015/09/13 02:40:28 Done.
+ return device_address_;
+}
+
+bool BluetoothGattConnection::IsConnected() {
+ return !already_decremented_connection_reference_on_device_ &&
+ adapter_->GetDevice(device_address_)->IsGattConnected();
Jeffrey Yasskin 2015/08/19 22:49:46 This leads to an interesting situation where: 1) w
Jeffrey Yasskin 2015/08/19 22:49:46 Do you need to check for adapter_->GetDevice() ret
scheib 2015/09/13 02:40:28 Done - refactored reference counting to have point
scheib 2015/09/13 02:40:28 Done.
+}
+
+void BluetoothGattConnection::Disconnect() {
+ if (already_decremented_connection_reference_on_device_)
+ return;
+
+ already_decremented_connection_reference_on_device_ = true;
+ BluetoothDevice* device = adapter_->GetDevice(device_address_);
+ if (device)
+ device->DecrementGattConnectionReferenceCount();
}
} // namespace device

Powered by Google App Engine
This is Rietveld 408576698