Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(243)

Side by Side Diff: device/bluetooth/bluetooth_remote_gatt_service_chromeos.cc

Issue 1347193004: Refactor DBusThreadManager to split away BT clients. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_remote_gatt_service_chromeos.h" 5 #include "device/bluetooth/bluetooth_remote_gatt_service_chromeos.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "chromeos/dbus/bluetooth_gatt_service_client.h"
10 #include "chromeos/dbus/dbus_thread_manager.h"
11 #include "device/bluetooth/bluetooth_adapter_chromeos.h" 9 #include "device/bluetooth/bluetooth_adapter_chromeos.h"
12 #include "device/bluetooth/bluetooth_device_chromeos.h" 10 #include "device/bluetooth/bluetooth_device_chromeos.h"
13 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_chromeos.h" 11 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_chromeos.h"
14 #include "device/bluetooth/bluetooth_remote_gatt_descriptor_chromeos.h" 12 #include "device/bluetooth/bluetooth_remote_gatt_descriptor_chromeos.h"
13 #include "device/bluetooth/dbus/bluetooth_gatt_service_client.h"
14 #include "device/bluetooth/dbus/bluez_dbus_manager.h"
15 15
16 namespace chromeos { 16 namespace chromeos {
17 17
18 namespace { 18 namespace {
19 19
20 // TODO(jamuraa) move these to cros_system_api later 20 // TODO(jamuraa) move these to cros_system_api later
21 const char kErrorFailed[] = "org.bluez.Error.Failed"; 21 const char kErrorFailed[] = "org.bluez.Error.Failed";
22 const char kErrorInProgress[] = "org.bluez.Error.InProgress"; 22 const char kErrorInProgress[] = "org.bluez.Error.InProgress";
23 const char kErrorInvalidValueLength[] = "org.bluez.Error.InvalidValueLength"; 23 const char kErrorInvalidValueLength[] = "org.bluez.Error.InvalidValueLength";
24 const char kErrorNotAuthorized[] = "org.bluez.Error.NotAuthorized"; 24 const char kErrorNotAuthorized[] = "org.bluez.Error.NotAuthorized";
25 const char kErrorNotPaired[] = "org.bluez.Error.NotPaired"; 25 const char kErrorNotPaired[] = "org.bluez.Error.NotPaired";
26 const char kErrorNotSupported[] = "org.bluez.Error.NotSupported"; 26 const char kErrorNotSupported[] = "org.bluez.Error.NotSupported";
27 const char kErrorNotPermitted[] = "org.bluez.Error.NotPermitted"; 27 const char kErrorNotPermitted[] = "org.bluez.Error.NotPermitted";
28 28
29 } // namespace 29 } // namespace
30 30
31 BluetoothRemoteGattServiceChromeOS::BluetoothRemoteGattServiceChromeOS( 31 BluetoothRemoteGattServiceChromeOS::BluetoothRemoteGattServiceChromeOS(
32 BluetoothAdapterChromeOS* adapter, 32 BluetoothAdapterChromeOS* adapter,
33 BluetoothDeviceChromeOS* device, 33 BluetoothDeviceChromeOS* device,
34 const dbus::ObjectPath& object_path) 34 const dbus::ObjectPath& object_path)
35 : object_path_(object_path), 35 : object_path_(object_path),
36 adapter_(adapter), 36 adapter_(adapter),
37 device_(device), 37 device_(device),
38 discovery_complete_(false), 38 discovery_complete_(false),
39 weak_ptr_factory_(this) { 39 weak_ptr_factory_(this) {
40 VLOG(1) << "Creating remote GATT service with identifier: " 40 VLOG(1) << "Creating remote GATT service with identifier: "
41 << object_path.value() << ", UUID: " << GetUUID().canonical_value(); 41 << object_path.value() << ", UUID: " << GetUUID().canonical_value();
42 DCHECK(adapter_); 42 DCHECK(adapter_);
43 43
44 DBusThreadManager::Get()->GetBluetoothGattServiceClient()->AddObserver(this); 44 bluez::BluezDBusManager::Get()->GetBluetoothGattServiceClient()->AddObserver(
45 DBusThreadManager::Get()->GetBluetoothGattCharacteristicClient()-> 45 this);
46 AddObserver(this); 46 bluez::BluezDBusManager::Get()
47 ->GetBluetoothGattCharacteristicClient()
48 ->AddObserver(this);
47 49
48 // Add all known GATT characteristics. 50 // Add all known GATT characteristics.
49 const std::vector<dbus::ObjectPath>& gatt_chars = 51 const std::vector<dbus::ObjectPath>& gatt_chars =
50 DBusThreadManager::Get()->GetBluetoothGattCharacteristicClient()-> 52 bluez::BluezDBusManager::Get()
51 GetCharacteristics(); 53 ->GetBluetoothGattCharacteristicClient()
54 ->GetCharacteristics();
52 for (std::vector<dbus::ObjectPath>::const_iterator iter = gatt_chars.begin(); 55 for (std::vector<dbus::ObjectPath>::const_iterator iter = gatt_chars.begin();
53 iter != gatt_chars.end(); ++iter) 56 iter != gatt_chars.end(); ++iter)
54 GattCharacteristicAdded(*iter); 57 GattCharacteristicAdded(*iter);
55 } 58 }
56 59
57 BluetoothRemoteGattServiceChromeOS::~BluetoothRemoteGattServiceChromeOS() { 60 BluetoothRemoteGattServiceChromeOS::~BluetoothRemoteGattServiceChromeOS() {
58 DBusThreadManager::Get()->GetBluetoothGattServiceClient()-> 61 bluez::BluezDBusManager::Get()
59 RemoveObserver(this); 62 ->GetBluetoothGattServiceClient()
60 DBusThreadManager::Get()->GetBluetoothGattCharacteristicClient()-> 63 ->RemoveObserver(this);
61 RemoveObserver(this); 64 bluez::BluezDBusManager::Get()
65 ->GetBluetoothGattCharacteristicClient()
66 ->RemoveObserver(this);
62 67
63 // Clean up all the characteristics. Copy the characteristics list here and 68 // Clean up all the characteristics. Copy the characteristics list here and
64 // clear the original so that when we send GattCharacteristicRemoved(), 69 // clear the original so that when we send GattCharacteristicRemoved(),
65 // GetCharacteristics() returns no characteristics. 70 // GetCharacteristics() returns no characteristics.
66 CharacteristicMap characteristics = characteristics_; 71 CharacteristicMap characteristics = characteristics_;
67 characteristics_.clear(); 72 characteristics_.clear();
68 for (CharacteristicMap::iterator iter = characteristics.begin(); 73 for (CharacteristicMap::iterator iter = characteristics.begin();
69 iter != characteristics.end(); ++iter) { 74 iter != characteristics.end(); ++iter) {
70 DCHECK(adapter_); 75 DCHECK(adapter_);
71 adapter_->NotifyGattCharacteristicRemoved(iter->second); 76 adapter_->NotifyGattCharacteristicRemoved(iter->second);
72 77
73 delete iter->second; 78 delete iter->second;
74 } 79 }
75 } 80 }
76 81
77 std::string BluetoothRemoteGattServiceChromeOS::GetIdentifier() const { 82 std::string BluetoothRemoteGattServiceChromeOS::GetIdentifier() const {
78 return object_path_.value(); 83 return object_path_.value();
79 } 84 }
80 85
81 device::BluetoothUUID BluetoothRemoteGattServiceChromeOS::GetUUID() const { 86 device::BluetoothUUID BluetoothRemoteGattServiceChromeOS::GetUUID() const {
82 BluetoothGattServiceClient::Properties* properties = 87 bluez::BluetoothGattServiceClient::Properties* properties =
83 DBusThreadManager::Get()->GetBluetoothGattServiceClient()-> 88 bluez::BluezDBusManager::Get()
84 GetProperties(object_path_); 89 ->GetBluetoothGattServiceClient()
90 ->GetProperties(object_path_);
85 DCHECK(properties); 91 DCHECK(properties);
86 return device::BluetoothUUID(properties->uuid.value()); 92 return device::BluetoothUUID(properties->uuid.value());
87 } 93 }
88 94
89 bool BluetoothRemoteGattServiceChromeOS::IsLocal() const { 95 bool BluetoothRemoteGattServiceChromeOS::IsLocal() const {
90 return false; 96 return false;
91 } 97 }
92 98
93 bool BluetoothRemoteGattServiceChromeOS::IsPrimary() const { 99 bool BluetoothRemoteGattServiceChromeOS::IsPrimary() const {
94 BluetoothGattServiceClient::Properties* properties = 100 bluez::BluetoothGattServiceClient::Properties* properties =
95 DBusThreadManager::Get()->GetBluetoothGattServiceClient()-> 101 bluez::BluezDBusManager::Get()
96 GetProperties(object_path_); 102 ->GetBluetoothGattServiceClient()
103 ->GetProperties(object_path_);
97 DCHECK(properties); 104 DCHECK(properties);
98 return properties->primary.value(); 105 return properties->primary.value();
99 } 106 }
100 107
101 device::BluetoothDevice* BluetoothRemoteGattServiceChromeOS::GetDevice() const { 108 device::BluetoothDevice* BluetoothRemoteGattServiceChromeOS::GetDevice() const {
102 return device_; 109 return device_;
103 } 110 }
104 111
105 std::vector<device::BluetoothGattCharacteristic*> 112 std::vector<device::BluetoothGattCharacteristic*>
106 BluetoothRemoteGattServiceChromeOS::GetCharacteristics() const { 113 BluetoothRemoteGattServiceChromeOS::GetCharacteristics() const {
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 } 227 }
221 228
222 void BluetoothRemoteGattServiceChromeOS::GattServicePropertyChanged( 229 void BluetoothRemoteGattServiceChromeOS::GattServicePropertyChanged(
223 const dbus::ObjectPath& object_path, 230 const dbus::ObjectPath& object_path,
224 const std::string& property_name){ 231 const std::string& property_name){
225 if (object_path != object_path_) 232 if (object_path != object_path_)
226 return; 233 return;
227 234
228 VLOG(1) << "Service property changed: \"" << property_name << "\", " 235 VLOG(1) << "Service property changed: \"" << property_name << "\", "
229 << object_path.value(); 236 << object_path.value();
230 BluetoothGattServiceClient::Properties* properties = 237 bluez::BluetoothGattServiceClient::Properties* properties =
231 DBusThreadManager::Get()->GetBluetoothGattServiceClient()->GetProperties( 238 bluez::BluezDBusManager::Get()
232 object_path); 239 ->GetBluetoothGattServiceClient()
240 ->GetProperties(object_path);
233 DCHECK(properties); 241 DCHECK(properties);
234 242
235 if (property_name != properties->characteristics.name()) { 243 if (property_name != properties->characteristics.name()) {
236 NotifyServiceChanged(); 244 NotifyServiceChanged();
237 return; 245 return;
238 } 246 }
239 247
240 if (discovery_complete_) 248 if (discovery_complete_)
241 return; 249 return;
242 250
243 VLOG(1) << "All characteristics were discovered for service: " 251 VLOG(1) << "All characteristics were discovered for service: "
244 << object_path.value(); 252 << object_path.value();
245 discovery_complete_ = true; 253 discovery_complete_ = true;
246 DCHECK(adapter_); 254 DCHECK(adapter_);
247 adapter_->NotifyGattDiscoveryComplete(this); 255 adapter_->NotifyGattDiscoveryComplete(this);
248 } 256 }
249 257
250 void BluetoothRemoteGattServiceChromeOS::GattCharacteristicAdded( 258 void BluetoothRemoteGattServiceChromeOS::GattCharacteristicAdded(
251 const dbus::ObjectPath& object_path) { 259 const dbus::ObjectPath& object_path) {
252 if (characteristics_.find(object_path) != characteristics_.end()) { 260 if (characteristics_.find(object_path) != characteristics_.end()) {
253 VLOG(1) << "Remote GATT characteristic already exists: " 261 VLOG(1) << "Remote GATT characteristic already exists: "
254 << object_path.value(); 262 << object_path.value();
255 return; 263 return;
256 } 264 }
257 265
258 BluetoothGattCharacteristicClient::Properties* properties = 266 bluez::BluetoothGattCharacteristicClient::Properties* properties =
259 DBusThreadManager::Get()->GetBluetoothGattCharacteristicClient()-> 267 bluez::BluezDBusManager::Get()
260 GetProperties(object_path); 268 ->GetBluetoothGattCharacteristicClient()
269 ->GetProperties(object_path);
261 DCHECK(properties); 270 DCHECK(properties);
262 if (properties->service.value() != object_path_) { 271 if (properties->service.value() != object_path_) {
263 VLOG(2) << "Remote GATT characteristic does not belong to this service."; 272 VLOG(2) << "Remote GATT characteristic does not belong to this service.";
264 return; 273 return;
265 } 274 }
266 275
267 VLOG(1) << "Adding new remote GATT characteristic for GATT service: " 276 VLOG(1) << "Adding new remote GATT characteristic for GATT service: "
268 << GetIdentifier() << ", UUID: " << GetUUID().canonical_value(); 277 << GetIdentifier() << ", UUID: " << GetUUID().canonical_value();
269 278
270 BluetoothRemoteGattCharacteristicChromeOS* characteristic = 279 BluetoothRemoteGattCharacteristicChromeOS* characteristic =
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 if (iter == characteristics_.end()) { 314 if (iter == characteristics_.end()) {
306 VLOG(3) << "Properties of unknown characteristic changed"; 315 VLOG(3) << "Properties of unknown characteristic changed";
307 return; 316 return;
308 } 317 }
309 318
310 // We may receive a property changed event in certain cases, e.g. when the 319 // We may receive a property changed event in certain cases, e.g. when the
311 // characteristic "Flags" property has been updated with values from the 320 // characteristic "Flags" property has been updated with values from the
312 // "Characteristic Extended Properties" descriptor. In this case, kick off 321 // "Characteristic Extended Properties" descriptor. In this case, kick off
313 // a service changed observer event to let observers refresh the 322 // a service changed observer event to let observers refresh the
314 // characteristics. 323 // characteristics.
315 BluetoothGattCharacteristicClient::Properties* properties = 324 bluez::BluetoothGattCharacteristicClient::Properties* properties =
316 DBusThreadManager::Get()->GetBluetoothGattCharacteristicClient()-> 325 bluez::BluezDBusManager::Get()
317 GetProperties(object_path); 326 ->GetBluetoothGattCharacteristicClient()
327 ->GetProperties(object_path);
318 328
319 DCHECK(properties); 329 DCHECK(properties);
320 DCHECK(adapter_); 330 DCHECK(adapter_);
321 331
322 if (property_name == properties->flags.name()) 332 if (property_name == properties->flags.name())
323 NotifyServiceChanged(); 333 NotifyServiceChanged();
324 else if (property_name == properties->value.name()) 334 else if (property_name == properties->value.name())
325 adapter_->NotifyGattCharacteristicValueChanged(iter->second, 335 adapter_->NotifyGattCharacteristicValueChanged(iter->second,
326 properties->value.value()); 336 properties->value.value());
327 } 337 }
328 338
329 } // namespace chromeos 339 } // namespace chromeos
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_remote_gatt_service_chromeos.h ('k') | device/bluetooth/bluetooth_socket_chromeos.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698