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 <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 dceeac4..ca77ae1 100644
--- a/tools/sdbusplus/templates/interface.mako.server.cpp
+++ b/tools/sdbusplus/templates/interface.mako.server.cpp
@@ -27,6 +27,18 @@
 {
 }
 
+    % if interface.properties:
+${classname}::${classname}(bus::bus& bus, const char* path,
+                           const std::map<std::string, PropertiesVariant>& 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 @@
         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<std::string, PropertiesVariant>& vals);
+
     % endif
     % for m in interface.methods:
 ${ m.cpp_prototype(loader, interface=interface, ptype='header') }