| 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_characteristic_service_provider_i
mpl.h" | 5 #include "device/bluetooth/dbus/bluetooth_gatt_characteristic_service_provider_i
mpl.h" |
| 6 | 6 |
| 7 #include <cstddef> | 7 #include <cstddef> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 12 #include "device/bluetooth/dbus/bluetooth_gatt_attribute_helpers.h" |
| 12 #include "third_party/cros_system_api/dbus/service_constants.h" | 13 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 13 | 14 |
| 14 namespace bluez { | 15 namespace bluez { |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| 18 const char kErrorInvalidArgs[] = "org.freedesktop.DBus.Error.InvalidArgs"; | 19 const char kErrorInvalidArgs[] = "org.freedesktop.DBus.Error.InvalidArgs"; |
| 19 const char kErrorPropertyReadOnly[] = | 20 const char kErrorPropertyReadOnly[] = |
| 20 "org.freedesktop.DBus.Error.PropertyReadOnly"; | 21 "org.freedesktop.DBus.Error.PropertyReadOnly"; |
| 21 const char kErrorFailed[] = "org.freedesktop.DBus.Error.Failed"; | 22 const char kErrorFailed[] = "org.freedesktop.DBus.Error.Failed"; |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 WriteProperties(&writer); | 258 WriteProperties(&writer); |
| 258 response_sender.Run(std::move(response)); | 259 response_sender.Run(std::move(response)); |
| 259 } | 260 } |
| 260 | 261 |
| 261 void BluetoothGattCharacteristicServiceProviderImpl::ReadValue( | 262 void BluetoothGattCharacteristicServiceProviderImpl::ReadValue( |
| 262 dbus::MethodCall* method_call, | 263 dbus::MethodCall* method_call, |
| 263 dbus::ExportedObject::ResponseSender response_sender) { | 264 dbus::ExportedObject::ResponseSender response_sender) { |
| 264 VLOG(3) << "BluetoothGattCharacteristicServiceProvider::ReadValue: " | 265 VLOG(3) << "BluetoothGattCharacteristicServiceProvider::ReadValue: " |
| 265 << object_path_.value(); | 266 << object_path_.value(); |
| 266 DCHECK(OnOriginThread()); | 267 DCHECK(OnOriginThread()); |
| 268 |
| 269 dbus::MessageReader reader(method_call); |
| 270 dbus::ObjectPath device_path = ReadDevicePath(&reader); |
| 271 if (device_path.value().empty()) { |
| 272 LOG(WARNING) << "ReadValue called with incorrect parameters: " |
| 273 << method_call->ToString(); |
| 274 // Continue on with an empty device path. This will return a null device to |
| 275 // the delegate, which should know how to handle it. |
| 276 } |
| 277 |
| 267 DCHECK(delegate_); | 278 DCHECK(delegate_); |
| 268 delegate_->GetValue( | 279 delegate_->GetValue( |
| 269 dbus::ObjectPath(), | 280 device_path, |
| 270 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnReadValue, | 281 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnReadValue, |
| 271 weak_ptr_factory_.GetWeakPtr(), method_call, response_sender), | 282 weak_ptr_factory_.GetWeakPtr(), method_call, response_sender), |
| 272 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnFailure, | 283 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnFailure, |
| 273 weak_ptr_factory_.GetWeakPtr(), method_call, response_sender)); | 284 weak_ptr_factory_.GetWeakPtr(), method_call, response_sender)); |
| 274 } | 285 } |
| 275 | 286 |
| 276 void BluetoothGattCharacteristicServiceProviderImpl::WriteValue( | 287 void BluetoothGattCharacteristicServiceProviderImpl::WriteValue( |
| 277 dbus::MethodCall* method_call, | 288 dbus::MethodCall* method_call, |
| 278 dbus::ExportedObject::ResponseSender response_sender) { | 289 dbus::ExportedObject::ResponseSender response_sender) { |
| 279 VLOG(3) << "BluetoothGattCharacteristicServiceProvider::WriteValue: " | 290 VLOG(3) << "BluetoothGattCharacteristicServiceProvider::WriteValue: " |
| 280 << object_path_.value(); | 291 << object_path_.value(); |
| 281 DCHECK(OnOriginThread()); | 292 DCHECK(OnOriginThread()); |
| 282 | 293 |
| 283 dbus::MessageReader reader(method_call); | 294 dbus::MessageReader reader(method_call); |
| 284 const uint8_t* bytes = NULL; | 295 const uint8_t* bytes = NULL; |
| 285 size_t length = 0; | 296 size_t length = 0; |
| 286 | 297 |
| 287 if (!reader.PopArrayOfBytes(&bytes, &length)) | |
| 288 VLOG(2) << "Error reading array of bytes in in WriteValue"; | |
| 289 std::vector<uint8_t> value; | 298 std::vector<uint8_t> value; |
| 299 if (!reader.PopArrayOfBytes(&bytes, &length)) { |
| 300 LOG(WARNING) << "Error reading value parameter. WriteValue called with " |
| 301 "incorrect parameters: " |
| 302 << method_call->ToString(); |
| 303 } |
| 290 if (bytes) | 304 if (bytes) |
| 291 value.assign(bytes, bytes + length); | 305 value.assign(bytes, bytes + length); |
| 292 | 306 |
| 307 dbus::ObjectPath device_path = ReadDevicePath(&reader); |
| 308 if (device_path.value().empty()) { |
| 309 LOG(WARNING) << "WriteValue called with incorrect parameters: " |
| 310 << method_call->ToString(); |
| 311 // Continue on with an empty device path. This will return a null device to |
| 312 // the delegate, which should know how to handle it. |
| 313 } |
| 314 |
| 293 DCHECK(delegate_); | 315 DCHECK(delegate_); |
| 294 delegate_->SetValue( | 316 delegate_->SetValue( |
| 295 dbus::ObjectPath(), value, | 317 device_path, value, |
| 296 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnWriteValue, | 318 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnWriteValue, |
| 297 weak_ptr_factory_.GetWeakPtr(), method_call, response_sender), | 319 weak_ptr_factory_.GetWeakPtr(), method_call, response_sender), |
| 298 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnFailure, | 320 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnFailure, |
| 299 weak_ptr_factory_.GetWeakPtr(), method_call, response_sender)); | 321 weak_ptr_factory_.GetWeakPtr(), method_call, response_sender)); |
| 300 } | 322 } |
| 301 | 323 |
| 302 void BluetoothGattCharacteristicServiceProviderImpl::StartNotify( | 324 void BluetoothGattCharacteristicServiceProviderImpl::StartNotify( |
| 303 dbus::MethodCall* method_call, | 325 dbus::MethodCall* method_call, |
| 304 dbus::ExportedObject::ResponseSender response_sender) { | 326 dbus::ExportedObject::ResponseSender response_sender) { |
| 305 VLOG(3) << "BluetoothGattCharacteristicServiceProvider::StartNotify: " | 327 VLOG(3) << "BluetoothGattCharacteristicServiceProvider::StartNotify: " |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 method_call, kErrorFailed, "Failed to get/set characteristic value."); | 415 method_call, kErrorFailed, "Failed to get/set characteristic value."); |
| 394 response_sender.Run(std::move(error_response)); | 416 response_sender.Run(std::move(error_response)); |
| 395 } | 417 } |
| 396 | 418 |
| 397 const dbus::ObjectPath& | 419 const dbus::ObjectPath& |
| 398 BluetoothGattCharacteristicServiceProviderImpl::object_path() const { | 420 BluetoothGattCharacteristicServiceProviderImpl::object_path() const { |
| 399 return object_path_; | 421 return object_path_; |
| 400 } | 422 } |
| 401 | 423 |
| 402 } // namespace bluez | 424 } // namespace bluez |
| OLD | NEW |