Chromium Code Reviews| 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 #include "device/bluetooth/bluetooth_gatt_connection.h" | 5 #include "device/bluetooth/bluetooth_gatt_connection.h" |
| 6 | 6 |
| 7 #include "device/bluetooth/bluetooth_adapter.h" | |
| 8 | |
| 7 namespace device { | 9 namespace device { |
| 8 | 10 |
| 9 BluetoothGattConnection::BluetoothGattConnection() { | 11 BluetoothGattConnection::BluetoothGattConnection( |
| 12 BluetoothAdapter* adapter, | |
| 13 const std::string& device_address) | |
| 14 : adapter_(adapter), device_address_(device_address) { | |
| 15 DCHECK(adapter_.get()); | |
| 16 DCHECK(!device_address_.empty()); | |
| 17 | |
| 18 BluetoothDevice* device = adapter_->GetDevice(device_address_); | |
| 19 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.
| |
| 20 device->IncrementGattConnectionReferenceCount(); | |
| 10 } | 21 } |
| 11 | 22 |
| 12 BluetoothGattConnection::~BluetoothGattConnection() { | 23 BluetoothGattConnection::~BluetoothGattConnection() { |
| 24 Disconnect(); | |
| 25 } | |
| 26 | |
| 27 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.
| |
| 28 return device_address_; | |
| 29 } | |
| 30 | |
| 31 bool BluetoothGattConnection::IsConnected() { | |
| 32 return !already_decremented_connection_reference_on_device_ && | |
| 33 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.
| |
| 34 } | |
| 35 | |
| 36 void BluetoothGattConnection::Disconnect() { | |
| 37 if (already_decremented_connection_reference_on_device_) | |
| 38 return; | |
| 39 | |
| 40 already_decremented_connection_reference_on_device_ = true; | |
| 41 BluetoothDevice* device = adapter_->GetDevice(device_address_); | |
| 42 if (device) | |
| 43 device->DecrementGattConnectionReferenceCount(); | |
| 13 } | 44 } |
| 14 | 45 |
| 15 } // namespace device | 46 } // namespace device |
| OLD | NEW |