From 4d47bf0aaa864c3ca9af9ea8016b53cc1b2b7c6c Mon Sep 17 00:00:00 2001 From: Patrick Williams Date: Wed, 1 Feb 2017 23:16:23 -0600 Subject: sdbus++: Add server constructor from property-map Add a constructor that takes a map of property-names to values and initializes all properties in the map with those values. Change-Id: Id0eaa2ec43aed490719d12537e75c1278d290013 Signed-off-by: Patrick Williams Signed-off-by: Brad Bishop --- tools/sdbusplus/templates/interface.mako.server.cpp | 12 ++++++++++++ tools/sdbusplus/templates/interface.mako.server.hpp | 10 ++++++++++ 2 files changed, 22 insertions(+) diff --git a/tools/sdbusplus/templates/interface.mako.server.cpp b/tools/sdbusplus/templates/interface.mako.server.cpp index dceeac4..ca77ae1 100644 --- a/tools/sdbusplus/templates/interface.mako.server.cpp +++ b/tools/sdbusplus/templates/interface.mako.server.cpp @@ -27,6 +27,18 @@ ${classname}::${classname}(bus::bus& bus, const char* path) { } + % if interface.properties: +${classname}::${classname}(bus::bus& bus, const char* path, + const std::map& vals) + : ${classname}(bus, path) +{ + for (const auto& v : vals) + { + setPropertyByName(v.first, v.second); + } +} + + % endif % for m in interface.methods: ${ m.cpp_prototype(loader, interface=interface, ptype='callback-cpp') } % endfor diff --git a/tools/sdbusplus/templates/interface.mako.server.hpp b/tools/sdbusplus/templates/interface.mako.server.hpp index 440fcce..ca45c66 100644 --- a/tools/sdbusplus/templates/interface.mako.server.hpp +++ b/tools/sdbusplus/templates/interface.mako.server.hpp @@ -57,6 +57,16 @@ class ${classname} using PropertiesVariant = sdbusplus::message::variant< ${",\n ".join(setOfPropertyTypes())}>; + /** @brief Constructor to initialize the object from a map of + * properties. + * + * @param[in] bus - Bus to attach to. + * @param[in] path - Path to attach at. + * @param[in] vals - Map of property name to value for initalization. + */ + ${classname}(bus::bus& bus, const char* path, + const std::map& vals); + % endif % for m in interface.methods: ${ m.cpp_prototype(loader, interface=interface, ptype='header') } -- cgit v1.2.3