1 #pragma once 2 3 #include <phosphor-logging/elog-errors.hpp> 4 #include <phosphor-logging/lg2.hpp> 5 #include <xyz/openbmc_project/Common/error.hpp> 6 7 using namespace sdbusplus::xyz::openbmc_project::Common::Error; 8 9 using Value = std::variant<int64_t, double, std::string, bool>; 10 11 std::string getService(sdbusplus::bus_t& bus, const std::string& path, 12 const char* intf); 13 14 template <typename T> 15 16 T getDbusProperty(sdbusplus::bus_t& bus, const std::string& service, 17 const std::string& path, const std::string& intf, 18 const std::string& property) 19 { 20 Value value; 21 22 auto method = bus.new_method_call(service.c_str(), path.c_str(), 23 "org.freedesktop.DBus.Properties", "Get"); 24 25 method.append(intf, property); 26 27 try 28 { 29 auto msg = bus.call(method); 30 msg.read(value); 31 } 32 catch (const sdbusplus::exception_t& ex) 33 { 34 return std::numeric_limits<T>::quiet_NaN(); 35 } 36 37 return std::get<T>(value); 38 } 39 40 int setDbusProperty(sdbusplus::bus_t& bus, const std::string& service, 41 const std::string& path, const std::string& intf, 42 const std::string& property, const Value& value); 43