sdbus++: async: client: add generated property calls
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I25ad8c0c167af0a55e235e5a7b4a46a3019d94ae
diff --git a/example/calculator-client.cpp b/example/calculator-client.cpp
index 56e9fb4..0fe8420 100644
--- a/example/calculator-client.cpp
+++ b/example/calculator-client.cpp
@@ -21,7 +21,7 @@
}
{
- auto _ = co_await c.get_property<int64_t>("LastResult");
+ auto _ = co_await c.lastResult();
std::cout << "Should be 42: " << _ << std::endl;
}
@@ -30,13 +30,13 @@
}
{
- auto _ = co_await c.get_property<int64_t>("LastResult");
+ auto _ = co_await c.lastResult();
std::cout << "Should be 0: " << _ << std::endl;
}
{
- co_await c.set_property<int64_t>("LastResult", 1234);
- auto _ = co_await c.get_property<int64_t>("LastResult");
+ co_await c.lastResult(1234);
+ auto _ = co_await c.lastResult();
std::cout << "Should be 1234: " << _ << std::endl;
}
diff --git a/tools/meson.build b/tools/meson.build
index 5890316..6493efb 100644
--- a/tools/meson.build
+++ b/tools/meson.build
@@ -22,6 +22,7 @@
'sdbusplus/templates/method.client.hpp.mako',
'sdbusplus/templates/method.prototype.hpp.mako',
'sdbusplus/templates/property.md.mako',
+ 'sdbusplus/templates/property.client.hpp.mako',
'sdbusplus/templates/property.prototype.hpp.mako',
'sdbusplus/templates/signal.md.mako',
'sdbusplus/templates/signal.prototype.hpp.mako',
diff --git a/tools/sdbusplus/templates/interface.client.hpp.mako b/tools/sdbusplus/templates/interface.client.hpp.mako
index b9d7fae..1d29441 100644
--- a/tools/sdbusplus/templates/interface.client.hpp.mako
+++ b/tools/sdbusplus/templates/interface.client.hpp.mako
@@ -38,22 +38,9 @@
% for m in interface.methods:
${m.render(loader, "method.client.hpp.mako", method=m, interface=interface)}
% endfor
-
- // To be replaced by generators...
- template <typename T>
- auto get_property(auto& property) const
- {
- return proxy.template get_property<T>(ctx, property);
- }
-
- // To be replaced by generators...
- template <typename T>
- auto set_property(auto& property, T&& value) const
- {
- return proxy.template set_property<T>(ctx, property,
- std::forward<T>(value));
- }
-
+ % for p in interface.properties:
+${p.render(loader, "property.client.hpp.mako", property=p, interface=interface)}
+ % endfor
private:
// Conversion constructor from proxy used by client_t.
constexpr ${interface.classname}(sdbusplus::async::context& ctx, Proxy p) :
diff --git a/tools/sdbusplus/templates/property.client.hpp.mako b/tools/sdbusplus/templates/property.client.hpp.mako
new file mode 100644
index 0000000..b218588
--- /dev/null
+++ b/tools/sdbusplus/templates/property.client.hpp.mako
@@ -0,0 +1,18 @@
+ /** Get value of ${property.name}
+ * ${property.description.strip()}
+ */
+ auto ${property.camelCase}()
+ {
+ return proxy.template get_property<\
+${property.cppTypeParam(interface.name)}>(ctx, "${property.name}");
+ }
+
+ /** Set value of ${property.name}
+ * ${property.description.strip()}
+ */
+ auto ${property.camelCase}(auto value)
+ {
+ return proxy.template set_property<\
+${property.cppTypeParam(interface.name)}>(
+ ctx, "${property.name}", std::forward<decltype(value)>(value));
+ }