diff options
| author | Patrick Williams <patrick@stwcx.xyz> | 2017-02-01 23:06:33 -0600 |
|---|---|---|
| committer | Brad Bishop <bradleyb@us.ibm.com> | 2017-02-03 00:24:10 -0500 |
| commit | 9fa855206cb1932951b3031a7d1b3c057df6296b (patch) | |
| tree | 344c36c3d22e654e6412f8168d00c949ef861205 /tools | |
| parent | a1fb5e6c3951eb8ad00795ba9471d968e53faad2 (diff) | |
| download | sdbusplus-9fa855206cb1932951b3031a7d1b3c057df6296b.tar.gz sdbusplus-9fa855206cb1932951b3031a7d1b3c057df6296b.zip | |
sdbus++: add server method for set-property
Add a method to the server bindings that sets properties
by looking up the name from a string.
Change-Id: I7e9081b66dfeffd394155a574c2178a7cd039e2a
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/sdbusplus/templates/interface.mako.server.cpp | 16 | ||||
| -rw-r--r-- | tools/sdbusplus/templates/interface.mako.server.hpp | 18 |
2 files changed, 34 insertions, 0 deletions
diff --git a/tools/sdbusplus/templates/interface.mako.server.cpp b/tools/sdbusplus/templates/interface.mako.server.cpp index aec8cfb..dceeac4 100644 --- a/tools/sdbusplus/templates/interface.mako.server.cpp +++ b/tools/sdbusplus/templates/interface.mako.server.cpp @@ -133,6 +133,22 @@ static const auto _property_${p.name} = } % endfor + % if interface.properties: +void ${classname}::setPropertyByName(const std::string& name, + const PropertiesVariant& val) +{ + % for p in interface.properties: + if (name == "${p.name}") + { + auto& v = message::variant_ns::get<${p.cppTypeParam(interface.name)}>(\ +val); + ${p.camelCase}(v); + return; + } + % endfor +} + + % endif % for e in interface.enums: namespace diff --git a/tools/sdbusplus/templates/interface.mako.server.hpp b/tools/sdbusplus/templates/interface.mako.server.hpp index 1879fd8..440fcce 100644 --- a/tools/sdbusplus/templates/interface.mako.server.hpp +++ b/tools/sdbusplus/templates/interface.mako.server.hpp @@ -5,6 +5,10 @@ <% namespaces = interface.name.split('.') classname = namespaces.pop() + + def setOfPropertyTypes(): + return set(p.cppTypeParam(interface.name) for p in + interface.properties); %> namespace sdbusplus { @@ -49,6 +53,11 @@ class ${classname} }; % endfor + % if interface.properties: + using PropertiesVariant = sdbusplus::message::variant< + ${",\n ".join(setOfPropertyTypes())}>; + + % endif % for m in interface.methods: ${ m.cpp_prototype(loader, interface=interface, ptype='header') } % endfor @@ -65,6 +74,15 @@ ${ s.cpp_prototype(loader, interface=interface, ptype='header') } ${p.camelCase}(${p.cppTypeParam(interface.name)} value); % endfor + % if interface.properties: + /** @brief Sets a property by name. + * @param[in] name - A string representation of the property name. + * @param[in] val - A variant containing the value to set. + */ + void setPropertyByName(const std::string& name, + const PropertiesVariant& val); + + % endif % for e in interface.enums: /** @brief Convert a string to an appropriate enum value. * @param[in] s - The string to convert in the form of |

