| 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_chromeos.h" | 5 #include "device/bluetooth/bluetooth_gatt_connection_chromeos.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "chromeos/dbus/dbus_thread_manager.h" | |
| 10 #include "device/bluetooth/bluetooth_adapter.h" | 9 #include "device/bluetooth/bluetooth_adapter.h" |
| 11 #include "device/bluetooth/bluetooth_device.h" | 10 #include "device/bluetooth/bluetooth_device.h" |
| 11 #include "device/bluetooth/dbus/bluez_dbus_manager.h" |
| 12 | 12 |
| 13 namespace chromeos { | 13 namespace chromeos { |
| 14 | 14 |
| 15 BluetoothGattConnectionChromeOS::BluetoothGattConnectionChromeOS( | 15 BluetoothGattConnectionChromeOS::BluetoothGattConnectionChromeOS( |
| 16 scoped_refptr<device::BluetoothAdapter> adapter, | 16 scoped_refptr<device::BluetoothAdapter> adapter, |
| 17 const std::string& device_address, | 17 const std::string& device_address, |
| 18 const dbus::ObjectPath& object_path) | 18 const dbus::ObjectPath& object_path) |
| 19 : connected_(true), | 19 : connected_(true), |
| 20 adapter_(adapter), | 20 adapter_(adapter), |
| 21 device_address_(device_address), | 21 device_address_(device_address), |
| 22 object_path_(object_path) { | 22 object_path_(object_path) { |
| 23 DCHECK(adapter_.get()); | 23 DCHECK(adapter_.get()); |
| 24 DCHECK(!device_address_.empty()); | 24 DCHECK(!device_address_.empty()); |
| 25 DCHECK(object_path_.IsValid()); | 25 DCHECK(object_path_.IsValid()); |
| 26 | 26 |
| 27 DBusThreadManager::Get()->GetBluetoothDeviceClient()->AddObserver(this); | 27 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->AddObserver(this); |
| 28 } | 28 } |
| 29 | 29 |
| 30 BluetoothGattConnectionChromeOS::~BluetoothGattConnectionChromeOS() { | 30 BluetoothGattConnectionChromeOS::~BluetoothGattConnectionChromeOS() { |
| 31 DBusThreadManager::Get()->GetBluetoothDeviceClient()->RemoveObserver(this); | 31 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->RemoveObserver( |
| 32 this); |
| 32 Disconnect(); | 33 Disconnect(); |
| 33 } | 34 } |
| 34 | 35 |
| 35 std::string BluetoothGattConnectionChromeOS::GetDeviceAddress() const { | 36 std::string BluetoothGattConnectionChromeOS::GetDeviceAddress() const { |
| 36 return device_address_; | 37 return device_address_; |
| 37 } | 38 } |
| 38 | 39 |
| 39 bool BluetoothGattConnectionChromeOS::IsConnected() { | 40 bool BluetoothGattConnectionChromeOS::IsConnected() { |
| 40 // Lazily determine the activity state of the connection. If already | 41 // Lazily determine the activity state of the connection. If already |
| 41 // marked as inactive, then return false. Otherwise, explicitly mark | 42 // marked as inactive, then return false. Otherwise, explicitly mark |
| 42 // |connected_| as false if the device is removed or disconnected. We do this, | 43 // |connected_| as false if the device is removed or disconnected. We do this, |
| 43 // so that if this method is called during a call to DeviceRemoved or | 44 // so that if this method is called during a call to DeviceRemoved or |
| 44 // DeviceChanged somewhere else, it returns the correct status. | 45 // DeviceChanged somewhere else, it returns the correct status. |
| 45 if (!connected_) | 46 if (!connected_) |
| 46 return false; | 47 return false; |
| 47 | 48 |
| 48 BluetoothDeviceClient::Properties* properties = | 49 bluez::BluetoothDeviceClient::Properties* properties = |
| 49 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> | 50 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( |
| 50 GetProperties(object_path_); | 51 object_path_); |
| 51 if (!properties || !properties->connected.value()) | 52 if (!properties || !properties->connected.value()) |
| 52 connected_ = false; | 53 connected_ = false; |
| 53 | 54 |
| 54 return connected_; | 55 return connected_; |
| 55 } | 56 } |
| 56 | 57 |
| 57 void BluetoothGattConnectionChromeOS::Disconnect() { | 58 void BluetoothGattConnectionChromeOS::Disconnect() { |
| 58 if (!connected_) { | 59 if (!connected_) { |
| 59 VLOG(1) << "Connection already inactive."; | 60 VLOG(1) << "Connection already inactive."; |
| 60 return; | 61 return; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 80 | 81 |
| 81 void BluetoothGattConnectionChromeOS::DevicePropertyChanged( | 82 void BluetoothGattConnectionChromeOS::DevicePropertyChanged( |
| 82 const dbus::ObjectPath& object_path, | 83 const dbus::ObjectPath& object_path, |
| 83 const std::string& property_name) { | 84 const std::string& property_name) { |
| 84 if (object_path != object_path_) | 85 if (object_path != object_path_) |
| 85 return; | 86 return; |
| 86 | 87 |
| 87 if (!connected_) | 88 if (!connected_) |
| 88 return; | 89 return; |
| 89 | 90 |
| 90 BluetoothDeviceClient::Properties* properties = | 91 bluez::BluetoothDeviceClient::Properties* properties = |
| 91 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> | 92 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties( |
| 92 GetProperties(object_path_); | 93 object_path_); |
| 93 | 94 |
| 94 if (!properties) { | 95 if (!properties) { |
| 95 connected_ = false; | 96 connected_ = false; |
| 96 return; | 97 return; |
| 97 } | 98 } |
| 98 | 99 |
| 99 if (property_name == properties->connected.name() && | 100 if (property_name == properties->connected.name() && |
| 100 !properties->connected.value()) | 101 !properties->connected.value()) |
| 101 connected_ = false; | 102 connected_ = false; |
| 102 } | 103 } |
| 103 | 104 |
| 104 } // namespace chromeos | 105 } // namespace chromeos |
| OLD | NEW |