| OLD | NEW |
| 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 "chromeos/dbus/fake_bluetooth_gatt_characteristic_client.h" | 5 #include "device/bluetooth/dbus/fake_bluetooth_gatt_characteristic_client.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/rand_util.h" | 9 #include "base/rand_util.h" |
| 10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| 11 #include "base/thread_task_runner_handle.h" | 11 #include "base/thread_task_runner_handle.h" |
| 12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 13 #include "chromeos/dbus/dbus_thread_manager.h" | 13 #include "device/bluetooth/dbus/bluez_dbus_manager.h" |
| 14 #include "chromeos/dbus/fake_bluetooth_gatt_descriptor_client.h" | 14 #include "device/bluetooth/dbus/fake_bluetooth_gatt_descriptor_client.h" |
| 15 #include "third_party/cros_system_api/dbus/service_constants.h" | 15 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 16 | 16 |
| 17 namespace chromeos { | 17 namespace bluez { |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 const int kStartNotifyResponseIntervalMs = 200; | 21 const int kStartNotifyResponseIntervalMs = 200; |
| 22 const int kHeartRateMeasurementNotificationIntervalMs = 2000; | 22 const int kHeartRateMeasurementNotificationIntervalMs = 2000; |
| 23 | 23 |
| 24 } // namespace | 24 } // namespace |
| 25 | 25 |
| 26 FakeBluetoothGattCharacteristicClient::DelayedCallback::DelayedCallback( | 26 FakeBluetoothGattCharacteristicClient::DelayedCallback::DelayedCallback( |
| 27 base::Closure callback, | 27 base::Closure callback, |
| 28 size_t delay) | 28 size_t delay) |
| 29 : callback_(callback), delay_(delay) { | 29 : callback_(callback), delay_(delay) {} |
| 30 } | |
| 31 | 30 |
| 32 FakeBluetoothGattCharacteristicClient::DelayedCallback::~DelayedCallback() { | 31 FakeBluetoothGattCharacteristicClient::DelayedCallback::~DelayedCallback() {} |
| 33 } | |
| 34 | 32 |
| 35 // static | 33 // static |
| 36 const char FakeBluetoothGattCharacteristicClient:: | 34 const char FakeBluetoothGattCharacteristicClient:: |
| 37 kHeartRateMeasurementPathComponent[] = "char0000"; | 35 kHeartRateMeasurementPathComponent[] = "char0000"; |
| 38 const char FakeBluetoothGattCharacteristicClient:: | 36 const char |
| 39 kBodySensorLocationPathComponent[] = "char0001"; | 37 FakeBluetoothGattCharacteristicClient::kBodySensorLocationPathComponent[] = |
| 38 "char0001"; |
| 40 const char FakeBluetoothGattCharacteristicClient:: | 39 const char FakeBluetoothGattCharacteristicClient:: |
| 41 kHeartRateControlPointPathComponent[] = "char0002"; | 40 kHeartRateControlPointPathComponent[] = "char0002"; |
| 42 | 41 |
| 43 // static | 42 // static |
| 44 const char FakeBluetoothGattCharacteristicClient::kHeartRateMeasurementUUID[] = | 43 const char FakeBluetoothGattCharacteristicClient::kHeartRateMeasurementUUID[] = |
| 45 "00002a37-0000-1000-8000-00805f9b34fb"; | 44 "00002a37-0000-1000-8000-00805f9b34fb"; |
| 46 const char FakeBluetoothGattCharacteristicClient::kBodySensorLocationUUID[] = | 45 const char FakeBluetoothGattCharacteristicClient::kBodySensorLocationUUID[] = |
| 47 "00002a38-0000-1000-8000-00805f9b34fb"; | 46 "00002a38-0000-1000-8000-00805f9b34fb"; |
| 48 const char FakeBluetoothGattCharacteristicClient::kHeartRateControlPointUUID[] = | 47 const char FakeBluetoothGattCharacteristicClient::kHeartRateControlPointUUID[] = |
| 49 "00002a39-0000-1000-8000-00805f9b34fb"; | 48 "00002a39-0000-1000-8000-00805f9b34fb"; |
| 50 | 49 |
| 51 FakeBluetoothGattCharacteristicClient::Properties::Properties( | 50 FakeBluetoothGattCharacteristicClient::Properties::Properties( |
| 52 const PropertyChangedCallback& callback) | 51 const PropertyChangedCallback& callback) |
| 53 : BluetoothGattCharacteristicClient::Properties( | 52 : BluetoothGattCharacteristicClient::Properties( |
| 54 NULL, | 53 NULL, |
| 55 bluetooth_gatt_characteristic::kBluetoothGattCharacteristicInterface, | 54 bluetooth_gatt_characteristic::kBluetoothGattCharacteristicInterface, |
| 56 callback) { | 55 callback) {} |
| 57 } | |
| 58 | 56 |
| 59 FakeBluetoothGattCharacteristicClient::Properties::~Properties() { | 57 FakeBluetoothGattCharacteristicClient::Properties::~Properties() {} |
| 60 } | |
| 61 | 58 |
| 62 void FakeBluetoothGattCharacteristicClient::Properties::Get( | 59 void FakeBluetoothGattCharacteristicClient::Properties::Get( |
| 63 dbus::PropertyBase* property, | 60 dbus::PropertyBase* property, |
| 64 dbus::PropertySet::GetCallback callback) { | 61 dbus::PropertySet::GetCallback callback) { |
| 65 VLOG(1) << "Get " << property->name(); | 62 VLOG(1) << "Get " << property->name(); |
| 66 callback.Run(true); | 63 callback.Run(true); |
| 67 } | 64 } |
| 68 | 65 |
| 69 void FakeBluetoothGattCharacteristicClient::Properties::GetAll() { | 66 void FakeBluetoothGattCharacteristicClient::Properties::GetAll() { |
| 70 VLOG(1) << "GetAll"; | 67 VLOG(1) << "GetAll"; |
| 71 } | 68 } |
| 72 | 69 |
| 73 void FakeBluetoothGattCharacteristicClient::Properties::Set( | 70 void FakeBluetoothGattCharacteristicClient::Properties::Set( |
| 74 dbus::PropertyBase* property, | 71 dbus::PropertyBase* property, |
| 75 dbus::PropertySet::SetCallback callback) { | 72 dbus::PropertySet::SetCallback callback) { |
| 76 VLOG(1) << "Set " << property->name(); | 73 VLOG(1) << "Set " << property->name(); |
| 77 callback.Run(false); | 74 callback.Run(false); |
| 78 } | 75 } |
| 79 | 76 |
| 80 FakeBluetoothGattCharacteristicClient::FakeBluetoothGattCharacteristicClient() | 77 FakeBluetoothGattCharacteristicClient::FakeBluetoothGattCharacteristicClient() |
| 81 : heart_rate_visible_(false), | 78 : heart_rate_visible_(false), |
| 82 authorized_(true), | 79 authorized_(true), |
| 83 authenticated_(true), | 80 authenticated_(true), |
| 84 calories_burned_(0), | 81 calories_burned_(0), |
| 85 extra_requests_(0), | 82 extra_requests_(0), |
| 86 weak_ptr_factory_(this) { | 83 weak_ptr_factory_(this) {} |
| 87 } | |
| 88 | 84 |
| 89 FakeBluetoothGattCharacteristicClient:: | 85 FakeBluetoothGattCharacteristicClient:: |
| 90 ~FakeBluetoothGattCharacteristicClient() { | 86 ~FakeBluetoothGattCharacteristicClient() { |
| 91 for (const auto& it : action_extra_requests_) { | 87 for (const auto& it : action_extra_requests_) { |
| 92 delete it.second; | 88 delete it.second; |
| 93 } | 89 } |
| 94 action_extra_requests_.clear(); | 90 action_extra_requests_.clear(); |
| 95 } | 91 } |
| 96 | 92 |
| 97 void FakeBluetoothGattCharacteristicClient::Init(dbus::Bus* bus) { | 93 void FakeBluetoothGattCharacteristicClient::Init(dbus::Bus* bus) {} |
| 98 } | |
| 99 | 94 |
| 100 void FakeBluetoothGattCharacteristicClient::AddObserver(Observer* observer) { | 95 void FakeBluetoothGattCharacteristicClient::AddObserver(Observer* observer) { |
| 101 observers_.AddObserver(observer); | 96 observers_.AddObserver(observer); |
| 102 } | 97 } |
| 103 | 98 |
| 104 void FakeBluetoothGattCharacteristicClient::RemoveObserver(Observer* observer) { | 99 void FakeBluetoothGattCharacteristicClient::RemoveObserver(Observer* observer) { |
| 105 observers_.RemoveObserver(observer); | 100 observers_.RemoveObserver(observer); |
| 106 } | 101 } |
| 107 | 102 |
| 108 std::vector<dbus::ObjectPath> | 103 std::vector<dbus::ObjectPath> |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 "Another write is in progress"); | 235 "Another write is in progress"); |
| 241 if (delayed->delay_ == 0) { | 236 if (delayed->delay_ == 0) { |
| 242 delayed->callback_.Run(); | 237 delayed->callback_.Run(); |
| 243 action_extra_requests_.erase("WriteValue"); | 238 action_extra_requests_.erase("WriteValue"); |
| 244 delete delayed; | 239 delete delayed; |
| 245 } | 240 } |
| 246 return; | 241 return; |
| 247 } | 242 } |
| 248 base::Closure completed_callback; | 243 base::Closure completed_callback; |
| 249 if (value.size() != 1) { | 244 if (value.size() != 1) { |
| 250 completed_callback = base::Bind(error_callback, | 245 completed_callback = |
| 251 "org.bluez.Error.InvalidValueLength", | 246 base::Bind(error_callback, "org.bluez.Error.InvalidValueLength", |
| 252 "Invalid length for write"); | 247 "Invalid length for write"); |
| 253 } else if (value[0] > 1) { | 248 } else if (value[0] > 1) { |
| 254 completed_callback = base::Bind(error_callback, | 249 completed_callback = base::Bind(error_callback, "org.bluez.Error.Failed", |
| 255 "org.bluez.Error.Failed", | |
| 256 "Invalid value given for write"); | 250 "Invalid value given for write"); |
| 257 } else if (value[0] == 1) { | 251 } else if (value[0] == 1) { |
| 258 // TODO(jamuraa): make this happen when the callback happens | 252 // TODO(jamuraa): make this happen when the callback happens |
| 259 calories_burned_ = 0; | 253 calories_burned_ = 0; |
| 260 completed_callback = callback; | 254 completed_callback = callback; |
| 261 } | 255 } |
| 262 | 256 |
| 263 if (extra_requests_ > 0) { | 257 if (extra_requests_ > 0) { |
| 264 action_extra_requests_["WriteValue"] = | 258 action_extra_requests_["WriteValue"] = |
| 265 new DelayedCallback(completed_callback, extra_requests_); | 259 new DelayedCallback(completed_callback, extra_requests_); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 return; | 324 return; |
| 331 } | 325 } |
| 332 | 326 |
| 333 VLOG(2) << "Exposing fake Heart Rate characteristics."; | 327 VLOG(2) << "Exposing fake Heart Rate characteristics."; |
| 334 | 328 |
| 335 std::vector<std::string> flags; | 329 std::vector<std::string> flags; |
| 336 | 330 |
| 337 // ==== Heart Rate Measurement Characteristic ==== | 331 // ==== Heart Rate Measurement Characteristic ==== |
| 338 heart_rate_measurement_path_ = | 332 heart_rate_measurement_path_ = |
| 339 service_path.value() + "/" + kHeartRateMeasurementPathComponent; | 333 service_path.value() + "/" + kHeartRateMeasurementPathComponent; |
| 340 heart_rate_measurement_properties_.reset(new Properties(base::Bind( | 334 heart_rate_measurement_properties_.reset(new Properties( |
| 341 &FakeBluetoothGattCharacteristicClient::OnPropertyChanged, | 335 base::Bind(&FakeBluetoothGattCharacteristicClient::OnPropertyChanged, |
| 342 weak_ptr_factory_.GetWeakPtr(), | 336 weak_ptr_factory_.GetWeakPtr(), |
| 343 dbus::ObjectPath(heart_rate_measurement_path_)))); | 337 dbus::ObjectPath(heart_rate_measurement_path_)))); |
| 344 heart_rate_measurement_properties_->uuid.ReplaceValue( | 338 heart_rate_measurement_properties_->uuid.ReplaceValue( |
| 345 kHeartRateMeasurementUUID); | 339 kHeartRateMeasurementUUID); |
| 346 heart_rate_measurement_properties_->service.ReplaceValue(service_path); | 340 heart_rate_measurement_properties_->service.ReplaceValue(service_path); |
| 347 flags.push_back(bluetooth_gatt_characteristic::kFlagNotify); | 341 flags.push_back(bluetooth_gatt_characteristic::kFlagNotify); |
| 348 heart_rate_measurement_properties_->flags.ReplaceValue(flags); | 342 heart_rate_measurement_properties_->flags.ReplaceValue(flags); |
| 349 | 343 |
| 350 // ==== Body Sensor Location Characteristic ==== | 344 // ==== Body Sensor Location Characteristic ==== |
| 351 body_sensor_location_path_ = | 345 body_sensor_location_path_ = |
| 352 service_path.value() + "/" + kBodySensorLocationPathComponent; | 346 service_path.value() + "/" + kBodySensorLocationPathComponent; |
| 353 body_sensor_location_properties_.reset(new Properties(base::Bind( | 347 body_sensor_location_properties_.reset(new Properties( |
| 354 &FakeBluetoothGattCharacteristicClient::OnPropertyChanged, | 348 base::Bind(&FakeBluetoothGattCharacteristicClient::OnPropertyChanged, |
| 355 weak_ptr_factory_.GetWeakPtr(), | 349 weak_ptr_factory_.GetWeakPtr(), |
| 356 dbus::ObjectPath(body_sensor_location_path_)))); | 350 dbus::ObjectPath(body_sensor_location_path_)))); |
| 357 body_sensor_location_properties_->uuid.ReplaceValue(kBodySensorLocationUUID); | 351 body_sensor_location_properties_->uuid.ReplaceValue(kBodySensorLocationUUID); |
| 358 body_sensor_location_properties_->service.ReplaceValue(service_path); | 352 body_sensor_location_properties_->service.ReplaceValue(service_path); |
| 359 flags.clear(); | 353 flags.clear(); |
| 360 flags.push_back(bluetooth_gatt_characteristic::kFlagRead); | 354 flags.push_back(bluetooth_gatt_characteristic::kFlagRead); |
| 361 body_sensor_location_properties_->flags.ReplaceValue(flags); | 355 body_sensor_location_properties_->flags.ReplaceValue(flags); |
| 362 | 356 |
| 363 // ==== Heart Rate Control Point Characteristic ==== | 357 // ==== Heart Rate Control Point Characteristic ==== |
| 364 heart_rate_control_point_path_ = | 358 heart_rate_control_point_path_ = |
| 365 service_path.value() + "/" + kHeartRateControlPointPathComponent; | 359 service_path.value() + "/" + kHeartRateControlPointPathComponent; |
| 366 heart_rate_control_point_properties_.reset(new Properties(base::Bind( | 360 heart_rate_control_point_properties_.reset(new Properties( |
| 367 &FakeBluetoothGattCharacteristicClient::OnPropertyChanged, | 361 base::Bind(&FakeBluetoothGattCharacteristicClient::OnPropertyChanged, |
| 368 weak_ptr_factory_.GetWeakPtr(), | 362 weak_ptr_factory_.GetWeakPtr(), |
| 369 dbus::ObjectPath(heart_rate_control_point_path_)))); | 363 dbus::ObjectPath(heart_rate_control_point_path_)))); |
| 370 heart_rate_control_point_properties_->uuid.ReplaceValue( | 364 heart_rate_control_point_properties_->uuid.ReplaceValue( |
| 371 kHeartRateControlPointUUID); | 365 kHeartRateControlPointUUID); |
| 372 heart_rate_control_point_properties_->service.ReplaceValue(service_path); | 366 heart_rate_control_point_properties_->service.ReplaceValue(service_path); |
| 373 flags.clear(); | 367 flags.clear(); |
| 374 flags.push_back(bluetooth_gatt_characteristic::kFlagWrite); | 368 flags.push_back(bluetooth_gatt_characteristic::kFlagWrite); |
| 375 heart_rate_control_point_properties_->flags.ReplaceValue(flags); | 369 heart_rate_control_point_properties_->flags.ReplaceValue(flags); |
| 376 | 370 |
| 377 heart_rate_visible_ = true; | 371 heart_rate_visible_ = true; |
| 378 | 372 |
| 379 NotifyCharacteristicAdded(dbus::ObjectPath(heart_rate_measurement_path_)); | 373 NotifyCharacteristicAdded(dbus::ObjectPath(heart_rate_measurement_path_)); |
| 380 NotifyCharacteristicAdded(dbus::ObjectPath(body_sensor_location_path_)); | 374 NotifyCharacteristicAdded(dbus::ObjectPath(body_sensor_location_path_)); |
| 381 NotifyCharacteristicAdded(dbus::ObjectPath(heart_rate_control_point_path_)); | 375 NotifyCharacteristicAdded(dbus::ObjectPath(heart_rate_control_point_path_)); |
| 382 | 376 |
| 383 // Expose CCC descriptor for Heart Rate Measurement characteristic. | 377 // Expose CCC descriptor for Heart Rate Measurement characteristic. |
| 384 FakeBluetoothGattDescriptorClient* descriptor_client = | 378 FakeBluetoothGattDescriptorClient* descriptor_client = |
| 385 static_cast<FakeBluetoothGattDescriptorClient*>( | 379 static_cast<FakeBluetoothGattDescriptorClient*>( |
| 386 DBusThreadManager::Get()->GetBluetoothGattDescriptorClient()); | 380 bluez::BluezDBusManager::Get()->GetBluetoothGattDescriptorClient()); |
| 387 dbus::ObjectPath ccc_path(descriptor_client->ExposeDescriptor( | 381 dbus::ObjectPath ccc_path(descriptor_client->ExposeDescriptor( |
| 388 dbus::ObjectPath(heart_rate_measurement_path_), | 382 dbus::ObjectPath(heart_rate_measurement_path_), |
| 389 FakeBluetoothGattDescriptorClient:: | 383 FakeBluetoothGattDescriptorClient:: |
| 390 kClientCharacteristicConfigurationUUID)); | 384 kClientCharacteristicConfigurationUUID)); |
| 391 DCHECK(ccc_path.IsValid()); | 385 DCHECK(ccc_path.IsValid()); |
| 392 heart_rate_measurement_ccc_desc_path_ = ccc_path.value(); | 386 heart_rate_measurement_ccc_desc_path_ = ccc_path.value(); |
| 393 | 387 |
| 394 std::vector<dbus::ObjectPath> desc_paths; | 388 std::vector<dbus::ObjectPath> desc_paths; |
| 395 desc_paths.push_back(ccc_path); | 389 desc_paths.push_back(ccc_path); |
| 396 | 390 |
| 397 heart_rate_measurement_properties_->descriptors.ReplaceValue(desc_paths); | 391 heart_rate_measurement_properties_->descriptors.ReplaceValue(desc_paths); |
| 398 } | 392 } |
| 399 | 393 |
| 400 void FakeBluetoothGattCharacteristicClient::HideHeartRateCharacteristics() { | 394 void FakeBluetoothGattCharacteristicClient::HideHeartRateCharacteristics() { |
| 401 VLOG(2) << "Hiding fake Heart Rate characteristics."; | 395 VLOG(2) << "Hiding fake Heart Rate characteristics."; |
| 402 | 396 |
| 403 // Hide the descriptors. | 397 // Hide the descriptors. |
| 404 FakeBluetoothGattDescriptorClient* descriptor_client = | 398 FakeBluetoothGattDescriptorClient* descriptor_client = |
| 405 static_cast<FakeBluetoothGattDescriptorClient*>( | 399 static_cast<FakeBluetoothGattDescriptorClient*>( |
| 406 DBusThreadManager::Get()->GetBluetoothGattDescriptorClient()); | 400 bluez::BluezDBusManager::Get()->GetBluetoothGattDescriptorClient()); |
| 407 descriptor_client->HideDescriptor( | 401 descriptor_client->HideDescriptor( |
| 408 dbus::ObjectPath(heart_rate_measurement_ccc_desc_path_)); | 402 dbus::ObjectPath(heart_rate_measurement_ccc_desc_path_)); |
| 409 | 403 |
| 410 // Notify the observers before deleting the properties structures so that they | 404 // Notify the observers before deleting the properties structures so that they |
| 411 // can be accessed from the observer method. | 405 // can be accessed from the observer method. |
| 412 NotifyCharacteristicRemoved(dbus::ObjectPath(heart_rate_measurement_path_)); | 406 NotifyCharacteristicRemoved(dbus::ObjectPath(heart_rate_measurement_path_)); |
| 413 NotifyCharacteristicRemoved(dbus::ObjectPath(body_sensor_location_path_)); | 407 NotifyCharacteristicRemoved(dbus::ObjectPath(body_sensor_location_path_)); |
| 414 NotifyCharacteristicRemoved(dbus::ObjectPath(heart_rate_control_point_path_)); | 408 NotifyCharacteristicRemoved(dbus::ObjectPath(heart_rate_control_point_path_)); |
| 415 | 409 |
| 416 heart_rate_measurement_properties_.reset(); | 410 heart_rate_measurement_properties_.reset(); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 } | 446 } |
| 453 | 447 |
| 454 dbus::ObjectPath | 448 dbus::ObjectPath |
| 455 FakeBluetoothGattCharacteristicClient::GetHeartRateControlPointPath() const { | 449 FakeBluetoothGattCharacteristicClient::GetHeartRateControlPointPath() const { |
| 456 return dbus::ObjectPath(heart_rate_control_point_path_); | 450 return dbus::ObjectPath(heart_rate_control_point_path_); |
| 457 } | 451 } |
| 458 | 452 |
| 459 void FakeBluetoothGattCharacteristicClient::OnPropertyChanged( | 453 void FakeBluetoothGattCharacteristicClient::OnPropertyChanged( |
| 460 const dbus::ObjectPath& object_path, | 454 const dbus::ObjectPath& object_path, |
| 461 const std::string& property_name) { | 455 const std::string& property_name) { |
| 462 VLOG(2) << "Characteristic property changed: " << object_path.value() | 456 VLOG(2) << "Characteristic property changed: " << object_path.value() << ": " |
| 463 << ": " << property_name; | 457 << property_name; |
| 464 | 458 |
| 465 FOR_EACH_OBSERVER(BluetoothGattCharacteristicClient::Observer, observers_, | 459 FOR_EACH_OBSERVER( |
| 466 GattCharacteristicPropertyChanged( | 460 BluetoothGattCharacteristicClient::Observer, observers_, |
| 467 object_path, property_name)); | 461 GattCharacteristicPropertyChanged(object_path, property_name)); |
| 468 } | 462 } |
| 469 | 463 |
| 470 void FakeBluetoothGattCharacteristicClient::NotifyCharacteristicAdded( | 464 void FakeBluetoothGattCharacteristicClient::NotifyCharacteristicAdded( |
| 471 const dbus::ObjectPath& object_path) { | 465 const dbus::ObjectPath& object_path) { |
| 472 VLOG(2) << "GATT characteristic added: " << object_path.value(); | 466 VLOG(2) << "GATT characteristic added: " << object_path.value(); |
| 473 FOR_EACH_OBSERVER(BluetoothGattCharacteristicClient::Observer, observers_, | 467 FOR_EACH_OBSERVER(BluetoothGattCharacteristicClient::Observer, observers_, |
| 474 GattCharacteristicAdded(object_path)); | 468 GattCharacteristicAdded(object_path)); |
| 475 } | 469 } |
| 476 | 470 |
| 477 void FakeBluetoothGattCharacteristicClient::NotifyCharacteristicRemoved( | 471 void FakeBluetoothGattCharacteristicClient::NotifyCharacteristicRemoved( |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 | 533 |
| 540 // Pick a value between 117 bpm and 153 bpm for heart rate. | 534 // Pick a value between 117 bpm and 153 bpm for heart rate. |
| 541 value.bpm = static_cast<uint8>(base::RandInt(117, 153)); | 535 value.bpm = static_cast<uint8>(base::RandInt(117, 153)); |
| 542 | 536 |
| 543 // Total calories burned in kJoules since the last reset. Increment this by 1 | 537 // Total calories burned in kJoules since the last reset. Increment this by 1 |
| 544 // every time. It's fine if it overflows: it becomes 0 when the user resets | 538 // every time. It's fine if it overflows: it becomes 0 when the user resets |
| 545 // the heart rate monitor (or pretend that he had a lot of cheeseburgers). | 539 // the heart rate monitor (or pretend that he had a lot of cheeseburgers). |
| 546 value.energy_expanded = calories_burned_++; | 540 value.energy_expanded = calories_burned_++; |
| 547 | 541 |
| 548 // Include one RR-Interval value, in seconds. | 542 // Include one RR-Interval value, in seconds. |
| 549 value.rr_interval = 60/value.bpm; | 543 value.rr_interval = 60 / value.bpm; |
| 550 | 544 |
| 551 // Return the bytes in an array. | 545 // Return the bytes in an array. |
| 552 uint8* bytes = reinterpret_cast<uint8*>(&value); | 546 uint8* bytes = reinterpret_cast<uint8*>(&value); |
| 553 std::vector<uint8> return_value; | 547 std::vector<uint8> return_value; |
| 554 return_value.assign(bytes, bytes + sizeof(value)); | 548 return_value.assign(bytes, bytes + sizeof(value)); |
| 555 return return_value; | 549 return return_value; |
| 556 } | 550 } |
| 557 | 551 |
| 558 bool FakeBluetoothGattCharacteristicClient::IsHeartRateVisible() const { | 552 bool FakeBluetoothGattCharacteristicClient::IsHeartRateVisible() const { |
| 559 DCHECK(heart_rate_visible_ != heart_rate_measurement_path_.empty()); | 553 DCHECK(heart_rate_visible_ != heart_rate_measurement_path_.empty()); |
| 560 DCHECK(heart_rate_visible_ != body_sensor_location_path_.empty()); | 554 DCHECK(heart_rate_visible_ != body_sensor_location_path_.empty()); |
| 561 DCHECK(heart_rate_visible_ != heart_rate_control_point_path_.empty()); | 555 DCHECK(heart_rate_visible_ != heart_rate_control_point_path_.empty()); |
| 562 DCHECK(heart_rate_visible_ == !!heart_rate_measurement_properties_.get()); | 556 DCHECK(heart_rate_visible_ == !!heart_rate_measurement_properties_.get()); |
| 563 DCHECK(heart_rate_visible_ == !!body_sensor_location_properties_.get()); | 557 DCHECK(heart_rate_visible_ == !!body_sensor_location_properties_.get()); |
| 564 DCHECK(heart_rate_visible_ == !!heart_rate_control_point_properties_.get()); | 558 DCHECK(heart_rate_visible_ == !!heart_rate_control_point_properties_.get()); |
| 565 return heart_rate_visible_; | 559 return heart_rate_visible_; |
| 566 } | 560 } |
| 567 | 561 |
| 568 } // namespace chromeos | 562 } // namespace bluez |
| OLD | NEW |