| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/dbus/bluetooth_gatt_service_service_provider_impl.h" | 5 #include "device/bluetooth/dbus/bluetooth_gatt_service_service_provider_impl.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 "third_party/cros_system_api/dbus/service_constants.h" | 9 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 10 | 10 |
| 11 namespace bluez { | 11 namespace bluez { |
| 12 | 12 |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 const char kErrorInvalidArgs[] = "org.freedesktop.DBus.Error.InvalidArgs"; | 15 const char kErrorInvalidArgs[] = "org.freedesktop.DBus.Error.InvalidArgs"; |
| 16 const char kErrorPropertyReadOnly[] = | 16 const char kErrorPropertyReadOnly[] = |
| 17 "org.freedesktop.DBus.Error.PropertyReadOnly"; | 17 "org.freedesktop.DBus.Error.PropertyReadOnly"; |
| 18 | 18 |
| 19 } // namespace | 19 } // namespace |
| 20 | 20 |
| 21 BluetoothGattServiceServiceProviderImpl:: | 21 BluetoothGattServiceServiceProviderImpl:: |
| 22 BluetoothGattServiceServiceProviderImpl( | 22 BluetoothGattServiceServiceProviderImpl( |
| 23 dbus::Bus* bus, | 23 dbus::Bus* bus, |
| 24 const dbus::ObjectPath& object_path, | 24 const dbus::ObjectPath& object_path, |
| 25 const std::string& uuid, | 25 const std::string& uuid, |
| 26 bool is_primary, |
| 26 const std::vector<dbus::ObjectPath>& includes) | 27 const std::vector<dbus::ObjectPath>& includes) |
| 27 : origin_thread_id_(base::PlatformThread::CurrentId()), | 28 : origin_thread_id_(base::PlatformThread::CurrentId()), |
| 28 uuid_(uuid), | 29 uuid_(uuid), |
| 30 is_primary_(is_primary), |
| 29 includes_(includes), | 31 includes_(includes), |
| 30 bus_(bus), | 32 bus_(bus), |
| 31 object_path_(object_path), | 33 object_path_(object_path), |
| 32 weak_ptr_factory_(this) { | 34 weak_ptr_factory_(this) { |
| 33 VLOG(1) << "Creating Bluetooth GATT service: " << object_path_.value() | 35 VLOG(1) << "Creating Bluetooth GATT service: " << object_path_.value() |
| 34 << " UUID: " << uuid; | 36 << " UUID: " << uuid; |
| 35 DCHECK(!uuid_.empty()); | 37 DCHECK(!uuid_.empty()); |
| 36 DCHECK(object_path_.IsValid()); | 38 DCHECK(object_path_.IsValid()); |
| 37 DCHECK(bus_); | 39 DCHECK(bus_); |
| 38 | 40 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 62 | 64 |
| 63 BluetoothGattServiceServiceProviderImpl:: | 65 BluetoothGattServiceServiceProviderImpl:: |
| 64 ~BluetoothGattServiceServiceProviderImpl() { | 66 ~BluetoothGattServiceServiceProviderImpl() { |
| 65 VLOG(1) << "Cleaning up Bluetooth GATT service: " << object_path_.value(); | 67 VLOG(1) << "Cleaning up Bluetooth GATT service: " << object_path_.value(); |
| 66 if (bus_) | 68 if (bus_) |
| 67 bus_->UnregisterExportedObject(object_path_); | 69 bus_->UnregisterExportedObject(object_path_); |
| 68 } | 70 } |
| 69 | 71 |
| 70 BluetoothGattServiceServiceProviderImpl:: | 72 BluetoothGattServiceServiceProviderImpl:: |
| 71 BluetoothGattServiceServiceProviderImpl(const dbus::ObjectPath& object_path, | 73 BluetoothGattServiceServiceProviderImpl(const dbus::ObjectPath& object_path, |
| 72 const std::string& uuid) | 74 const std::string& uuid, |
| 75 bool is_primary) |
| 73 : origin_thread_id_(base::PlatformThread::CurrentId()), | 76 : origin_thread_id_(base::PlatformThread::CurrentId()), |
| 74 uuid_(uuid), | 77 uuid_(uuid), |
| 78 is_primary_(is_primary), |
| 75 bus_(nullptr), | 79 bus_(nullptr), |
| 76 object_path_(object_path), | 80 object_path_(object_path), |
| 77 weak_ptr_factory_(this) {} | 81 weak_ptr_factory_(this) {} |
| 78 | 82 |
| 79 bool BluetoothGattServiceServiceProviderImpl::OnOriginThread() { | 83 bool BluetoothGattServiceServiceProviderImpl::OnOriginThread() { |
| 80 return base::PlatformThread::CurrentId() == origin_thread_id_; | 84 return base::PlatformThread::CurrentId() == origin_thread_id_; |
| 81 } | 85 } |
| 82 | 86 |
| 83 void BluetoothGattServiceServiceProviderImpl::Get( | 87 void BluetoothGattServiceServiceProviderImpl::Get( |
| 84 dbus::MethodCall* method_call, | 88 dbus::MethodCall* method_call, |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 dbus::MessageWriter variant_writer(NULL); | 202 dbus::MessageWriter variant_writer(NULL); |
| 199 | 203 |
| 200 writer->OpenArray("{sv}", &array_writer); | 204 writer->OpenArray("{sv}", &array_writer); |
| 201 | 205 |
| 202 array_writer.OpenDictEntry(&dict_entry_writer); | 206 array_writer.OpenDictEntry(&dict_entry_writer); |
| 203 dict_entry_writer.AppendString(bluetooth_gatt_service::kUUIDProperty); | 207 dict_entry_writer.AppendString(bluetooth_gatt_service::kUUIDProperty); |
| 204 dict_entry_writer.AppendVariantOfString(uuid_); | 208 dict_entry_writer.AppendVariantOfString(uuid_); |
| 205 array_writer.CloseContainer(&dict_entry_writer); | 209 array_writer.CloseContainer(&dict_entry_writer); |
| 206 | 210 |
| 207 array_writer.OpenDictEntry(&dict_entry_writer); | 211 array_writer.OpenDictEntry(&dict_entry_writer); |
| 212 dict_entry_writer.AppendString(bluetooth_gatt_service::kPrimaryProperty); |
| 213 dict_entry_writer.AppendVariantOfBool(is_primary_); |
| 214 array_writer.CloseContainer(&dict_entry_writer); |
| 215 |
| 216 array_writer.OpenDictEntry(&dict_entry_writer); |
| 208 dict_entry_writer.AppendString(bluetooth_gatt_service::kIncludesProperty); | 217 dict_entry_writer.AppendString(bluetooth_gatt_service::kIncludesProperty); |
| 209 dict_entry_writer.OpenVariant("ao", &variant_writer); | 218 dict_entry_writer.OpenVariant("ao", &variant_writer); |
| 210 variant_writer.AppendArrayOfObjectPaths(includes_); | 219 variant_writer.AppendArrayOfObjectPaths(includes_); |
| 211 dict_entry_writer.CloseContainer(&variant_writer); | 220 dict_entry_writer.CloseContainer(&variant_writer); |
| 212 array_writer.CloseContainer(&dict_entry_writer); | 221 array_writer.CloseContainer(&dict_entry_writer); |
| 213 | 222 |
| 214 writer->CloseContainer(&array_writer); | 223 writer->CloseContainer(&array_writer); |
| 215 } | 224 } |
| 216 | 225 |
| 217 void BluetoothGattServiceServiceProviderImpl::OnExported( | 226 void BluetoothGattServiceServiceProviderImpl::OnExported( |
| 218 const std::string& interface_name, | 227 const std::string& interface_name, |
| 219 const std::string& method_name, | 228 const std::string& method_name, |
| 220 bool success) { | 229 bool success) { |
| 221 LOG_IF(WARNING, !success) << "Failed to export " << interface_name << "." | 230 LOG_IF(WARNING, !success) << "Failed to export " << interface_name << "." |
| 222 << method_name; | 231 << method_name; |
| 223 } | 232 } |
| 224 | 233 |
| 225 const dbus::ObjectPath& BluetoothGattServiceServiceProviderImpl::object_path() | 234 const dbus::ObjectPath& BluetoothGattServiceServiceProviderImpl::object_path() |
| 226 const { | 235 const { |
| 227 return object_path_; | 236 return object_path_; |
| 228 } | 237 } |
| 229 | 238 |
| 230 } // namespace bluez | 239 } // namespace bluez |
| OLD | NEW |