vpd-tool sync BIOS attributes implementation stub

This commit implements stub for vpd-tool manufacturing clean sync
BIOS attributes feature. This changes in this commit allows user to
select --syncBiosAttribute option in --mfgClean. This commit does not
include complete implementation of --syncBiosAttribute option.

Change-Id: I0a8232588edb28b220a0fcf04070a26e2bb2c6f6
Signed-off-by: Souvik Roy <souvikroyofficial10@gmail.com>
diff --git a/vpd-tool/include/tool_constants.hpp b/vpd-tool/include/tool_constants.hpp
index 26c8e75..84b7025 100644
--- a/vpd-tool/include/tool_constants.hpp
+++ b/vpd-tool/include/tool_constants.hpp
@@ -34,5 +34,9 @@
 constexpr auto chassisStateManagerObjectPath =
     "/xyz/openbmc_project/state/chassis0";
 constexpr auto chassisStateManagerInfName = "xyz.openbmc_project.State.Chassis";
+constexpr auto dbusService = "org.freedesktop.DBus";
+constexpr auto dbusObjectPath = "/org/freedesktop/DBus";
+constexpr auto dbusInterface = "org.freedesktop.DBus";
+constexpr auto biosConfigMgrService = "xyz.openbmc_project.BIOSConfigManager";
 } // namespace constants
 } // namespace vpd
diff --git a/vpd-tool/include/tool_utils.hpp b/vpd-tool/include/tool_utils.hpp
index 97359c9..d4bde8a 100644
--- a/vpd-tool/include/tool_utils.hpp
+++ b/vpd-tool/include/tool_utils.hpp
@@ -868,5 +868,40 @@
     return false;
 }
 
+/**
+ * @brief API to check if a D-Bus service is running or not.
+ *
+ * Any failure in calling the method "NameHasOwner" implies that the service
+ * is not in a running state. Hence the API returns false in case of any
+ * exception as well.
+ *
+ * @param[in] i_serviceName - D-Bus service name whose status is to be
+ * checked.
+ * @return bool - True if the service is running, false otherwise.
+ */
+inline bool isServiceRunning(const std::string& i_serviceName) noexcept
+{
+    bool l_retVal = false;
+
+    try
+    {
+        auto l_bus = sdbusplus::bus::new_default();
+        auto l_method = l_bus.new_method_call(
+            constants::dbusService, constants::dbusObjectPath,
+            constants::dbusInterface, "NameHasOwner");
+        l_method.append(i_serviceName);
+
+        l_bus.call(l_method).read(l_retVal);
+    }
+    catch (const sdbusplus::exception::SdBusError& l_ex)
+    {
+        std::cout << "Call to check service status failed with exception: " +
+                         std::string(l_ex.what())
+                  << std::endl;
+    }
+
+    return l_retVal;
+}
+
 } // namespace utils
 } // namespace vpd
diff --git a/vpd-tool/include/vpd_tool.hpp b/vpd-tool/include/vpd_tool.hpp
index d1248da..67a52fc 100644
--- a/vpd-tool/include/vpd_tool.hpp
+++ b/vpd-tool/include/vpd_tool.hpp
@@ -168,6 +168,26 @@
      */
     int handleMoreOption(const nlohmann::json& i_parsedJsonObj) const noexcept;
 
+    /**
+     * @brief API to get VPD value of keyword in BIOS Config Manager.
+     *
+     * For a given record and keyword, this API gets the associated BIOS
+     * attribute current value from BIOS Config Manager, by reading the
+     * attribute value from BIOS Config Manager, converts the BIOS attribute
+     * value to VPD format, and returns it.
+     *
+     * @param[in] i_recordName - Record name.
+     * @param[in] i_keywordName - Keyword name.
+     *
+     * @return On success returns the resultant keyword value in binary
+     * format, else returns empty value.
+     *
+     * @throw std::terminate, std::bad_alloc
+     */
+    types::BinaryVector getVpdValueInBiosConfigManager(
+        [[maybe_unused]] const std::string& i_recordName,
+        [[maybe_unused]] const std::string& i_keywordName) const;
+
   public:
     /**
      * @brief Read keyword value.
@@ -259,13 +279,14 @@
      * 3. D-Bus cache.
      * 4. Backup path.
      *
-     * @param[in] i_syncBiosAttributes - Flag which specifies whether BIOS
-     * attribute related keywords need to be synced from BIOS Config Manager
-     * instead of being reset to default value.
+     * @param[in] i_syncBiosAttributesRequired - Flag which specifies whether
+     * BIOS attribute related keywords need to be synced from BIOS Config
+     * Manager instead of being reset to default value.
      *
      * @return On success returns 0, otherwise returns -1.
      */
-    int cleanSystemVpd(bool i_syncBiosAttributes = false) const noexcept;
+    int cleanSystemVpd(
+        bool i_syncBiosAttributesRequired = false) const noexcept;
 
     /**
      * @brief Dump all the inventory objects in JSON or table format to console.