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*8f73ad76SAlex.Song static constexpr char availabilityIntf[] = 22*8f73ad76SAlex.Song "xyz.openbmc_project.State.Decorator.Availability"; 23aadb30ddSPatrick Venture 248729eb98SPatrick Venture explicit DbusHelper(sdbusplus::bus::bus bus) : _bus(std::move(bus)) 258729eb98SPatrick Venture {} 26aadb30ddSPatrick Venture ~DbusHelper() = default; 278729eb98SPatrick Venture 288729eb98SPatrick Venture DbusHelper(const DbusHelper&) = delete; 298729eb98SPatrick Venture DbusHelper& operator=(const DbusHelper&) = delete; 308729eb98SPatrick Venture 31aadb30ddSPatrick Venture DbusHelper(DbusHelper&&) = default; 32aadb30ddSPatrick Venture DbusHelper& operator=(DbusHelper&&) = default; 33aadb30ddSPatrick Venture 349b93692dSPatrick Venture std::string getService(const std::string& intf, 35aadb30ddSPatrick Venture const std::string& path) override; 36aadb30ddSPatrick Venture 379b93692dSPatrick Venture void getProperties(const std::string& service, const std::string& path, 381df9e879SPatrick Venture SensorProperties* prop) override; 39aadb30ddSPatrick Venture 409b93692dSPatrick Venture bool thresholdsAsserted(const std::string& service, 41aadb30ddSPatrick Venture const std::string& path) override; 42aadb30ddSPatrick Venture 43aadb30ddSPatrick Venture template <typename T> 449b93692dSPatrick Venture void getProperty(const std::string& service, const std::string& path, 459b93692dSPatrick Venture const std::string& interface, 46aadb30ddSPatrick Venture const std::string& propertyName, T& prop) 47aadb30ddSPatrick Venture { 48aadb30ddSPatrick Venture namespace log = phosphor::logging; 49aadb30ddSPatrick Venture 508729eb98SPatrick Venture auto msg = _bus.new_method_call(service.c_str(), path.c_str(), 51aadb30ddSPatrick Venture propertiesintf, "Get"); 52aadb30ddSPatrick Venture 53aadb30ddSPatrick Venture msg.append(interface, propertyName); 54aadb30ddSPatrick Venture 55aadb30ddSPatrick Venture std::variant<T> result; 56aadb30ddSPatrick Venture try 57aadb30ddSPatrick Venture { 588729eb98SPatrick Venture auto valueResponseMsg = _bus.call(msg); 59aadb30ddSPatrick Venture valueResponseMsg.read(result); 60aadb30ddSPatrick Venture } 61e7507a8bSPatrick Williams catch (const sdbusplus::exception::exception& ex) 62aadb30ddSPatrick Venture { 63aadb30ddSPatrick Venture log::log<log::level::ERR>("Get Property Failed", 64aadb30ddSPatrick Venture log::entry("WHAT=%s", ex.what())); 65aadb30ddSPatrick Venture throw; 66aadb30ddSPatrick Venture } 67aadb30ddSPatrick Venture 68aadb30ddSPatrick Venture prop = std::get<T>(result); 69aadb30ddSPatrick Venture } 708729eb98SPatrick Venture 718729eb98SPatrick Venture private: 728729eb98SPatrick Venture sdbusplus::bus::bus _bus; 73aadb30ddSPatrick Venture }; 74aadb30ddSPatrick Venture 75aadb30ddSPatrick Venture } // namespace pid_control 76