| 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" | 7 #include "device/bluetooth/bluetooth_adapter.h" |
| 8 | 8 |
| 9 namespace device { | 9 namespace device { |
| 10 | 10 |
| 11 BluetoothGattConnection::BluetoothGattConnection( | 11 BluetoothGattConnection::BluetoothGattConnection( |
| 12 scoped_refptr<device::BluetoothAdapter> adapter, | 12 scoped_refptr<device::BluetoothAdapter> adapter, |
| 13 const std::string& device_address) | 13 const std::string& device_address, |
| 14 : adapter_(adapter), device_address_(device_address) { | 14 bool in_progress) |
| 15 : adapter_(adapter), |
| 16 device_address_(device_address), |
| 17 in_progress_(in_progress) { |
| 15 DCHECK(adapter_.get()); | 18 DCHECK(adapter_.get()); |
| 16 DCHECK(!device_address_.empty()); | 19 DCHECK(!device_address_.empty()); |
| 17 | 20 |
| 18 device_ = adapter_->GetDevice(device_address_); | 21 device_ = adapter_->GetDevice(device_address_); |
| 19 DCHECK(device_); | 22 DCHECK(device_); |
| 20 owns_reference_for_connection_ = true; | 23 owns_reference_for_connection_ = true; |
| 21 device_->AddGattConnection(this); | 24 device_->AddGattConnection(this); |
| 22 } | 25 } |
| 23 | 26 |
| 24 BluetoothGattConnection::~BluetoothGattConnection() { | 27 BluetoothGattConnection::~BluetoothGattConnection() { |
| 25 Disconnect(); | 28 Disconnect(); |
| 26 } | 29 } |
| 27 | 30 |
| 28 const std::string& BluetoothGattConnection::GetDeviceAddress() const { | 31 const std::string& BluetoothGattConnection::GetDeviceAddress() const { |
| 29 return device_address_; | 32 return device_address_; |
| 30 } | 33 } |
| 31 | 34 |
| 32 bool BluetoothGattConnection::IsConnected() { | 35 bool BluetoothGattConnection::IsConnected() { |
| 33 if (!owns_reference_for_connection_) | 36 if (!owns_reference_for_connection_) |
| 34 return false; | 37 return false; |
| 35 DCHECK(adapter_->GetDevice(device_address_)); | 38 DCHECK(adapter_->GetDevice(device_address_)); |
| 36 DCHECK(device_->IsGattConnected()); | 39 DCHECK(device_->IsGattConnected()); |
| 37 return true; | 40 return true; |
| 38 } | 41 } |
| 39 | 42 |
| 43 bool BluetoothGattConnection::InProgress() { |
| 44 return in_progress_; |
| 45 } |
| 46 |
| 40 void BluetoothGattConnection::Disconnect() { | 47 void BluetoothGattConnection::Disconnect() { |
| 41 if (!owns_reference_for_connection_) | 48 if (!owns_reference_for_connection_) |
| 42 return; | 49 return; |
| 43 | 50 |
| 44 owns_reference_for_connection_ = false; | 51 owns_reference_for_connection_ = false; |
| 45 device_->RemoveGattConnection(this); | 52 device_->RemoveGattConnection(this); |
| 46 } | 53 } |
| 47 | 54 |
| 48 void BluetoothGattConnection::InvalidateConnectionReference() { | 55 void BluetoothGattConnection::InvalidateConnectionReference() { |
| 49 owns_reference_for_connection_ = false; | 56 owns_reference_for_connection_ = false; |
| 50 } | 57 } |
| 51 | 58 |
| 52 } // namespace device | 59 } // namespace device |
| OLD | NEW |