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

Side by Side Diff: device/bluetooth/dbus/bluetooth_gatt_characteristic_service_provider_impl.cc

Issue 1979163002: Add DBus plumbing and tests for sending devices with ATT read/writes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@devices
Patch Set: Created 4 years, 7 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 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"
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 method_call, kErrorInvalidArgs, 179 method_call, kErrorInvalidArgs,
180 "No such interface: '" + interface_name + "'."); 180 "No such interface: '" + interface_name + "'.");
181 response_sender.Run(std::move(error_response)); 181 response_sender.Run(std::move(error_response));
182 return; 182 return;
183 } 183 }
184 184
185 // If getting the "Value" property, obtain the value from the delegate. 185 // If getting the "Value" property, obtain the value from the delegate.
186 if (property_name == bluetooth_gatt_characteristic::kValueProperty) { 186 if (property_name == bluetooth_gatt_characteristic::kValueProperty) {
187 DCHECK(delegate_); 187 DCHECK(delegate_);
188 delegate_->GetValue( 188 delegate_->GetValue(
189 dbus::ObjectPath(),
189 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnGet, 190 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnGet,
190 weak_ptr_factory_.GetWeakPtr(), method_call, 191 weak_ptr_factory_.GetWeakPtr(), method_call,
191 response_sender), 192 response_sender),
192 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnFailure, 193 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnFailure,
193 weak_ptr_factory_.GetWeakPtr(), method_call, 194 weak_ptr_factory_.GetWeakPtr(), method_call,
194 response_sender)); 195 response_sender));
195 return; 196 return;
196 } 197 }
197 198
198 std::unique_ptr<dbus::Response> response = 199 std::unique_ptr<dbus::Response> response =
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 method_call, kErrorInvalidArgs, 282 method_call, kErrorInvalidArgs,
282 "Property '" + property_name + "' has type 'ay'."); 283 "Property '" + property_name + "' has type 'ay'.");
283 response_sender.Run(std::move(error_response)); 284 response_sender.Run(std::move(error_response));
284 return; 285 return;
285 } 286 }
286 287
287 // Pass the set request onto the delegate. 288 // Pass the set request onto the delegate.
288 std::vector<uint8_t> value(bytes, bytes + length); 289 std::vector<uint8_t> value(bytes, bytes + length);
289 DCHECK(delegate_); 290 DCHECK(delegate_);
290 delegate_->SetValue( 291 delegate_->SetValue(
291 value, 292 dbus::ObjectPath(), value,
292 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnSet, 293 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnSet,
293 weak_ptr_factory_.GetWeakPtr(), method_call, response_sender), 294 weak_ptr_factory_.GetWeakPtr(), method_call, response_sender),
294 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnFailure, 295 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnFailure,
295 weak_ptr_factory_.GetWeakPtr(), method_call, response_sender)); 296 weak_ptr_factory_.GetWeakPtr(), method_call, response_sender));
296 } 297 }
297 298
298 void BluetoothGattCharacteristicServiceProviderImpl::GetAll( 299 void BluetoothGattCharacteristicServiceProviderImpl::GetAll(
299 dbus::MethodCall* method_call, 300 dbus::MethodCall* method_call,
300 dbus::ExportedObject::ResponseSender response_sender) { 301 dbus::ExportedObject::ResponseSender response_sender) {
301 VLOG(2) << "BluetoothGattCharacteristicServiceProvider::GetAll: " 302 VLOG(2) << "BluetoothGattCharacteristicServiceProvider::GetAll: "
(...skipping 19 matching lines...) Expand all
321 method_call, kErrorInvalidArgs, 322 method_call, kErrorInvalidArgs,
322 "No such interface: '" + interface_name + "'."); 323 "No such interface: '" + interface_name + "'.");
323 response_sender.Run(std::move(error_response)); 324 response_sender.Run(std::move(error_response));
324 return; 325 return;
325 } 326 }
326 327
327 // Try to obtain the value from the delegate. We will construct the 328 // Try to obtain the value from the delegate. We will construct the
328 // response in the success callback. 329 // response in the success callback.
329 DCHECK(delegate_); 330 DCHECK(delegate_);
330 delegate_->GetValue( 331 delegate_->GetValue(
332 dbus::ObjectPath(),
331 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnGetAll, 333 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnGetAll,
332 weak_ptr_factory_.GetWeakPtr(), method_call, response_sender), 334 weak_ptr_factory_.GetWeakPtr(), method_call, response_sender),
333 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnFailure, 335 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnFailure,
334 weak_ptr_factory_.GetWeakPtr(), method_call, response_sender)); 336 weak_ptr_factory_.GetWeakPtr(), method_call, response_sender));
335 } 337 }
336 338
337 void BluetoothGattCharacteristicServiceProviderImpl::ReadValue( 339 void BluetoothGattCharacteristicServiceProviderImpl::ReadValue(
338 dbus::MethodCall* method_call, 340 dbus::MethodCall* method_call,
339 dbus::ExportedObject::ResponseSender response_sender) { 341 dbus::ExportedObject::ResponseSender response_sender) {
340 VLOG(3) << "BluetoothGattCharacteristicServiceProvider::ReadValue: " 342 VLOG(3) << "BluetoothGattCharacteristicServiceProvider::ReadValue: "
341 << object_path_.value(); 343 << object_path_.value();
342 DCHECK(OnOriginThread()); 344 DCHECK(OnOriginThread());
343 DCHECK(delegate_); 345 DCHECK(delegate_);
344 delegate_->GetValue( 346 delegate_->GetValue(
347 dbus::ObjectPath(),
345 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnReadValue, 348 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnReadValue,
346 weak_ptr_factory_.GetWeakPtr(), method_call, response_sender), 349 weak_ptr_factory_.GetWeakPtr(), method_call, response_sender),
347 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnFailure, 350 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnFailure,
348 weak_ptr_factory_.GetWeakPtr(), method_call, response_sender)); 351 weak_ptr_factory_.GetWeakPtr(), method_call, response_sender));
349 } 352 }
350 353
351 void BluetoothGattCharacteristicServiceProviderImpl::WriteValue( 354 void BluetoothGattCharacteristicServiceProviderImpl::WriteValue(
352 dbus::MethodCall* method_call, 355 dbus::MethodCall* method_call,
353 dbus::ExportedObject::ResponseSender response_sender) { 356 dbus::ExportedObject::ResponseSender response_sender) {
354 VLOG(3) << "BluetoothGattCharacteristicServiceProvider::WriteValue: " 357 VLOG(3) << "BluetoothGattCharacteristicServiceProvider::WriteValue: "
355 << object_path_.value(); 358 << object_path_.value();
356 DCHECK(OnOriginThread()); 359 DCHECK(OnOriginThread());
357 360
358 dbus::MessageReader reader(method_call); 361 dbus::MessageReader reader(method_call);
359 const uint8_t* bytes = NULL; 362 const uint8_t* bytes = NULL;
360 size_t length = 0; 363 size_t length = 0;
361 364
362 if (!reader.PopArrayOfBytes(&bytes, &length)) 365 if (!reader.PopArrayOfBytes(&bytes, &length))
363 VLOG(2) << "Error reading array of bytes in in WriteValue"; 366 VLOG(2) << "Error reading array of bytes in in WriteValue";
364 std::vector<uint8_t> value; 367 std::vector<uint8_t> value;
365 if (bytes) 368 if (bytes)
366 value.assign(bytes, bytes + length); 369 value.assign(bytes, bytes + length);
367 370
368 DCHECK(delegate_); 371 DCHECK(delegate_);
369 delegate_->SetValue( 372 delegate_->SetValue(
370 value, 373 dbus::ObjectPath(), value,
371 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnWriteValue, 374 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnWriteValue,
372 weak_ptr_factory_.GetWeakPtr(), method_call, response_sender), 375 weak_ptr_factory_.GetWeakPtr(), method_call, response_sender),
373 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnFailure, 376 base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnFailure,
374 weak_ptr_factory_.GetWeakPtr(), method_call, response_sender)); 377 weak_ptr_factory_.GetWeakPtr(), method_call, response_sender));
375 } 378 }
376 379
377 void BluetoothGattCharacteristicServiceProviderImpl::StartNotify( 380 void BluetoothGattCharacteristicServiceProviderImpl::StartNotify(
378 dbus::MethodCall* method_call, 381 dbus::MethodCall* method_call,
379 dbus::ExportedObject::ResponseSender response_sender) { 382 dbus::ExportedObject::ResponseSender response_sender) {
380 VLOG(3) << "BluetoothGattCharacteristicServiceProvider::StartNotify: " 383 VLOG(3) << "BluetoothGattCharacteristicServiceProvider::StartNotify: "
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 method_call, kErrorFailed, "Failed to get/set characteristic value."); 521 method_call, kErrorFailed, "Failed to get/set characteristic value.");
519 response_sender.Run(std::move(error_response)); 522 response_sender.Run(std::move(error_response));
520 } 523 }
521 524
522 const dbus::ObjectPath& 525 const dbus::ObjectPath&
523 BluetoothGattCharacteristicServiceProviderImpl::object_path() const { 526 BluetoothGattCharacteristicServiceProviderImpl::object_path() const {
524 return object_path_; 527 return object_path_;
525 } 528 }
526 529
527 } // namespace bluez 530 } // namespace bluez
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698