utility: Add Get All Properties

Add a utility function to call the D-Bus GetAll method. This will be
used to get the values of all the properties from the Supported
Configuration interface from Entity Manager. Start with the variant
values for the properties in the Supported Configuration interface which
are uint64_t (count), string (type), and array of strings (models).

Make the service parameter optional since the caller may already have
the service name from another D-Bus call like getSubTree, or the caller
may decide to call getService() before the getAll function if they are
going to call getAll multiple times and the service name can be reused.
If the service name is not passed, the new getAll will call getService().

Tested: Verified that calling the new function worked as expected
        calling it with and without a service name.

Change-Id: I4d679f0e5d28248d38050b6aed44d4ea86b83c59
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
diff --git a/utility.cpp b/utility.cpp
index cec9d8b..ee65cff 100644
--- a/utility.cpp
+++ b/utility.cpp
@@ -63,6 +63,31 @@
     return response.begin()->first;
 }
 
+DbusPropertyMap getAllProperties(sdbusplus::bus::bus& bus,
+                                 const std::string& path,
+                                 const std::string& interface,
+                                 const std::string& service)
+{
+    DbusPropertyMap properties;
+
+    auto serviceStr = service;
+    if (serviceStr.empty())
+    {
+        serviceStr = getService(path, interface, bus);
+        if (serviceStr.empty())
+        {
+            return properties;
+        }
+    }
+
+    auto method = bus.new_method_call(serviceStr.c_str(), path.c_str(),
+                                      PROPERTY_INTF, "GetAll");
+    method.append(interface);
+    auto reply = bus.call(method);
+    reply.read(properties);
+    return properties;
+}
+
 DbusSubtree getSubTree(sdbusplus::bus::bus& bus, const std::string& path,
                        const std::string& interface, int32_t depth)
 {
diff --git a/utility.hpp b/utility.hpp
index 019173b..51fe31d 100644
--- a/utility.hpp
+++ b/utility.hpp
@@ -23,11 +23,15 @@
 constexpr auto PROPERTY_INTF = "org.freedesktop.DBus.Properties";
 
 using DbusPath = std::string;
+using DbusProperty = std::string;
 using DbusService = std::string;
 using DbusInterface = std::string;
 using DbusInterfaceList = std::vector<DbusInterface>;
 using DbusSubtree =
     std::map<DbusPath, std::map<DbusService, DbusInterfaceList>>;
+using DbusVariant =
+    std::variant<uint64_t, std::string, std::vector<std::string>>;
+using DbusPropertyMap = std::map<DbusProperty, DbusVariant>;
 /**
  * @brief Get the service name from the mapper for the
  *        interface and path passed in.
@@ -95,6 +99,21 @@
     auto reply = bus.call(method);
 }
 
+/**
+ * @brief Get all D-Bus properties
+ *
+ * @param[in] bus - the D-Bus object
+ * @param[in] path - the D-Bus object path
+ * @param[in] interface - the D-Bus interface name
+ * @param[in] service - the D-Bus service name (optional)
+ *
+ * @return DbusPropertyMap - Map of property names and values
+ */
+DbusPropertyMap getAllProperties(sdbusplus::bus::bus& bus,
+                                 const std::string& path,
+                                 const std::string& interface,
+                                 const std::string& service = std::string());
+
 /** @brief Get subtree from the object mapper.
  *
  * Helper function to find objects, services, and interfaces.