sdbus++: async: server: make properties protected
When the implementation wants to override the property set/get
methods, they likely want to access the underlying storage. Move
them to be protected rather than private so they can be modified.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: Ib7e752e1fa6e0f358f6e663aa51c2cf0c93118b7
diff --git a/example/calculator-aserver.cpp b/example/calculator-aserver.cpp
index 290e0aa..149da86 100644
--- a/example/calculator-aserver.cpp
+++ b/example/calculator-aserver.cpp
@@ -15,17 +15,23 @@
auto get_property(last_result_t) const
{
- return 42;
+ return _last_result;
}
- bool set_property(last_result_t, auto)
+ bool set_property(last_result_t, int64_t v)
{
+ if (v % 2 == 0)
+ {
+ std::swap(_last_result, v);
+ return v != _last_result;
+ }
return false;
}
private:
auto startup() -> sdbusplus::async::task<>
{
+ last_result(123);
ctx.get_bus().request_name("net.poettering.Calculator");
status(State::Error);
diff --git a/tools/sdbusplus/templates/interface.aserver.hpp.mako b/tools/sdbusplus/templates/interface.aserver.hpp.mako
index 2f1189e..f94ba3b 100644
--- a/tools/sdbusplus/templates/interface.aserver.hpp.mako
+++ b/tools/sdbusplus/templates/interface.aserver.hpp.mako
@@ -80,6 +80,11 @@
${p.render(loader, "property.aserver.set.hpp.mako", property=p, interface=interface)}
% endfor
+ protected:
+% for p in interface.properties:
+${p.render(loader, "property.aserver.value.hpp.mako", property=p, interface=interface)}\
+% endfor
+
private:
/** @return the async context */
sdbusplus::async::context& _context()
@@ -91,10 +96,6 @@
_${interface.joinedName("_", "interface")};
% for p in interface.properties:
-${p.render(loader, "property.aserver.value.hpp.mako", property=p, interface=interface)}\
-% endfor
-
-% for p in interface.properties:
${p.render(loader, "property.aserver.typeid.hpp.mako", property=p, interface=interface)}\
% endfor
% for s in interface.signals: