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_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