1aadb30ddSPatrick Venture #pragma once 2aadb30ddSPatrick Venture 3aadb30ddSPatrick Venture #include "dbushelper_interface.hpp" 4aadb30ddSPatrick Venture 5aadb30ddSPatrick Venture #include <phosphor-logging/log.hpp> 6aadb30ddSPatrick Venture #include <sdbusplus/bus.hpp> 7aadb30ddSPatrick Venture 8aadb30ddSPatrick Venture #include <string> 9aadb30ddSPatrick Venture #include <variant> 10aadb30ddSPatrick Venture 11aadb30ddSPatrick Venture namespace pid_control 12aadb30ddSPatrick Venture { 13aadb30ddSPatrick Venture 14aadb30ddSPatrick Venture class DbusHelper : public DbusHelperInterface 15aadb30ddSPatrick Venture { 16aadb30ddSPatrick Venture public: 17aadb30ddSPatrick Venture static constexpr char sensorintf[] = "xyz.openbmc_project.Sensor.Value"; 18aadb30ddSPatrick Venture static constexpr char propertiesintf[] = "org.freedesktop.DBus.Properties"; 19aadb30ddSPatrick Venture static constexpr char criticalThreshInf[] = 20aadb30ddSPatrick Venture "xyz.openbmc_project.Sensor.Threshold.Critical"; 21*af97d8efSJonico Eustaquio static constexpr char warningThreshInf[] = 22*af97d8efSJonico Eustaquio "xyz.openbmc_project.Sensor.Threshold.Warning"; 238f73ad76SAlex.Song static constexpr char availabilityIntf[] = 248f73ad76SAlex.Song "xyz.openbmc_project.State.Decorator.Availability"; 25aadb30ddSPatrick Venture DbusHelper(sdbusplus::bus_t bus)268c051121SPatrick Williams explicit DbusHelper(sdbusplus::bus_t bus) : _bus(std::move(bus)) {} 27aadb30ddSPatrick Venture ~DbusHelper() = default; 288729eb98SPatrick Venture 298729eb98SPatrick Venture DbusHelper(const DbusHelper&) = delete; 308729eb98SPatrick Venture DbusHelper& operator=(const DbusHelper&) = delete; 318729eb98SPatrick Venture 32aadb30ddSPatrick Venture DbusHelper(DbusHelper&&) = default; 33aadb30ddSPatrick Venture DbusHelper& operator=(DbusHelper&&) = default; 34aadb30ddSPatrick Venture 359b93692dSPatrick Venture std::string getService(const std::string& intf, 36aadb30ddSPatrick Venture const std::string& path) override; 37aadb30ddSPatrick Venture 389b93692dSPatrick Venture void getProperties(const std::string& service, const std::string& path, 391df9e879SPatrick Venture SensorProperties* prop) override; 40aadb30ddSPatrick Venture 419b93692dSPatrick Venture bool thresholdsAsserted(const std::string& service, 42aadb30ddSPatrick Venture const std::string& path) override; 43aadb30ddSPatrick Venture 44aadb30ddSPatrick Venture template <typename T> getProperty(const std::string & service,const std::string & path,const std::string & interface,const std::string & propertyName,T & prop)459b93692dSPatrick Venture void getProperty(const std::string& service, const std::string& path, 469b93692dSPatrick Venture const std::string& interface, 47aadb30ddSPatrick Venture const std::string& propertyName, T& prop) 48aadb30ddSPatrick Venture { 49aadb30ddSPatrick Venture namespace log = phosphor::logging; 50aadb30ddSPatrick Venture 518729eb98SPatrick Venture auto msg = _bus.new_method_call(service.c_str(), path.c_str(), 52aadb30ddSPatrick Venture propertiesintf, "Get"); 53aadb30ddSPatrick Venture 54aadb30ddSPatrick Venture msg.append(interface, propertyName); 55aadb30ddSPatrick Venture 56aadb30ddSPatrick Venture std::variant<T> result; 57aadb30ddSPatrick Venture try 58aadb30ddSPatrick Venture { 598729eb98SPatrick Venture auto valueResponseMsg = _bus.call(msg); 60aadb30ddSPatrick Venture valueResponseMsg.read(result); 61aadb30ddSPatrick Venture } 62b228bc30SPatrick Williams catch (const sdbusplus::exception_t& ex) 63aadb30ddSPatrick Venture { 64aadb30ddSPatrick Venture log::log<log::level::ERR>("Get Property Failed", 65aadb30ddSPatrick Venture log::entry("WHAT=%s", ex.what())); 66aadb30ddSPatrick Venture throw; 67aadb30ddSPatrick Venture } 68aadb30ddSPatrick Venture 69aadb30ddSPatrick Venture prop = std::get<T>(result); 70aadb30ddSPatrick Venture } 718729eb98SPatrick Venture 728729eb98SPatrick Venture private: 73b228bc30SPatrick Williams sdbusplus::bus_t _bus; 74aadb30ddSPatrick Venture }; 75aadb30ddSPatrick Venture 76aadb30ddSPatrick Venture } // namespace pid_control 77