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 scoped_refptr<device::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 device_ = adapter_->GetDevice(device_address_); |
| 19 DCHECK(device_); |
| 20 owns_reference_for_connection_ = true; |
| 21 device_->AddGattConnection(this); |
10 } | 22 } |
11 | 23 |
12 BluetoothGattConnection::~BluetoothGattConnection() { | 24 BluetoothGattConnection::~BluetoothGattConnection() { |
| 25 Disconnect(); |
| 26 } |
| 27 |
| 28 const std::string& BluetoothGattConnection::GetDeviceAddress() const { |
| 29 return device_address_; |
| 30 } |
| 31 |
| 32 bool BluetoothGattConnection::IsConnected() { |
| 33 if (!owns_reference_for_connection_) |
| 34 return false; |
| 35 DCHECK(adapter_->GetDevice(device_address_)); |
| 36 DCHECK(device_->IsGattConnected()); |
| 37 return true; |
| 38 } |
| 39 |
| 40 void BluetoothGattConnection::Disconnect() { |
| 41 if (!owns_reference_for_connection_) |
| 42 return; |
| 43 |
| 44 owns_reference_for_connection_ = false; |
| 45 device_->RemoveGattConnection(this); |
| 46 } |
| 47 |
| 48 void BluetoothGattConnection::InvalidateConnectionReference() { |
| 49 owns_reference_for_connection_ = false; |
13 } | 50 } |
14 | 51 |
15 } // namespace device | 52 } // namespace device |
OLD | NEW |