regs: Create regulator control utility function
The regulator control program will call methods on the
phosphor-regulators service to control the mode in which the
phosphor-regulators application should run in.
Tested:
Dbus method call occurs against the phosphor-regulators service
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
Change-Id: Ib5829f271883bee2ebd52d33cb75da603752e0ae
diff --git a/phosphor-regulators/src/regsctl/utility.hpp b/phosphor-regulators/src/regsctl/utility.hpp
new file mode 100644
index 0000000..5e46dd8
--- /dev/null
+++ b/phosphor-regulators/src/regsctl/utility.hpp
@@ -0,0 +1,30 @@
+#pragma once
+
+#include <sdbusplus/bus.hpp>
+
+namespace phosphor::power::regulators::control
+{
+
+constexpr auto busName = "xyz.openbmc_project.Power.Regulators";
+constexpr auto objPath = "/xyz/openbmc_project/power/regulators/manager";
+constexpr auto interface = "xyz.openbmc_project.Power.Regulators.Manager";
+
+/**
+ * @brief Call a dbus method
+ * @param[in] method - Method name to call
+ * @param[in] args - Any needed arguments to the method
+ *
+ * @return Response message from the method call
+ */
+template <typename... Args>
+auto callMethod(const std::string& method, Args&&... args)
+{
+ auto bus = sdbusplus::bus::new_default();
+ auto reqMsg =
+ bus.new_method_call(busName, objPath, interface, method.c_str());
+ reqMsg.append(std::forward<Args>(args)...);
+
+ return bus.call(reqMsg);
+}
+
+} // namespace phosphor::power::regulators::control