libchrome: UPSTREAM: add support for synchronous PropertySet::Set to dbus
Upstram cl: https://codereview.chromium.org/1361503003/
The existing PropertySet::Set function is asynchronous.
This CL adds the synchronous version of PropertySet::Set.
It is defined as PropertySet::SetAndBlock.
Bug: 24131409
TEST=run tests on a veyron_jaq chromebook
Change-Id: Idceebeaf05e7480371286ebfa0c72222298f1d46
diff --git a/dbus/property.cc b/dbus/property.cc
index dde0611..b7a0c8b 100644
--- a/dbus/property.cc
+++ b/dbus/property.cc
@@ -174,6 +174,22 @@
callback));
}
+bool PropertySet::SetAndBlock(PropertyBase* property) {
+ MethodCall method_call(kPropertiesInterface, kPropertiesSet);
+ MessageWriter writer(&method_call);
+ writer.AppendString(interface());
+ writer.AppendString(property->name());
+ property->AppendSetValueToWriter(&writer);
+
+ DCHECK(object_proxy_);
+ scoped_ptr<dbus::Response> response(
+ object_proxy_->CallMethodAndBlock(&method_call,
+ ObjectProxy::TIMEOUT_USE_DEFAULT));
+ if (response.get())
+ return true;
+ return false;
+}
+
void PropertySet::OnSet(PropertyBase* property,
SetCallback callback,
Response* response) {
diff --git a/dbus/property.h b/dbus/property.h
index 5f36d69..f03f027 100644
--- a/dbus/property.h
+++ b/dbus/property.h
@@ -276,6 +276,10 @@
// depending on the remote object. This method may be overridden by
// sub-classes if interfaces use different method calls.
virtual void Set(PropertyBase* property, SetCallback callback);
+
+ // The sychronous version of Set().
+ virtual bool SetAndBlock(PropertyBase* property);
+
virtual void OnSet(PropertyBase* property, SetCallback callback,
Response* response);
@@ -389,6 +393,12 @@
property_set()->Set(this, callback);
}
+ // The sychronous version of Set().
+ virtual bool SetAndBlock(const T& value) {
+ set_value_ = value;
+ return property_set()->SetAndBlock(this);
+ }
+
// Method used by PropertySet to retrieve the value from a MessageReader,
// no knowledge of the contained type is required, this method returns
// true if its expected type was found, false if not.