| 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 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 const std::vector<dbus::ObjectPath>& includes) | 27 const std::vector<dbus::ObjectPath>& includes) |
| 28 : origin_thread_id_(base::PlatformThread::CurrentId()), | 28 : origin_thread_id_(base::PlatformThread::CurrentId()), |
| 29 uuid_(uuid), | 29 uuid_(uuid), |
| 30 is_primary_(is_primary), | 30 is_primary_(is_primary), |
| 31 includes_(includes), | 31 includes_(includes), |
| 32 bus_(bus), | 32 bus_(bus), |
| 33 object_path_(object_path), | 33 object_path_(object_path), |
| 34 weak_ptr_factory_(this) { | 34 weak_ptr_factory_(this) { |
| 35 VLOG(1) << "Creating Bluetooth GATT service: " << object_path_.value() | 35 VLOG(1) << "Creating Bluetooth GATT service: " << object_path_.value() |
| 36 << " UUID: " << uuid; | 36 << " UUID: " << uuid; |
| 37 |
| 38 // If we have a null bus, this means that this is being initialized for a |
| 39 // test, hence we shouldn't do any other setup. |
| 40 if (!bus_) |
| 41 return; |
| 42 |
| 37 DCHECK(!uuid_.empty()); | 43 DCHECK(!uuid_.empty()); |
| 38 DCHECK(object_path_.IsValid()); | 44 DCHECK(object_path_.IsValid()); |
| 39 DCHECK(bus_); | |
| 40 | 45 |
| 41 exported_object_ = bus_->GetExportedObject(object_path_); | 46 exported_object_ = bus_->GetExportedObject(object_path_); |
| 42 | 47 |
| 43 exported_object_->ExportMethod( | 48 exported_object_->ExportMethod( |
| 44 dbus::kDBusPropertiesInterface, dbus::kDBusPropertiesGet, | 49 dbus::kDBusPropertiesInterface, dbus::kDBusPropertiesGet, |
| 45 base::Bind(&BluetoothGattServiceServiceProviderImpl::Get, | 50 base::Bind(&BluetoothGattServiceServiceProviderImpl::Get, |
| 46 weak_ptr_factory_.GetWeakPtr()), | 51 weak_ptr_factory_.GetWeakPtr()), |
| 47 base::Bind(&BluetoothGattServiceServiceProviderImpl::OnExported, | 52 base::Bind(&BluetoothGattServiceServiceProviderImpl::OnExported, |
| 48 weak_ptr_factory_.GetWeakPtr())); | 53 weak_ptr_factory_.GetWeakPtr())); |
| 49 | 54 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 62 weak_ptr_factory_.GetWeakPtr())); | 67 weak_ptr_factory_.GetWeakPtr())); |
| 63 } | 68 } |
| 64 | 69 |
| 65 BluetoothGattServiceServiceProviderImpl:: | 70 BluetoothGattServiceServiceProviderImpl:: |
| 66 ~BluetoothGattServiceServiceProviderImpl() { | 71 ~BluetoothGattServiceServiceProviderImpl() { |
| 67 VLOG(1) << "Cleaning up Bluetooth GATT service: " << object_path_.value(); | 72 VLOG(1) << "Cleaning up Bluetooth GATT service: " << object_path_.value(); |
| 68 if (bus_) | 73 if (bus_) |
| 69 bus_->UnregisterExportedObject(object_path_); | 74 bus_->UnregisterExportedObject(object_path_); |
| 70 } | 75 } |
| 71 | 76 |
| 72 BluetoothGattServiceServiceProviderImpl:: | |
| 73 BluetoothGattServiceServiceProviderImpl(const dbus::ObjectPath& object_path, | |
| 74 const std::string& uuid, | |
| 75 bool is_primary) | |
| 76 : origin_thread_id_(base::PlatformThread::CurrentId()), | |
| 77 uuid_(uuid), | |
| 78 is_primary_(is_primary), | |
| 79 bus_(nullptr), | |
| 80 object_path_(object_path), | |
| 81 weak_ptr_factory_(this) {} | |
| 82 | |
| 83 bool BluetoothGattServiceServiceProviderImpl::OnOriginThread() { | 77 bool BluetoothGattServiceServiceProviderImpl::OnOriginThread() { |
| 84 return base::PlatformThread::CurrentId() == origin_thread_id_; | 78 return base::PlatformThread::CurrentId() == origin_thread_id_; |
| 85 } | 79 } |
| 86 | 80 |
| 87 void BluetoothGattServiceServiceProviderImpl::Get( | 81 void BluetoothGattServiceServiceProviderImpl::Get( |
| 88 dbus::MethodCall* method_call, | 82 dbus::MethodCall* method_call, |
| 89 dbus::ExportedObject::ResponseSender response_sender) { | 83 dbus::ExportedObject::ResponseSender response_sender) { |
| 90 VLOG(2) << "BluetoothGattServiceServiceProvider::Get: " | 84 VLOG(2) << "BluetoothGattServiceServiceProvider::Get: " |
| 91 << object_path_.value(); | 85 << object_path_.value(); |
| 92 DCHECK(OnOriginThread()); | 86 DCHECK(OnOriginThread()); |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 LOG_IF(WARNING, !success) << "Failed to export " << interface_name << "." | 224 LOG_IF(WARNING, !success) << "Failed to export " << interface_name << "." |
| 231 << method_name; | 225 << method_name; |
| 232 } | 226 } |
| 233 | 227 |
| 234 const dbus::ObjectPath& BluetoothGattServiceServiceProviderImpl::object_path() | 228 const dbus::ObjectPath& BluetoothGattServiceServiceProviderImpl::object_path() |
| 235 const { | 229 const { |
| 236 return object_path_; | 230 return object_path_; |
| 237 } | 231 } |
| 238 | 232 |
| 239 } // namespace bluez | 233 } // namespace bluez |
| OLD | NEW |