chromeos-dbus-bindings: Add support for STRUCT and typed async methods
The async method handlers in libchromeos have been changed to use
strongly typed response objects. This change mainly changes the
adapter generator to produce the correct signatures for the async
adapter methods.
In the attempt to support existing XML files from shill and
modemmanager I implemented some features that are required there:
1. Allow nested <node> elements (which are still ignored but at
least parsing of XML files doesn't fail.
2. Add support for <tp:docstring> element to extract comments
from interface/method/signal/property definitions and add
then to adaptor/proxy code which should help user to make
sense of method intentions.
3. Added support for STRUCT D-Bus types (...). Now using
std::tuple<> to represent D-Bus structures.
4. a{sv} are converted to chromeos::VariantDictionary instead of
std::map<std::string, chromeos::Any> which is shorter and
being very popular type in D-Bus, makes a few generated
function signatures neater.
5. Added support for "org.freedesktop.DBus.GLib.Async" annotation
to be an alias for "org.chromium.DBus.Method.Kind"="async".
6. Fixed chromeos::string_utils::Split() to eliminate empty
strings if they were created by trimming all-whitespace
elements of the split array.
BUG=None
TEST=FEATURES=test emerge-link chromeos-dbus-bindings
Change-Id: I73cf13819128ca5fca9e9188d162d120b737cf1f
Reviewed-on: https://chromium-review.googlesource.com/229430
Reviewed-by: Paul Stewart <pstew@chromium.org>
Commit-Queue: Alex Vakulenko <avakulenko@chromium.org>
Tested-by: Alex Vakulenko <avakulenko@chromium.org>
diff --git a/chromeos-dbus-bindings/proxy_generator_unittest.cc b/chromeos-dbus-bindings/proxy_generator_unittest.cc
index 7bb1ab9..6c5e1a6 100644
--- a/chromeos-dbus-bindings/proxy_generator_unittest.cc
+++ b/chromeos-dbus-bindings/proxy_generator_unittest.cc
@@ -57,6 +57,7 @@
#include <chromeos/dbus/dbus_method_invoker.h>
#include <chromeos/dbus/dbus_signal_handler.h>
#include <chromeos/errors/error.h>
+#include <chromeos/variant_dictionary.h>
#include <dbus/bus.h>
#include <dbus/message.h>
#include <dbus/object_path.h>
@@ -65,7 +66,7 @@
namespace org {
namespace chromium {
-class TestInterfaceProxy {
+class TestInterfaceProxy final {
public:
class SignalReceiver {
public:
@@ -74,6 +75,7 @@
const std::vector<std::string>&,
uint8_t) {}
};
+
TestInterfaceProxy(
const scoped_refptr<dbus::Bus>& bus,
const std::string& service_name,
@@ -105,10 +107,12 @@
&TestInterfaceProxy::OnDBusSignalConnected,
base::Unretained(this)));
}
- virtual ~TestInterfaceProxy() {
+
+ ~TestInterfaceProxy() {
dbus_object_proxy_->Detach();
bus_->RemoveObjectProxy(service_name_, object_path_, base::Closure());
}
+
void OnDBusSignalConnected(
const std::string& interface,
const std::string& signal,
@@ -120,7 +124,8 @@
<< object_path_.value();
}
}
- virtual bool Elements(
+
+ bool Elements(
const std::string& in_space_walk,
const std::vector<dbus::ObjectPath>& in_ramblin_man,
std::string* out_3,
@@ -135,7 +140,8 @@
return response && chromeos::dbus_utils::ExtractMethodCallResults(
response.get(), error, out_3);
}
- virtual bool ReturnToPatagonia(
+
+ bool ReturnToPatagonia(
int64_t* out_1,
chromeos::ErrorPtr* error) {
auto response = chromeos::dbus_utils::CallMethodAndBlock(
@@ -146,7 +152,8 @@
return response && chromeos::dbus_utils::ExtractMethodCallResults(
response.get(), error, out_1);
}
- virtual bool NiceWeatherForDucks(
+
+ bool NiceWeatherForDucks(
bool in_1,
chromeos::ErrorPtr* error) {
auto response = chromeos::dbus_utils::CallMethodAndBlock(
@@ -158,7 +165,10 @@
return response && chromeos::dbus_utils::ExtractMethodCallResults(
response.get(), error);
}
- virtual bool ExperimentNumberSix(
+
+ // Comment line1
+ // line2
+ bool ExperimentNumberSix(
chromeos::ErrorPtr* error) {
auto response = chromeos::dbus_utils::CallMethodAndBlock(
dbus_object_proxy_,
@@ -168,7 +178,8 @@
return response && chromeos::dbus_utils::ExtractMethodCallResults(
response.get(), error);
}
- virtual bool GetPersonInfo(
+
+ bool GetPersonInfo(
std::string* out_name,
int32_t* out_age,
chromeos::ErrorPtr* error) {
@@ -238,6 +249,7 @@
vector<Interface::Argument>{
{"", kSignal2Argument1},
{"", kSignal2Argument2}});
+ interface.methods.back().doc_string_ = "Comment line1\nline2";
Interface interface2;
interface2.name = kInterfaceName2;
interface2.methods.emplace_back(