blob: b1a141865e3b08eac68c6123375c930da67e4423 [file] [log] [blame]
Matthew Barthcd9ab082020-04-13 13:52:49 -05001#pragma once
2
3#include <sdbusplus/bus.hpp>
Shawn McCarney8acaf542021-03-30 10:38:37 -05004#include <sdbusplus/sdbus.hpp>
5
6#include <chrono>
Matthew Barthcd9ab082020-04-13 13:52:49 -05007
8namespace phosphor::power::regulators::control
9{
10
11constexpr auto busName = "xyz.openbmc_project.Power.Regulators";
12constexpr auto objPath = "/xyz/openbmc_project/power/regulators/manager";
13constexpr 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 */
22template <typename... Args>
23auto callMethod(const std::string& method, Args&&... args)
24{
25 auto bus = sdbusplus::bus::new_default();
26 auto reqMsg =
27 bus.new_method_call(busName, objPath, interface, method.c_str());
28 reqMsg.append(std::forward<Args>(args)...);
29
Shawn McCarney8acaf542021-03-30 10:38:37 -050030 // 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);
Matthew Barthcd9ab082020-04-13 13:52:49 -050034}
35
36} // namespace phosphor::power::regulators::control