sdbus++: Add server method for get-property
Add a method to the server bindings that gets properties
by looking up the name from a string.
Change-Id: I304504ba20d6747afba27cd08f79bcc564c34a46
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
diff --git a/tools/sdbusplus/templates/interface.mako.server.cpp b/tools/sdbusplus/templates/interface.mako.server.cpp
index ca77ae1..14dfa01 100644
--- a/tools/sdbusplus/templates/interface.mako.server.cpp
+++ b/tools/sdbusplus/templates/interface.mako.server.cpp
@@ -160,6 +160,19 @@
% endfor
}
+auto ${classname}::getPropertyByName(const std::string& name) ->
+ PropertiesVariant
+{
+ % for p in interface.properties:
+ if (name == "${p.name}")
+ {
+ return ${p.camelCase}();
+ }
+ % endfor
+
+ return PropertiesVariant();
+}
+
% endif
% for e in interface.enums:
diff --git a/tools/sdbusplus/templates/interface.mako.server.hpp b/tools/sdbusplus/templates/interface.mako.server.hpp
index ca45c66..c67f9b7 100644
--- a/tools/sdbusplus/templates/interface.mako.server.hpp
+++ b/tools/sdbusplus/templates/interface.mako.server.hpp
@@ -92,6 +92,12 @@
void setPropertyByName(const std::string& name,
const PropertiesVariant& val);
+ /** @brief Gets a property by name.
+ * @param[in] name - A string representation of the property name.
+ * @return - A variant containing the value of the property.
+ */
+ PropertiesVariant getPropertyByName(const std::string& name);
+
% endif
% for e in interface.enums:
/** @brief Convert a string to an appropriate enum value.