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
3 // found in the LICENSE file.
5 #include "device/bluetooth/bluetooth_gatt_connection.h"
7 #include "device/bluetooth/bluetooth_adapter.h"
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());
18 device_
= adapter_
->GetDevice(device_address_
);
20 owns_reference_for_connection_
= true;
21 device_
->AddGattConnection(this);
24 BluetoothGattConnection::~BluetoothGattConnection() {
28 const std::string
& BluetoothGattConnection::GetDeviceAddress() const {
29 return device_address_
;
32 bool BluetoothGattConnection::IsConnected() {
33 if (!owns_reference_for_connection_
)
35 DCHECK(adapter_
->GetDevice(device_address_
));
36 DCHECK(device_
->IsGattConnected());
40 void BluetoothGattConnection::Disconnect() {
41 if (!owns_reference_for_connection_
)
44 owns_reference_for_connection_
= false;
45 device_
->RemoveGattConnection(this);
48 void BluetoothGattConnection::InvalidateConnectionReference() {
49 owns_reference_for_connection_
= false;