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

Unified Diff: device/bluetooth/dbus/bluetooth_gatt_characteristic_service_provider_impl.cc

Issue 1974633002: Implement DBus changes needed for notifications. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
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 side-by-side diff with in-line comments
Download patch
Index: device/bluetooth/dbus/bluetooth_gatt_characteristic_service_provider_impl.cc
diff --git a/device/bluetooth/dbus/bluetooth_gatt_characteristic_service_provider_impl.cc b/device/bluetooth/dbus/bluetooth_gatt_characteristic_service_provider_impl.cc
index d7acdb41c5bf41584d11328d52023ed00e5c12c9..97f36fac5ae395ac10fe6d3001f2bbf37c5588bb 100644
--- a/device/bluetooth/dbus/bluetooth_gatt_characteristic_service_provider_impl.cc
+++ b/device/bluetooth/dbus/bluetooth_gatt_characteristic_service_provider_impl.cc
@@ -40,9 +40,6 @@ BluetoothGattCharacteristicServiceProviderImpl::
weak_ptr_factory_(this) {
VLOG(1) << "Created Bluetooth GATT characteristic: " << object_path.value()
<< " UUID: " << uuid;
-
- // If we have a null bus, this means that this is being initialized for a
- // test, hence we shouldn't do any other setup.
if (!bus_)
return;
@@ -90,6 +87,20 @@ BluetoothGattCharacteristicServiceProviderImpl::
weak_ptr_factory_.GetWeakPtr()),
base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnExported,
weak_ptr_factory_.GetWeakPtr()));
+ exported_object_->ExportMethod(
+ bluetooth_gatt_characteristic::kBluetoothGattCharacteristicInterface,
+ bluetooth_gatt_characteristic::kStartNotify,
+ base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::StartNotify,
+ weak_ptr_factory_.GetWeakPtr()),
+ base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnExported,
+ weak_ptr_factory_.GetWeakPtr()));
+ exported_object_->ExportMethod(
+ bluetooth_gatt_characteristic::kBluetoothGattCharacteristicInterface,
+ bluetooth_gatt_characteristic::kStopNotify,
+ base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::StopNotify,
+ weak_ptr_factory_.GetWeakPtr()),
+ base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnExported,
+ weak_ptr_factory_.GetWeakPtr()));
}
BluetoothGattCharacteristicServiceProviderImpl::
@@ -102,6 +113,10 @@ BluetoothGattCharacteristicServiceProviderImpl::
void BluetoothGattCharacteristicServiceProviderImpl::SendValueChanged(
const std::vector<uint8_t>& value) {
+ // Running a test, don't actually try to write to use DBus.
+ if (!bus_)
+ return;
+
VLOG(2) << "Emitting a PropertiesChanged signal for characteristic value.";
dbus::Signal signal(dbus::kDBusPropertiesInterface,
dbus::kDBusPropertiesChangedSignal);
@@ -359,6 +374,46 @@ void BluetoothGattCharacteristicServiceProviderImpl::WriteValue(
weak_ptr_factory_.GetWeakPtr(), method_call, response_sender));
}
+void BluetoothGattCharacteristicServiceProviderImpl::StartNotify(
xiyuan 2016/05/12 18:33:18 Silly question: Why StartNotify do delegate_->GetV
rkc 2016/05/12 19:51:50 Ugh, this is really stupid of me. I apologize! Thi
+ dbus::MethodCall* method_call,
+ dbus::ExportedObject::ResponseSender response_sender) {
+ VLOG(3) << "BluetoothGattCharacteristicServiceProvider::StartNotify: "
+ << object_path_.value();
+ DCHECK(OnOriginThread());
+ DCHECK(delegate_);
+ delegate_->GetValue(
+ base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnReadValue,
+ weak_ptr_factory_.GetWeakPtr(), method_call, response_sender),
+ base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnFailure,
+ weak_ptr_factory_.GetWeakPtr(), method_call, response_sender));
+}
+
+void BluetoothGattCharacteristicServiceProviderImpl::StopNotify(
+ dbus::MethodCall* method_call,
+ dbus::ExportedObject::ResponseSender response_sender) {
+ VLOG(3) << "BluetoothGattCharacteristicServiceProvider::WriteValue: "
xiyuan 2016/05/12 18:33:18 nit: update the message, WriteValue -> StopNotify?
rkc 2016/05/12 19:51:50 Done.
+ << object_path_.value();
+ DCHECK(OnOriginThread());
+
+ dbus::MessageReader reader(method_call);
+ const uint8_t* bytes = NULL;
+ size_t length = 0;
+
+ if (!reader.PopArrayOfBytes(&bytes, &length))
+ VLOG(2) << "Error reading array of bytes in in WriteValue";
xiyuan 2016/05/12 18:33:18 nit: update the message
rkc 2016/05/12 19:51:50 Done.
+ std::vector<uint8_t> value;
+ if (bytes)
+ value.assign(bytes, bytes + length);
+
+ DCHECK(delegate_);
+ delegate_->SetValue(
+ value,
+ base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnWriteValue,
+ weak_ptr_factory_.GetWeakPtr(), method_call, response_sender),
+ base::Bind(&BluetoothGattCharacteristicServiceProviderImpl::OnFailure,
+ weak_ptr_factory_.GetWeakPtr(), method_call, response_sender));
+}
+
void BluetoothGattCharacteristicServiceProviderImpl::OnExported(
const std::string& interface_name,
const std::string& method_name,

Powered by Google App Engine
This is Rietveld 408576698