summaryrefslogtreecommitdiff
path: root/chromeos-dbus-bindings
diff options
context:
space:
mode:
authorAlex Vakulenko <avakulenko@chromium.org>2014-12-04 08:28:49 -0800
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-12-05 01:09:41 +0000
commitc4e32f54a834739eefbf4b651bb9692bd58da043 (patch)
tree7b7df9ef9a88dcccdfc1c7cb2cfac5e1d7ef79f5 /chromeos-dbus-bindings
parent824b5246a3ab5c70d32938ed9c3b982f5624dfe9 (diff)
downloaddbus-binding-generator-c4e32f54a834739eefbf4b651bb9692bd58da043.tar.gz
chromeos-dbus-bindings: Add asynchronous method proxies and timeouts
Added async versions of proxy methods and also optional timeout parameter when calling D-Bus methods. If the timeout is not specified, a D-Bus default value is used. BUG=chromium:431736 TEST=FEATURES=test emerge-link chromeos-dbus-bindings Change-Id: I3104d8b3c54809c352e361b199d37a4206bb58dc Reviewed-on: https://chromium-review.googlesource.com/233180 Tested-by: Alex Vakulenko <avakulenko@chromium.org> Reviewed-by: Vitaly Buka <vitalybuka@chromium.org> Commit-Queue: Alex Vakulenko <avakulenko@chromium.org>
Diffstat (limited to 'chromeos-dbus-bindings')
-rw-r--r--chromeos-dbus-bindings/proxy_generator.cc68
-rw-r--r--chromeos-dbus-bindings/proxy_generator.h5
-rw-r--r--chromeos-dbus-bindings/proxy_generator_unittest.cc103
3 files changed, 164 insertions, 12 deletions
diff --git a/chromeos-dbus-bindings/proxy_generator.cc b/chromeos-dbus-bindings/proxy_generator.cc
index a379bca..66f39ea 100644
--- a/chromeos-dbus-bindings/proxy_generator.cc
+++ b/chromeos-dbus-bindings/proxy_generator.cc
@@ -122,6 +122,7 @@ void ProxyGenerator::GenerateInterfaceProxy(const ServiceConfig& config,
AddPropertyPublicMethods(proxy_name, text);
for (const auto& method : interface.methods) {
AddMethodProxy(method, interface.name, text);
+ AddAsyncMethodProxy(method, interface.name, text);
}
AddProperties(config, interface, text);
@@ -440,12 +441,15 @@ void ProxyGenerator::AddMethodProxy(const Interface::Method& method,
block.AddLine(StringPrintf(
"%s* %s,", argument_type.c_str(), argument_name.c_str()));
}
- block.AddLine("chromeos::ErrorPtr* error) {");
+ block.AddLine("chromeos::ErrorPtr* error,");
+ block.AddLine("int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT) {");
block.PopOffset();
block.PushOffset(kBlockOffset);
- block.AddLine("auto response = chromeos::dbus_utils::CallMethodAndBlock(");
+ block.AddLine(
+ "auto response = chromeos::dbus_utils::CallMethodAndBlockWithTimeout(");
block.PushOffset(kLineContinuationOffset);
+ block.AddLine("timeout_ms,");
block.AddLine("dbus_object_proxy_,");
block.AddLine(StringPrintf("\"%s\",", interface_name.c_str()));
block.AddLine(StringPrintf("\"%s\",", method.name.c_str()));
@@ -470,6 +474,66 @@ void ProxyGenerator::AddMethodProxy(const Interface::Method& method,
}
// static
+void ProxyGenerator::AddAsyncMethodProxy(const Interface::Method& method,
+ const string& interface_name,
+ IndentedText* text) {
+ IndentedText block;
+ DbusSignature signature;
+ block.AddComments(method.doc_string);
+ block.AddLine(StringPrintf("void %sAsync(", method.name.c_str()));
+ block.PushOffset(kLineContinuationOffset);
+ vector<string> argument_names;
+ int argument_number = 0;
+ for (const auto& argument : method.input_arguments) {
+ string argument_type;
+ CHECK(signature.Parse(argument.type, &argument_type));
+ MakeConstReferenceIfNeeded(&argument_type);
+ string argument_name = GetArgName("in", argument.name, ++argument_number);
+ argument_names.push_back(argument_name);
+ block.AddLine(StringPrintf(
+ "%s %s,", argument_type.c_str(), argument_name.c_str()));
+ }
+ vector<string> out_params;
+ for (const auto& argument : method.output_arguments) {
+ string argument_type;
+ CHECK(signature.Parse(argument.type, &argument_type));
+ MakeConstReferenceIfNeeded(&argument_type);
+ if (!argument.name.empty())
+ base::StringAppendF(&argument_type, " /*%s*/", argument.name.c_str());
+ out_params.push_back(argument_type);
+ }
+ block.AddLine(StringPrintf(
+ "const base::Callback<void(%s)>& success_callback,",
+ chromeos::string_utils::Join(", ", out_params).c_str()));
+ block.AddLine(
+ "const base::Callback<void(chromeos::Error*)>& error_callback,");
+ block.AddLine("int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT) {");
+ block.PopOffset();
+ block.PushOffset(kBlockOffset);
+
+ block.AddLine("chromeos::dbus_utils::CallMethodWithTimeout(");
+ block.PushOffset(kLineContinuationOffset);
+ block.AddLine("timeout_ms,");
+ block.AddLine("dbus_object_proxy_,");
+ block.AddLine(StringPrintf("\"%s\",", interface_name.c_str()));
+ block.AddLine(StringPrintf("\"%s\",", method.name.c_str()));
+ block.AddLine("success_callback,");
+ string last_argument = "error_callback";
+ for (const auto& argument_name : argument_names) {
+ block.AddLine(StringPrintf("%s,", last_argument.c_str()));
+ last_argument = argument_name;
+ }
+ block.AddLine(StringPrintf("%s);", last_argument.c_str()));
+ block.PopOffset();
+
+ block.PopOffset();
+ block.AddLine("}");
+ block.AddBlankLine();
+
+ text->AddBlock(block);
+}
+
+// static
void ProxyGenerator::ObjectManager::GenerateProxy(
const ServiceConfig& config,
const std::vector<Interface>& interfaces,
diff --git a/chromeos-dbus-bindings/proxy_generator.h b/chromeos-dbus-bindings/proxy_generator.h
index f561714..8fd46a4 100644
--- a/chromeos-dbus-bindings/proxy_generator.h
+++ b/chromeos-dbus-bindings/proxy_generator.h
@@ -83,6 +83,11 @@ class ProxyGenerator : public HeaderGenerator {
const std::string& interface_name,
IndentedText* text);
+ // Generates a native C++ method which calls a D-Bus method asynchronously.
+ static void AddAsyncMethodProxy(const Interface::Method& interface,
+ const std::string& interface_name,
+ IndentedText* text);
+
// Generates the Object Manager proxy class.
struct ObjectManager {
// Generates the top-level class for Object Manager proxy.
diff --git a/chromeos-dbus-bindings/proxy_generator_unittest.cc b/chromeos-dbus-bindings/proxy_generator_unittest.cc
index 9afc9ab..2d26a2b 100644
--- a/chromeos-dbus-bindings/proxy_generator_unittest.cc
+++ b/chromeos-dbus-bindings/proxy_generator_unittest.cc
@@ -121,8 +121,10 @@ class TestInterfaceProxy final {
const std::string& in_space_walk,
const std::vector<dbus::ObjectPath>& in_ramblin_man,
std::string* out_3,
- chromeos::ErrorPtr* error) {
- auto response = chromeos::dbus_utils::CallMethodAndBlock(
+ chromeos::ErrorPtr* error,
+ int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT) {
+ auto response = chromeos::dbus_utils::CallMethodAndBlockWithTimeout(
+ timeout_ms,
dbus_object_proxy_,
"org.chromium.TestInterface",
"Elements",
@@ -133,10 +135,29 @@ class TestInterfaceProxy final {
response.get(), error, out_3);
}
+ void ElementsAsync(
+ const std::string& in_space_walk,
+ const std::vector<dbus::ObjectPath>& in_ramblin_man,
+ const base::Callback<void(const std::string&)>& success_callback,
+ const base::Callback<void(chromeos::Error*)>& error_callback,
+ int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT) {
+ chromeos::dbus_utils::CallMethodWithTimeout(
+ timeout_ms,
+ dbus_object_proxy_,
+ "org.chromium.TestInterface",
+ "Elements",
+ success_callback,
+ error_callback,
+ in_space_walk,
+ in_ramblin_man);
+ }
+
bool ReturnToPatagonia(
int64_t* out_1,
- chromeos::ErrorPtr* error) {
- auto response = chromeos::dbus_utils::CallMethodAndBlock(
+ chromeos::ErrorPtr* error,
+ int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT) {
+ auto response = chromeos::dbus_utils::CallMethodAndBlockWithTimeout(
+ timeout_ms,
dbus_object_proxy_,
"org.chromium.TestInterface",
"ReturnToPatagonia",
@@ -145,10 +166,25 @@ class TestInterfaceProxy final {
response.get(), error, out_1);
}
+ void ReturnToPatagoniaAsync(
+ const base::Callback<void(int64_t)>& success_callback,
+ const base::Callback<void(chromeos::Error*)>& error_callback,
+ int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT) {
+ chromeos::dbus_utils::CallMethodWithTimeout(
+ timeout_ms,
+ dbus_object_proxy_,
+ "org.chromium.TestInterface",
+ "ReturnToPatagonia",
+ success_callback,
+ error_callback);
+ }
+
bool NiceWeatherForDucks(
bool in_1,
- chromeos::ErrorPtr* error) {
- auto response = chromeos::dbus_utils::CallMethodAndBlock(
+ chromeos::ErrorPtr* error,
+ int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT) {
+ auto response = chromeos::dbus_utils::CallMethodAndBlockWithTimeout(
+ timeout_ms,
dbus_object_proxy_,
"org.chromium.TestInterface",
"NiceWeatherForDucks",
@@ -158,11 +194,28 @@ class TestInterfaceProxy final {
response.get(), error);
}
+ void NiceWeatherForDucksAsync(
+ bool in_1,
+ const base::Callback<void()>& success_callback,
+ const base::Callback<void(chromeos::Error*)>& error_callback,
+ int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT) {
+ chromeos::dbus_utils::CallMethodWithTimeout(
+ timeout_ms,
+ dbus_object_proxy_,
+ "org.chromium.TestInterface",
+ "NiceWeatherForDucks",
+ success_callback,
+ error_callback,
+ in_1);
+ }
+
// Comment line1
// line2
bool ExperimentNumberSix(
- chromeos::ErrorPtr* error) {
- auto response = chromeos::dbus_utils::CallMethodAndBlock(
+ chromeos::ErrorPtr* error,
+ int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT) {
+ auto response = chromeos::dbus_utils::CallMethodAndBlockWithTimeout(
+ timeout_ms,
dbus_object_proxy_,
"org.chromium.TestInterface",
"ExperimentNumberSix",
@@ -171,6 +224,21 @@ class TestInterfaceProxy final {
response.get(), error);
}
+ // Comment line1
+ // line2
+ void ExperimentNumberSixAsync(
+ const base::Callback<void()>& success_callback,
+ const base::Callback<void(chromeos::Error*)>& error_callback,
+ int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT) {
+ chromeos::dbus_utils::CallMethodWithTimeout(
+ timeout_ms,
+ dbus_object_proxy_,
+ "org.chromium.TestInterface",
+ "ExperimentNumberSix",
+ success_callback,
+ error_callback);
+ }
+
private:
scoped_refptr<dbus::Bus> bus_;
std::string service_name_;
@@ -216,8 +284,10 @@ class TestInterface2Proxy final {
bool GetPersonInfo(
std::string* out_name,
int32_t* out_age,
- chromeos::ErrorPtr* error) {
- auto response = chromeos::dbus_utils::CallMethodAndBlock(
+ chromeos::ErrorPtr* error,
+ int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT) {
+ auto response = chromeos::dbus_utils::CallMethodAndBlockWithTimeout(
+ timeout_ms,
dbus_object_proxy_,
"org.chromium.TestInterface2",
"GetPersonInfo",
@@ -226,6 +296,19 @@ class TestInterface2Proxy final {
response.get(), error, out_name, out_age);
}
+ void GetPersonInfoAsync(
+ const base::Callback<void(const std::string& /*name*/, int32_t /*age*/)>& success_callback,
+ const base::Callback<void(chromeos::Error*)>& error_callback,
+ int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT) {
+ chromeos::dbus_utils::CallMethodWithTimeout(
+ timeout_ms,
+ dbus_object_proxy_,
+ "org.chromium.TestInterface2",
+ "GetPersonInfo",
+ success_callback,
+ error_callback);
+ }
+
private:
scoped_refptr<dbus::Bus> bus_;
std::string service_name_;