Chromium Code Reviews| 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, |