1*f2e94221STao Lin #pragma once
2*f2e94221STao Lin 
37452a867SVijay Khemka #include <phosphor-logging/elog-errors.hpp>
491799dbdSTao Lin #include <phosphor-logging/lg2.hpp>
57452a867SVijay Khemka #include <xyz/openbmc_project/Common/error.hpp>
67452a867SVijay Khemka 
77452a867SVijay Khemka using namespace sdbusplus::xyz::openbmc_project::Common::Error;
87452a867SVijay Khemka 
97452a867SVijay Khemka using Value = std::variant<int64_t, double, std::string, bool>;
107452a867SVijay Khemka 
118e11cccbSPatrick Williams std::string getService(sdbusplus::bus_t& bus, const std::string& path,
12*f2e94221STao Lin                        const char* intf);
137452a867SVijay Khemka 
147452a867SVijay Khemka template <typename T>
157452a867SVijay Khemka 
getDbusProperty(sdbusplus::bus_t & bus,const std::string & service,const std::string & path,const std::string & intf,const std::string & property)168e11cccbSPatrick Williams T getDbusProperty(sdbusplus::bus_t& bus, const std::string& service,
177452a867SVijay Khemka                   const std::string& path, const std::string& intf,
187452a867SVijay Khemka                   const std::string& property)
197452a867SVijay Khemka {
207452a867SVijay Khemka     Value value;
217452a867SVijay Khemka 
22*f2e94221STao Lin     auto method = bus.new_method_call(service.c_str(), path.c_str(),
23*f2e94221STao Lin                                       "org.freedesktop.DBus.Properties", "Get");
247452a867SVijay Khemka 
257452a867SVijay Khemka     method.append(intf, property);
267452a867SVijay Khemka 
27187582bdSHarvey Wu     try
28187582bdSHarvey Wu     {
297452a867SVijay Khemka         auto msg = bus.call(method);
307452a867SVijay Khemka         msg.read(value);
31187582bdSHarvey Wu     }
328e11cccbSPatrick Williams     catch (const sdbusplus::exception_t& ex)
33187582bdSHarvey Wu     {
34187582bdSHarvey Wu         return std::numeric_limits<T>::quiet_NaN();
35187582bdSHarvey Wu     }
367452a867SVijay Khemka 
377452a867SVijay Khemka     return std::get<T>(value);
387452a867SVijay Khemka }
3991799dbdSTao Lin 
4091799dbdSTao Lin int setDbusProperty(sdbusplus::bus_t& bus, const std::string& service,
4191799dbdSTao Lin                     const std::string& path, const std::string& intf,
42*f2e94221STao Lin                     const std::string& property, const Value& value);
43