1 #pragma once
2 
3 #include <sdbusplus/bus.hpp>
4 #include <sdbusplus/sdbus.hpp>
5 
6 #include <chrono>
7 
8 namespace phosphor::power::regulators::control
9 {
10 
11 constexpr auto busName = "xyz.openbmc_project.Power.Regulators";
12 constexpr auto objPath = "/xyz/openbmc_project/power/regulators/manager";
13 constexpr auto interface = "xyz.openbmc_project.Power.Regulators.Manager";
14 
15 /**
16  * @brief Call a dbus method
17  * @param[in] method - Method name to call
18  * @param[in] args - Any needed arguments to the method
19  *
20  * @return Response message from the method call
21  */
22 template <typename... Args>
23 auto callMethod(const std::string& method, Args&&... args)
24 {
25     auto bus = sdbusplus::bus::new_default();
26     auto reqMsg = bus.new_method_call(busName, objPath, interface,
27                                       method.c_str());
28     reqMsg.append(std::forward<Args>(args)...);
29 
30     // Set timeout to 6 minutes; some regulator methods take over 5 minutes
31     using namespace std::chrono_literals;
32     sdbusplus::SdBusDuration timeout{6min};
33     return bus.call(reqMsg, timeout);
34 }
35 
36 } // namespace phosphor::power::regulators::control
37