sdbus++: remove `PropertiesVariant` for empty properties
A previous commit changed behavior to always add `PropertiesVariant`
even when there were no properties (and to use `variant<monostate>`).
The missing `PropertiesVariant` was used by some other repositories to
detect if an interface had properties or not. Adding an empty
`PropertiesVariant` breaks this expectation.
Switch back to having no type defined when there are no properties.
Also, move the new `properties_t` over to the common template for
consistency with the `PropertiesVariant` definition and for potential
use elsewhere.
Fixes: 8aea1d814330 ("sdbus++: generate `properties` method for client harness")
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I75b36412fe42eb44d5a638c6a8ad7a3ee9b835e3
diff --git a/tools/sdbusplus/templates/interface.client.hpp.mako b/tools/sdbusplus/templates/interface.client.hpp.mako
index cbc89d2..4943562 100644
--- a/tools/sdbusplus/templates/interface.client.hpp.mako
+++ b/tools/sdbusplus/templates/interface.client.hpp.mako
@@ -49,13 +49,6 @@
private sdbusplus::async::client::details::client_context_friend
{
public:
- struct properties_t
- {
- % for p in interface.properties:
- ${p.cppTypeParam(interface.name)} ${p.snake_case}${p.default_value(interface.name)};
- % endfor
- };
-
friend Client;
template <typename, typename>
friend struct sdbusplus::client::${interface.cppNamespacedClass()};
@@ -71,6 +64,7 @@
${p.render(loader, "property.client.hpp.mako", property=p, interface=interface)}
% endfor
+ % if interface.properties:
auto properties()
{
return proxy.template get_all_properties<PropertiesVariant>(context()) |
@@ -104,6 +98,7 @@
return result;
});
}
+ % endif
private:
// Conversion constructor from proxy used by client_t.
diff --git a/tools/sdbusplus/templates/interface.common.hpp.mako b/tools/sdbusplus/templates/interface.common.hpp.mako
index a26f404..0c14038 100644
--- a/tools/sdbusplus/templates/interface.common.hpp.mako
+++ b/tools/sdbusplus/templates/interface.common.hpp.mako
@@ -32,10 +32,15 @@
% endfor
% if interface.properties:
+ struct properties_t
+ {
+ % for p in interface.properties:
+ ${p.cppTypeParam(interface.name)} ${p.snake_case}${p.default_value(interface.name)};
+ % endfor
+ };
+
using PropertiesVariant = sdbusplus::utility::dedup_variant_t<
${",\n ".join(sorted(setOfPropertyTypes()))}>;
- % else:
- using PropertiesVariant = std::variant<std::monostate>;
% endif \
% for p in interface.paths: