Reducing the dbus string constants

There are a large number of dbus constants scattered throughout the
code that could/should be obtained from phosphor-dbus-interface values.
Some of the minor refactoring is done in this commit to reduce the
dbus string constants.

Change-Id: I2a8441e9ab275e8f2a72c3c79a6ed80e6e444f46
Signed-off-by: Pavithra Barithaya <pavithra.b@ibm.com>
diff --git a/common/utils.cpp b/common/utils.cpp
index 8afa1f4..1dd9fdf 100644
--- a/common/utils.cpp
+++ b/common/utils.cpp
@@ -5,6 +5,8 @@
 
 #include <phosphor-logging/lg2.hpp>
 #include <xyz/openbmc_project/Common/error.hpp>
+#include <xyz/openbmc_project/Logging/Create/client.hpp>
+#include <xyz/openbmc_project/ObjectMapper/client.hpp>
 
 #include <algorithm>
 #include <array>
@@ -23,9 +25,8 @@
 {
 namespace utils
 {
-constexpr auto mapperBusName = "xyz.openbmc_project.ObjectMapper";
-constexpr auto mapperPath = "/xyz/openbmc_project/object_mapper";
-constexpr auto mapperInterface = "xyz.openbmc_project.ObjectMapper";
+
+using ObjectMapper = sdbusplus::client::xyz::openbmc_project::ObjectMapper<>;
 
 Entities getParentEntites(const EntityAssociations& entityAssoc)
 {
@@ -414,8 +415,9 @@
     std::map<std::string, std::vector<std::string>> mapperResponse;
     auto& bus = DBusHandler::getBus();
 
-    auto mapper = bus.new_method_call(mapperBusName, mapperPath,
-                                      mapperInterface, "GetObject");
+    auto mapper = bus.new_method_call(ObjectMapper::default_service,
+                                      ObjectMapper::instance_path,
+                                      ObjectMapper::interface, "GetObject");
 
     if (interface)
     {
@@ -436,8 +438,9 @@
                             const std::vector<std::string>& ifaceList) const
 {
     auto& bus = pldm::utils::DBusHandler::getBus();
-    auto method = bus.new_method_call(mapperBusName, mapperPath,
-                                      mapperInterface, "GetSubTree");
+    auto method = bus.new_method_call(ObjectMapper::default_service,
+                                      ObjectMapper::instance_path,
+                                      ObjectMapper::interface, "GetSubTree");
     method.append(searchPath, depth, ifaceList);
     auto reply = bus.call(method, dbusTimeout);
     GetSubTreeResponse response;
@@ -447,21 +450,22 @@
 
 void reportError(const char* errorMsg)
 {
-    static constexpr auto logObjPath = "/xyz/openbmc_project/logging";
-    static constexpr auto logInterface = "xyz.openbmc_project.Logging.Create";
-
     auto& bus = pldm::utils::DBusHandler::getBus();
 
     try
     {
-        auto service = DBusHandler().getService(logObjPath, logInterface);
+        using LoggingCreate =
+            sdbusplus::client::xyz::openbmc_project::logging::Create<>;
+
         using namespace sdbusplus::xyz::openbmc_project::Logging::server;
         auto severity =
             sdbusplus::xyz::openbmc_project::Logging::server::convertForMessage(
                 sdbusplus::xyz::openbmc_project::Logging::server::Entry::Level::
                     Error);
-        auto method = bus.new_method_call(service.c_str(), logObjPath,
-                                          logInterface, "Create");
+        auto method = bus.new_method_call(LoggingCreate::default_service,
+                                          LoggingCreate::instance_path,
+                                          LoggingCreate::interface, "Create");
+
         std::map<std::string, std::string> addlData{};
         method.append(errorMsg, severity, addlData);
         bus.call_noreply(method, dbusTimeout);
diff --git a/host-bmc/dbus_to_host_effecters.cpp b/host-bmc/dbus_to_host_effecters.cpp
index 165dab9..b16c750 100644
--- a/host-bmc/dbus_to_host_effecters.cpp
+++ b/host-bmc/dbus_to_host_effecters.cpp
@@ -5,6 +5,7 @@
 
 #include <phosphor-logging/lg2.hpp>
 #include <xyz/openbmc_project/Common/error.hpp>
+#include <xyz/openbmc_project/State/Boot/Progress/client.hpp>
 #include <xyz/openbmc_project/State/OperatingSystem/Status/server.hpp>
 
 #include <fstream>
@@ -126,6 +127,9 @@
     const DbusChgHostEffecterProps& chProperties, size_t effecterInfoIndex,
     size_t dbusInfoIndex, uint16_t effecterId)
 {
+    using BootProgress =
+        sdbusplus::client::xyz::openbmc_project::state::boot::Progress<>;
+
     const auto& propertyName = hostEffecterInfo[effecterInfoIndex]
                                    .dbusInfo[dbusInfoIndex]
                                    .dbusMap.propertyName;
@@ -154,21 +158,22 @@
             return;
         }
     }
-    constexpr auto hostStateInterface =
-        "xyz.openbmc_project.State.Boot.Progress";
     constexpr auto hostStatePath = "/xyz/openbmc_project/state/host0";
 
     try
     {
         auto propVal = dbusHandler->getDbusPropertyVariant(
-            hostStatePath, "BootProgress", hostStateInterface);
+            hostStatePath, "BootProgress", BootProgress::interface);
         const auto& currHostState = std::get<std::string>(propVal);
-        if ((currHostState != "xyz.openbmc_project.State.Boot.Progress."
-                              "ProgressStages.SystemInitComplete") &&
-            (currHostState != "xyz.openbmc_project.State.Boot.Progress."
-                              "ProgressStages.OSRunning") &&
-            (currHostState != "xyz.openbmc_project.State.Boot.Progress."
-                              "ProgressStages.SystemSetup"))
+        if ((sdbusplus::message::convert_from_string<
+                 BootProgress::ProgressStages>(currHostState) !=
+             BootProgress::ProgressStages::SystemInitComplete) &&
+            (sdbusplus::message::convert_from_string<
+                 BootProgress::ProgressStages>(currHostState) !=
+             BootProgress::ProgressStages::OSRunning) &&
+            (sdbusplus::message::convert_from_string<
+                 BootProgress::ProgressStages>(currHostState) !=
+             BootProgress::ProgressStages::SystemSetup))
         {
             info("Host is not up. Current host state: {CUR_HOST_STATE}",
                  "CUR_HOST_STATE", currHostState.c_str());
diff --git a/oem/ibm/libpldmresponder/oem_ibm_handler.cpp b/oem/ibm/libpldmresponder/oem_ibm_handler.cpp
index 7ab075d..a6ac666 100644
--- a/oem/ibm/libpldmresponder/oem_ibm_handler.cpp
+++ b/oem/ibm/libpldmresponder/oem_ibm_handler.cpp
@@ -8,6 +8,7 @@
 #include <libpldm/oem/ibm/entity.h>
 
 #include <phosphor-logging/lg2.hpp>
+#include <xyz/openbmc_project/State/BMC/client.hpp>
 
 PHOSPHOR_LOG2_USING;
 
@@ -575,12 +576,14 @@
 }
 int pldm::responder::oem_ibm_platform::Handler::checkBMCState()
 {
+    using BMC = sdbusplus::client::xyz::openbmc_project::state::BMC<>;
+    auto bmcPath = sdbusplus::message::object_path(BMC::namespace_path::value) /
+                   BMC::namespace_path::bmc;
     try
     {
         pldm::utils::PropertyValue propertyValue =
             pldm::utils::DBusHandler().getDbusPropertyVariant(
-                "/xyz/openbmc_project/state/bmc0", "CurrentBMCState",
-                "xyz.openbmc_project.State.BMC");
+                bmcPath.str.c_str(), "CurrentBMCState", BMC::interface);
 
         if (std::get<std::string>(propertyValue) ==
             "xyz.openbmc_project.State.BMC.BMCState.NotReady")
diff --git a/oem/ibm/libpldmresponder/platform_oem_ibm.cpp b/oem/ibm/libpldmresponder/platform_oem_ibm.cpp
index 432bfd4..5d9eea5 100644
--- a/oem/ibm/libpldmresponder/platform_oem_ibm.cpp
+++ b/oem/ibm/libpldmresponder/platform_oem_ibm.cpp
@@ -7,6 +7,7 @@
 
 #include <phosphor-logging/lg2.hpp>
 #include <xyz/openbmc_project/Common/error.hpp>
+#include <xyz/openbmc_project/State/Boot/Progress/client.hpp>
 
 #include <iostream>
 
@@ -23,22 +24,26 @@
     const std::vector<uint16_t>& handles,
     pldm::requester::Handler<pldm::requester::Request>* handler)
 {
+    using BootProgress =
+        sdbusplus::client::xyz::openbmc_project::state::boot::Progress<>;
+
     constexpr auto hostStatePath = "/xyz/openbmc_project/state/host0";
-    constexpr auto hostStateInterface =
-        "xyz.openbmc_project.State.Boot.Progress";
     constexpr auto hostStateProperty = "BootProgress";
 
     try
     {
         auto propVal = pldm::utils::DBusHandler().getDbusPropertyVariant(
-            hostStatePath, hostStateProperty, hostStateInterface);
+            hostStatePath, hostStateProperty, BootProgress::interface);
         const auto& currHostState = std::get<std::string>(propVal);
-        if ((currHostState != "xyz.openbmc_project.State.Boot.Progress."
-                              "ProgressStages.SystemInitComplete") &&
-            (currHostState != "xyz.openbmc_project.State.Boot.Progress."
-                              "ProgressStages.OSRunning") &&
-            (currHostState != "xyz.openbmc_project.State.Boot.Progress."
-                              "ProgressStages.SystemSetup"))
+        if ((sdbusplus::message::convert_from_string<
+                 BootProgress::ProgressStages>(currHostState) !=
+             BootProgress::ProgressStages::SystemInitComplete) &&
+            (sdbusplus::message::convert_from_string<
+                 BootProgress::ProgressStages>(currHostState) !=
+             BootProgress::ProgressStages::OSRunning) &&
+            (sdbusplus::message::convert_from_string<
+                 BootProgress::ProgressStages>(currHostState) !=
+             BootProgress::ProgressStages::SystemSetup))
         {
             return PLDM_SUCCESS;
         }