summaryrefslogtreecommitdiffstats
path: root/chromeos/dbus/fake_bluetooth_gatt_characteristic_client.cc
diff options
context:
space:
mode:
authorarmansito@chromium.org <armansito@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-07 20:26:45 +0000
committerarmansito@chromium.org <armansito@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-07 20:26:45 +0000
commitd62d70e49f7a7096175a8d071d1b930d9ca2f0a9 (patch)
tree8455a87fb5b9bd25b961e1af9563c292359614a4 /chromeos/dbus/fake_bluetooth_gatt_characteristic_client.cc
parent0fc48a16950329a84ce8cda23646b82052ace2ef (diff)
downloadchromium_src-d62d70e49f7a7096175a8d071d1b930d9ca2f0a9.zip
chromium_src-d62d70e49f7a7096175a8d071d1b930d9ca2f0a9.tar.gz
chromium_src-d62d70e49f7a7096175a8d071d1b930d9ca2f0a9.tar.bz2
device/bluetooth: Update characteristic value D-Bus bindings.
The original BlueZ GATT API doc spec used DBus.Properties interface for characteristic value access. Since we are modifying this API for Chrome OS, this CL updates the Chrome D-Bus bindings and modifies the device/bluetooth GATT code to use the new bindings for characteristic value reads, writes, and updates. BUG=378182 TEST=Tested against my custom bluetoothd build; device_unittests Review URL: https://codereview.chromium.org/301093003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@275693 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos/dbus/fake_bluetooth_gatt_characteristic_client.cc')
-rw-r--r--chromeos/dbus/fake_bluetooth_gatt_characteristic_client.cc129
1 files changed, 62 insertions, 67 deletions
diff --git a/chromeos/dbus/fake_bluetooth_gatt_characteristic_client.cc b/chromeos/dbus/fake_bluetooth_gatt_characteristic_client.cc
index c822f95..0010ace 100644
--- a/chromeos/dbus/fake_bluetooth_gatt_characteristic_client.cc
+++ b/chromeos/dbus/fake_bluetooth_gatt_characteristic_client.cc
@@ -51,9 +51,6 @@ void FakeBluetoothGattCharacteristicClient::Properties::Get(
dbus::PropertyBase* property,
dbus::PropertySet::GetCallback callback) {
VLOG(1) << "Get " << property->name();
-
- // TODO(armansito): Return success or failure here based on characteristic
- // read permission.
callback.Run(true);
}
@@ -65,34 +62,7 @@ void FakeBluetoothGattCharacteristicClient::Properties::Set(
dbus::PropertyBase* property,
dbus::PropertySet::SetCallback callback) {
VLOG(1) << "Set " << property->name();
- if (property->name() != value.name()) {
- callback.Run(false);
- return;
- }
-
- // Allow writing to only certain characteristics that are defined with the
- // write permission.
- bool write = false;
- for (std::vector<std::string>::const_iterator iter = flags.value().begin();
- iter != flags.value().end();
- ++iter) {
- if (*iter == bluetooth_gatt_characteristic::kFlagWrite ||
- *iter == bluetooth_gatt_characteristic::kFlagWriteWithoutResponse ||
- *iter ==
- bluetooth_gatt_characteristic::kFlagAuthenticatedSignedWrites ||
- *iter == bluetooth_gatt_characteristic::kFlagReliableWrite) {
- write = true;
- break;
- }
- }
-
- if (!write) {
- callback.Run(false);
- return;
- }
-
- callback.Run(true);
- property->ReplaceValueWithSetValue();
+ callback.Run(false);
}
FakeBluetoothGattCharacteristicClient::FakeBluetoothGattCharacteristicClient()
@@ -145,6 +115,61 @@ FakeBluetoothGattCharacteristicClient::GetProperties(
return NULL;
}
+void FakeBluetoothGattCharacteristicClient::ReadValue(
+ const dbus::ObjectPath& object_path,
+ const ValueCallback& callback,
+ const ErrorCallback& error_callback) {
+ if (!IsHeartRateVisible()) {
+ error_callback.Run(kUnknownCharacteristicError, "");
+ return;
+ }
+
+ if (object_path.value() == heart_rate_measurement_path_ ||
+ object_path.value() == heart_rate_control_point_path_) {
+ error_callback.Run("org.bluez.Error.ReadNotPermitted",
+ "Reads of this value are not allowed");
+ return;
+ }
+
+ if (object_path.value() != body_sensor_location_path_) {
+ error_callback.Run(kUnknownCharacteristicError, "");
+ return;
+ }
+
+ std::vector<uint8> value;
+ value.push_back(0x06); // Location is "foot".
+ callback.Run(value);
+}
+
+void FakeBluetoothGattCharacteristicClient::WriteValue(
+ const dbus::ObjectPath& object_path,
+ const std::vector<uint8>& value,
+ const base::Closure& callback,
+ const ErrorCallback& error_callback) {
+ if (!IsHeartRateVisible()) {
+ error_callback.Run(kUnknownCharacteristicError, "");
+ return;
+ }
+
+ if (object_path.value() != heart_rate_control_point_path_) {
+ error_callback.Run("org.bluez.Error.WriteNotPermitted",
+ "Writes of this value are not allowed");
+ return;
+ }
+
+ DCHECK(heart_rate_control_point_properties_.get());
+ if (value.size() != 1 || value[0] > 1) {
+ error_callback.Run("org.bluez.Error.Failed",
+ "Invalid value given for write");
+ return;
+ }
+
+ if (value[0] == 1)
+ calories_burned_ = 0;
+
+ callback.Run();
+}
+
void FakeBluetoothGattCharacteristicClient::ExposeHeartRateCharacteristics(
const dbus::ObjectPath& service_path) {
if (IsHeartRateVisible()) {
@@ -169,9 +194,6 @@ void FakeBluetoothGattCharacteristicClient::ExposeHeartRateCharacteristics(
flags.push_back(bluetooth_gatt_characteristic::kFlagNotify);
heart_rate_measurement_properties_->flags.ReplaceValue(flags);
- std::vector<uint8> measurement_value = GetHeartRateMeasurementValue();
- heart_rate_measurement_properties_->value.ReplaceValue(measurement_value);
-
// ==== Body Sensor Location Characteristic ====
body_sensor_location_path_ =
service_path.value() + "/" + kBodySensorLocationPathComponent;
@@ -185,12 +207,6 @@ void FakeBluetoothGattCharacteristicClient::ExposeHeartRateCharacteristics(
flags.push_back(bluetooth_gatt_characteristic::kFlagRead);
body_sensor_location_properties_->flags.ReplaceValue(flags);
- // The sensor is in the "Other" location.
- std::vector<uint8> body_sensor_location_value;
- body_sensor_location_value.push_back(0);
- body_sensor_location_properties_->value.ReplaceValue(
- body_sensor_location_value);
-
// ==== Heart Rate Control Point Characteristic ====
heart_rate_control_point_path_ =
service_path.value() + "/" + kHeartRateControlPointPathComponent;
@@ -205,13 +221,6 @@ void FakeBluetoothGattCharacteristicClient::ExposeHeartRateCharacteristics(
flags.push_back(bluetooth_gatt_characteristic::kFlagWrite);
heart_rate_control_point_properties_->flags.ReplaceValue(flags);
- // Set the initial value to 0. Whenever this gets set to 1, we will reset the
- // total calories burned and change the value back to 0.
- std::vector<uint8> heart_rate_control_point_value;
- heart_rate_control_point_value.push_back(0);
- heart_rate_control_point_properties_->value.ReplaceValue(
- heart_rate_control_point_value);
-
heart_rate_visible_ = true;
NotifyCharacteristicAdded(dbus::ObjectPath(heart_rate_measurement_path_));
@@ -286,25 +295,6 @@ void FakeBluetoothGattCharacteristicClient::OnPropertyChanged(
FOR_EACH_OBSERVER(BluetoothGattCharacteristicClient::Observer, observers_,
GattCharacteristicPropertyChanged(
object_path, property_name));
-
- // If the heart rate control point was set, reset the calories burned.
- if (object_path.value() != heart_rate_control_point_path_)
- return;
- DCHECK(heart_rate_control_point_properties_.get());
- dbus::Property<std::vector<uint8> >* value_prop =
- &heart_rate_control_point_properties_->value;
- if (property_name != value_prop->name())
- return;
-
- std::vector<uint8> value = value_prop->value();
- DCHECK(value.size() == 1);
- if (value[0] == 0)
- return;
-
- DCHECK(value[0] == 1);
- calories_burned_ = 0;
- value[0] = 0;
- value_prop->ReplaceValue(value);
}
void FakeBluetoothGattCharacteristicClient::NotifyCharacteristicAdded(
@@ -327,7 +317,12 @@ void FakeBluetoothGattCharacteristicClient::
return;
VLOG(2) << "Updating heart rate value.";
std::vector<uint8> measurement = GetHeartRateMeasurementValue();
- heart_rate_measurement_properties_->value.ReplaceValue(measurement);
+
+ FOR_EACH_OBSERVER(
+ BluetoothGattCharacteristicClient::Observer,
+ observers_,
+ GattCharacteristicValueUpdated(
+ dbus::ObjectPath(heart_rate_measurement_path_), measurement));
base::MessageLoop::current()->PostDelayedTask(
FROM_HERE,