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

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

Issue 1542163002: Switch to standard integer types in device/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: win Created 4 years, 12 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 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 "device/bluetooth/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"
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 delete delayed; 172 delete delayed;
173 } 173 }
174 return; 174 return;
175 } 175 }
176 176
177 base::Closure completed_callback; 177 base::Closure completed_callback;
178 if (!IsHeartRateVisible()) { 178 if (!IsHeartRateVisible()) {
179 completed_callback = 179 completed_callback =
180 base::Bind(error_callback, kUnknownCharacteristicError, ""); 180 base::Bind(error_callback, kUnknownCharacteristicError, "");
181 } else { 181 } else {
182 std::vector<uint8> value = {0x06}; // Location is "foot". 182 std::vector<uint8_t> value = {0x06}; // Location is "foot".
183 completed_callback = base::Bind( 183 completed_callback = base::Bind(
184 &FakeBluetoothGattCharacteristicClient::DelayedReadValueCallback, 184 &FakeBluetoothGattCharacteristicClient::DelayedReadValueCallback,
185 weak_ptr_factory_.GetWeakPtr(), object_path, callback, value); 185 weak_ptr_factory_.GetWeakPtr(), object_path, callback, value);
186 } 186 }
187 187
188 if (extra_requests_ > 0) { 188 if (extra_requests_ > 0) {
189 action_extra_requests_["ReadValue"] = 189 action_extra_requests_["ReadValue"] =
190 new DelayedCallback(completed_callback, extra_requests_); 190 new DelayedCallback(completed_callback, extra_requests_);
191 return; 191 return;
192 } 192 }
193 193
194 completed_callback.Run(); 194 completed_callback.Run();
195 } 195 }
196 196
197 void FakeBluetoothGattCharacteristicClient::WriteValue( 197 void FakeBluetoothGattCharacteristicClient::WriteValue(
198 const dbus::ObjectPath& object_path, 198 const dbus::ObjectPath& object_path,
199 const std::vector<uint8>& value, 199 const std::vector<uint8_t>& value,
200 const base::Closure& callback, 200 const base::Closure& callback,
201 const ErrorCallback& error_callback) { 201 const ErrorCallback& error_callback) {
202 if (!authenticated_) { 202 if (!authenticated_) {
203 error_callback.Run("org.bluez.Error.NotPaired", "Please login"); 203 error_callback.Run("org.bluez.Error.NotPaired", "Please login");
204 return; 204 return;
205 } 205 }
206 206
207 if (!authorized_) { 207 if (!authorized_) {
208 error_callback.Run("org.bluez.Error.NotAuthorized", "Authorize first"); 208 error_callback.Run("org.bluez.Error.NotAuthorized", "Authorize first");
209 return; 209 return;
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 void FakeBluetoothGattCharacteristicClient:: 478 void FakeBluetoothGattCharacteristicClient::
479 ScheduleHeartRateMeasurementValueChange() { 479 ScheduleHeartRateMeasurementValueChange() {
480 if (!IsHeartRateVisible()) 480 if (!IsHeartRateVisible())
481 return; 481 return;
482 482
483 // Don't send updates if the characteristic is not notifying. 483 // Don't send updates if the characteristic is not notifying.
484 if (!heart_rate_measurement_properties_->notifying.value()) 484 if (!heart_rate_measurement_properties_->notifying.value())
485 return; 485 return;
486 486
487 VLOG(2) << "Updating heart rate value."; 487 VLOG(2) << "Updating heart rate value.";
488 std::vector<uint8> measurement = GetHeartRateMeasurementValue(); 488 std::vector<uint8_t> measurement = GetHeartRateMeasurementValue();
489 heart_rate_measurement_properties_->value.ReplaceValue(measurement); 489 heart_rate_measurement_properties_->value.ReplaceValue(measurement);
490 490
491 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 491 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
492 FROM_HERE, base::Bind(&FakeBluetoothGattCharacteristicClient:: 492 FROM_HERE, base::Bind(&FakeBluetoothGattCharacteristicClient::
493 ScheduleHeartRateMeasurementValueChange, 493 ScheduleHeartRateMeasurementValueChange,
494 weak_ptr_factory_.GetWeakPtr()), 494 weak_ptr_factory_.GetWeakPtr()),
495 base::TimeDelta::FromMilliseconds( 495 base::TimeDelta::FromMilliseconds(
496 kHeartRateMeasurementNotificationIntervalMs)); 496 kHeartRateMeasurementNotificationIntervalMs));
497 } 497 }
498 498
499 void FakeBluetoothGattCharacteristicClient::DelayedReadValueCallback( 499 void FakeBluetoothGattCharacteristicClient::DelayedReadValueCallback(
500 const dbus::ObjectPath& object_path, 500 const dbus::ObjectPath& object_path,
501 const ValueCallback& callback, 501 const ValueCallback& callback,
502 const std::vector<uint8_t>& value) { 502 const std::vector<uint8_t>& value) {
503 Properties* properties = GetProperties(object_path); 503 Properties* properties = GetProperties(object_path);
504 DCHECK(properties); 504 DCHECK(properties);
505 505
506 properties->value.ReplaceValue(value); 506 properties->value.ReplaceValue(value);
507 callback.Run(value); 507 callback.Run(value);
508 } 508 }
509 509
510 std::vector<uint8> 510 std::vector<uint8_t>
511 FakeBluetoothGattCharacteristicClient::GetHeartRateMeasurementValue() { 511 FakeBluetoothGattCharacteristicClient::GetHeartRateMeasurementValue() {
512 // TODO(armansito): We should make sure to properly pack this struct to ensure 512 // TODO(armansito): We should make sure to properly pack this struct to ensure
513 // correct byte alignment and endianness. It doesn't matter too much right now 513 // correct byte alignment and endianness. It doesn't matter too much right now
514 // as this is a fake and GCC on Linux seems to do the right thing. 514 // as this is a fake and GCC on Linux seems to do the right thing.
515 struct { 515 struct {
516 uint8 flags; 516 uint8_t flags;
517 uint8 bpm; 517 uint8_t bpm;
518 uint16 energy_expanded; 518 uint16_t energy_expanded;
519 uint16 rr_interval; 519 uint16_t rr_interval;
520 } value; 520 } value;
521 521
522 // Flags in LSB: 0 11 1 1 000 522 // Flags in LSB: 0 11 1 1 000
523 // | | | | | 523 // | | | | |
524 // 8-bit bpm format -- | | | | 524 // 8-bit bpm format -- | | | |
525 // Sensor contact supported -- | | | 525 // Sensor contact supported -- | | |
526 // Energy expanded field present -- | | 526 // Energy expanded field present -- | |
527 // RR-Interval values present ------- | 527 // RR-Interval values present ------- |
528 // Reserved for future use ------------ 528 // Reserved for future use ------------
529 value.flags = 0x0; 529 value.flags = 0x0;
530 value.flags |= (0x03 << 1); 530 value.flags |= (0x03 << 1);
531 value.flags |= (0x01 << 3); 531 value.flags |= (0x01 << 3);
532 value.flags |= (0x01 << 4); 532 value.flags |= (0x01 << 4);
533 533
534 // 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.
535 value.bpm = static_cast<uint8>(base::RandInt(117, 153)); 535 value.bpm = static_cast<uint8_t>(base::RandInt(117, 153));
536 536
537 // 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
538 // 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
539 // 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).
540 value.energy_expanded = calories_burned_++; 540 value.energy_expanded = calories_burned_++;
541 541
542 // Include one RR-Interval value, in seconds. 542 // Include one RR-Interval value, in seconds.
543 value.rr_interval = 60 / value.bpm; 543 value.rr_interval = 60 / value.bpm;
544 544
545 // Return the bytes in an array. 545 // Return the bytes in an array.
546 uint8* bytes = reinterpret_cast<uint8*>(&value); 546 uint8_t* bytes = reinterpret_cast<uint8_t*>(&value);
547 std::vector<uint8> return_value; 547 std::vector<uint8_t> return_value;
548 return_value.assign(bytes, bytes + sizeof(value)); 548 return_value.assign(bytes, bytes + sizeof(value));
549 return return_value; 549 return return_value;
550 } 550 }
551 551
552 bool FakeBluetoothGattCharacteristicClient::IsHeartRateVisible() const { 552 bool FakeBluetoothGattCharacteristicClient::IsHeartRateVisible() const {
553 DCHECK(heart_rate_visible_ != heart_rate_measurement_path_.empty()); 553 DCHECK(heart_rate_visible_ != heart_rate_measurement_path_.empty());
554 DCHECK(heart_rate_visible_ != body_sensor_location_path_.empty()); 554 DCHECK(heart_rate_visible_ != body_sensor_location_path_.empty());
555 DCHECK(heart_rate_visible_ != heart_rate_control_point_path_.empty()); 555 DCHECK(heart_rate_visible_ != heart_rate_control_point_path_.empty());
556 DCHECK(heart_rate_visible_ == !!heart_rate_measurement_properties_.get()); 556 DCHECK(heart_rate_visible_ == !!heart_rate_measurement_properties_.get());
557 DCHECK(heart_rate_visible_ == !!body_sensor_location_properties_.get()); 557 DCHECK(heart_rate_visible_ == !!body_sensor_location_properties_.get());
558 DCHECK(heart_rate_visible_ == !!heart_rate_control_point_properties_.get()); 558 DCHECK(heart_rate_visible_ == !!heart_rate_control_point_properties_.get());
559 return heart_rate_visible_; 559 return heart_rate_visible_;
560 } 560 }
561 561
562 } // namespace bluez 562 } // namespace bluez
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698