Add getBusName() utility function to SDBusPlus

Add a function to SDBusPlus to get the D-Bus bus
name for an object path and interface.

Change-Id: I7d7a533c7430fcf42e1e0f6a21a2453e6c8197ea
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
diff --git a/src/data_types.hpp b/src/data_types.hpp
index 5eab4b2..21f2ecf 100644
--- a/src/data_types.hpp
+++ b/src/data_types.hpp
@@ -13,6 +13,10 @@
 namespace monitoring
 {
 
+constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper";
+constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper";
+constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper";
+
 /** @brief A map with references as keys. */
 template <typename Key, typename Value>
 using RefKeyMap = std::map<std::reference_wrapper<Key>, Value, std::less<Key>>;
diff --git a/src/propertywatchimpl.hpp b/src/propertywatchimpl.hpp
index 67bbaff..3ef5de5 100644
--- a/src/propertywatchimpl.hpp
+++ b/src/propertywatchimpl.hpp
@@ -14,11 +14,6 @@
 namespace monitoring
 {
 
-static constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper";
-static constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper";
-static constexpr auto MAPPER_INTERFACE =
-    "xyz.openbmc_project.ObjectMapper";
-
 using MappedPropertyIndex =
     RefKeyMap<const std::string,
     RefKeyMap<const std::string,
diff --git a/src/sdbusplus.hpp b/src/sdbusplus.hpp
index aba5a36..d62a5d4 100644
--- a/src/sdbusplus.hpp
+++ b/src/sdbusplus.hpp
@@ -3,6 +3,7 @@
 #include <sdbusplus/bus.hpp>
 #include <sdbusplus/message.hpp>
 #include <sdbusplus/bus/match.hpp>
+#include "data_types.hpp"
 
 struct Loop;
 
@@ -104,6 +105,29 @@
                     callback);
         }
 
+        /** @brief Look up the bus name for a path and interface */
+        static auto getBusName(
+            const std::string& path,
+            const std::string& interface)
+        {
+            std::vector<std::string> interfaces{interface};
+
+            auto object = callMethodAndRead<GetObject>(
+                    MAPPER_BUSNAME,
+                    MAPPER_PATH,
+                    MAPPER_INTERFACE,
+                    "GetObject",
+                    path,
+                    interfaces);
+
+            std::string name;
+            if (!object.empty())
+            {
+                name = object.begin()->first;
+            }
+            return name;
+        }
+
         friend Loop;
 };