Add a phosphor::power::util getSubTree helper

Adding a helper function to do the GetSubTree method call on the object
mapper.

Signed-off-by: Brandon Wyman <bjwyman@gmail.com>
Change-Id: Iaac9723d6e1086b873ad6b260daf46a8cfa875c3
diff --git a/utility.cpp b/utility.cpp
index 7fdd6b2..cec9d8b 100644
--- a/utility.cpp
+++ b/utility.cpp
@@ -63,6 +63,22 @@
     return response.begin()->first;
 }
 
+DbusSubtree getSubTree(sdbusplus::bus::bus& bus, const std::string& path,
+                       const std::string& interface, int32_t depth)
+{
+    auto mapperCall = bus.new_method_call(MAPPER_BUSNAME, MAPPER_PATH,
+                                          MAPPER_INTERFACE, "GetSubTree");
+    mapperCall.append(path);
+    mapperCall.append(depth);
+    mapperCall.append(std::vector<std::string>({interface}));
+
+    auto reply = bus.call(mapperCall);
+
+    DbusSubtree response;
+    reply.read(response);
+    return response;
+}
+
 json loadJSONFromFile(const char* path)
 {
     std::ifstream ifs(path);
diff --git a/utility.hpp b/utility.hpp
index df59b92..019173b 100644
--- a/utility.hpp
+++ b/utility.hpp
@@ -22,6 +22,12 @@
 constexpr auto POWEROFF_TARGET = "obmc-chassis-hard-poweroff@0.target";
 constexpr auto PROPERTY_INTF = "org.freedesktop.DBus.Properties";
 
+using DbusPath = std::string;
+using DbusService = std::string;
+using DbusInterface = std::string;
+using DbusInterfaceList = std::vector<DbusInterface>;
+using DbusSubtree =
+    std::map<DbusPath, std::map<DbusService, DbusInterfaceList>>;
 /**
  * @brief Get the service name from the mapper for the
  *        interface and path passed in.
@@ -89,6 +95,23 @@
     auto reply = bus.call(method);
 }
 
+/** @brief Get subtree from the object mapper.
+ *
+ * Helper function to find objects, services, and interfaces.
+ * See:
+ * https://github.com/openbmc/docs/blob/master/architecture/object-mapper.md
+ *
+ * @param[in] bus - The D-Bus object.
+ * @param[in] path - The root of the tree to search.
+ * @param[in] interface - Interface in the subtree to search for
+ * @param[in] depth - The number of path elements to descend.
+ *
+ * @return DbusSubtree - Map of object paths to a map of service names to their
+ *                       interfaces.
+ */
+DbusSubtree getSubTree(sdbusplus::bus::bus& bus, const std::string& path,
+                       const std::string& interface, int32_t depth);
+
 /**
  * Logs an error and powers off the system.
  *