Matthew Barth | cd9ab08 | 2020-04-13 13:52:49 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <sdbusplus/bus.hpp> |
Shawn McCarney | 8acaf54 | 2021-03-30 10:38:37 -0500 | [diff] [blame] | 4 | #include <sdbusplus/sdbus.hpp> |
| 5 | |
| 6 | #include <chrono> |
Matthew Barth | cd9ab08 | 2020-04-13 13:52:49 -0500 | [diff] [blame] | 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 = |
| 27 | bus.new_method_call(busName, objPath, interface, method.c_str()); |
| 28 | reqMsg.append(std::forward<Args>(args)...); |
| 29 | |
Shawn McCarney | 8acaf54 | 2021-03-30 10:38:37 -0500 | [diff] [blame] | 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); |
Matthew Barth | cd9ab08 | 2020-04-13 13:52:49 -0500 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | } // namespace phosphor::power::regulators::control |