diff options
author | armansito@chromium.org <armansito@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-27 22:26:37 +0000 |
---|---|---|
committer | armansito@chromium.org <armansito@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-27 22:26:37 +0000 |
commit | c3c2abb6c117830b7ed277f229b53e91b19ae2a4 (patch) | |
tree | 24150f1907a54384888c0734b73d3dde55958ba9 /chromeos/dbus/fake_bluetooth_gatt_characteristic_client.cc | |
parent | 2b6c37214d2c8fe24032c6da6b4c46fb33379415 (diff) | |
download | chromium_src-c3c2abb6c117830b7ed277f229b53e91b19ae2a4.zip chromium_src-c3c2abb6c117830b7ed277f229b53e91b19ae2a4.tar.gz chromium_src-c3c2abb6c117830b7ed277f229b53e91b19ae2a4.tar.bz2 |
device/bluetooth: Add device::BluetoothGattNotifySession.
This CL introduces device::BluetoothGattNotifySession, which represents a
single instance of a request to a remote characteristic to start sending value
updates if it supports notifications or indications. Instances are obtained by
calling BluetoothGattCharacteristic::StartNotifySession and sessions are stopped
by calling BluetoothGattNotifySession::Stop on the received instance, which
is owned by the caller. The characteristic will keep sending value updates as
long as there is at least one active session.
This CL implements this functionality for Chrome OS by adding the necessary
bindings for the new D-Bus API calls "StartNotify" and "StopNotify" on
org.bluez.GattCharacteristic1. A reference count is kept for all created
sessions inside BluetoothRemoteGattCharacteristicChromeOS.
BUG=387989
TEST=device_unittests
Review URL: https://codereview.chromium.org/352063002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@280433 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.cc | 68 |
1 files changed, 62 insertions, 6 deletions
diff --git a/chromeos/dbus/fake_bluetooth_gatt_characteristic_client.cc b/chromeos/dbus/fake_bluetooth_gatt_characteristic_client.cc index 0010ace..04745e6 100644 --- a/chromeos/dbus/fake_bluetooth_gatt_characteristic_client.cc +++ b/chromeos/dbus/fake_bluetooth_gatt_characteristic_client.cc @@ -16,6 +16,7 @@ namespace chromeos { namespace { +const int kStartNotifyResponseIntervalMs = 200; const int kHeartRateMeasurementNotificationIntervalMs = 2000; } // namespace @@ -170,6 +171,62 @@ void FakeBluetoothGattCharacteristicClient::WriteValue( callback.Run(); } +void FakeBluetoothGattCharacteristicClient::StartNotify( + const dbus::ObjectPath& object_path, + const base::Closure& callback, + const ErrorCallback& error_callback) { + if (!IsHeartRateVisible()) { + error_callback.Run(kUnknownCharacteristicError, ""); + return; + } + + if (object_path.value() != heart_rate_measurement_path_) { + error_callback.Run("org.bluez.Error.NotSupported", + "This characteristic does not support notifications"); + return; + } + + if (heart_rate_measurement_properties_->notifying.value()) { + error_callback.Run("org.bluez.Error.Busy", + "Characteristic already notifying"); + return; + } + + heart_rate_measurement_properties_->notifying.ReplaceValue(true); + ScheduleHeartRateMeasurementValueChange(); + + // Respond asynchronously. + base::MessageLoop::current()->PostDelayedTask( + FROM_HERE, + callback, + base::TimeDelta::FromMilliseconds(kStartNotifyResponseIntervalMs)); +} + +void FakeBluetoothGattCharacteristicClient::StopNotify( + const dbus::ObjectPath& object_path, + const base::Closure& callback, + const ErrorCallback& error_callback) { + if (!IsHeartRateVisible()) { + error_callback.Run(kUnknownCharacteristicError, ""); + return; + } + + if (object_path.value() != heart_rate_measurement_path_) { + error_callback.Run("org.bluez.Error.NotSupported", + "This characteristic does not support notifications"); + return; + } + + if (!heart_rate_measurement_properties_->notifying.value()) { + error_callback.Run("org.bluez.Error.Failed", "Not notifying"); + return; + } + + heart_rate_measurement_properties_->notifying.ReplaceValue(false); + + callback.Run(); +} + void FakeBluetoothGattCharacteristicClient::ExposeHeartRateCharacteristics( const dbus::ObjectPath& service_path) { if (IsHeartRateVisible()) { @@ -227,12 +284,6 @@ void FakeBluetoothGattCharacteristicClient::ExposeHeartRateCharacteristics( NotifyCharacteristicAdded(dbus::ObjectPath(body_sensor_location_path_)); NotifyCharacteristicAdded(dbus::ObjectPath(heart_rate_control_point_path_)); - // Set up notifications for heart rate measurement. - // TODO(armansito): Do this based on the value of the "client characteristic - // configuration" descriptor. Since it's still unclear how descriptors will - // be handled by BlueZ, automatically set up notifications for now. - ScheduleHeartRateMeasurementValueChange(); - // Expose CCC descriptor for Heart Rate Measurement characteristic. FakeBluetoothGattDescriptorClient* descriptor_client = static_cast<FakeBluetoothGattDescriptorClient*>( @@ -315,6 +366,11 @@ void FakeBluetoothGattCharacteristicClient:: ScheduleHeartRateMeasurementValueChange() { if (!IsHeartRateVisible()) return; + + // Don't send updates if the characteristic is not notifying. + if (!heart_rate_measurement_properties_->notifying.value()) + return; + VLOG(2) << "Updating heart rate value."; std::vector<uint8> measurement = GetHeartRateMeasurementValue(); |