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"; 218f73ad76SAlex.Song static constexpr char availabilityIntf[] = 228f73ad76SAlex.Song "xyz.openbmc_project.State.Decorator.Availability"; 23aadb30ddSPatrick Venture 24*8c051121SPatrick Williams explicit DbusHelper(sdbusplus::bus_t bus) : _bus(std::move(bus)) {} 25aadb30ddSPatrick Venture ~DbusHelper() = default; 268729eb98SPatrick Venture 278729eb98SPatrick Venture DbusHelper(const DbusHelper&) = delete; 288729eb98SPatrick Venture DbusHelper& operator=(const DbusHelper&) = delete; 298729eb98SPatrick Venture 30aadb30ddSPatrick Venture DbusHelper(DbusHelper&&) = default; 31aadb30ddSPatrick Venture DbusHelper& operator=(DbusHelper&&) = default; 32aadb30ddSPatrick Venture 339b93692dSPatrick Venture std::string getService(const std::string& intf, 34aadb30ddSPatrick Venture const std::string& path) override; 35aadb30ddSPatrick Venture 369b93692dSPatrick Venture void getProperties(const std::string& service, const std::string& path, 371df9e879SPatrick Venture SensorProperties* prop) override; 38aadb30ddSPatrick Venture 399b93692dSPatrick Venture bool thresholdsAsserted(const std::string& service, 40aadb30ddSPatrick Venture const std::string& path) override; 41aadb30ddSPatrick Venture 42aadb30ddSPatrick Venture template <typename T> 439b93692dSPatrick Venture void getProperty(const std::string& service, const std::string& path, 449b93692dSPatrick Venture const std::string& interface, 45aadb30ddSPatrick Venture const std::string& propertyName, T& prop) 46aadb30ddSPatrick Venture { 47aadb30ddSPatrick Venture namespace log = phosphor::logging; 48aadb30ddSPatrick Venture 498729eb98SPatrick Venture auto msg = _bus.new_method_call(service.c_str(), path.c_str(), 50aadb30ddSPatrick Venture propertiesintf, "Get"); 51aadb30ddSPatrick Venture 52aadb30ddSPatrick Venture msg.append(interface, propertyName); 53aadb30ddSPatrick Venture 54aadb30ddSPatrick Venture std::variant<T> result; 55aadb30ddSPatrick Venture try 56aadb30ddSPatrick Venture { 578729eb98SPatrick Venture auto valueResponseMsg = _bus.call(msg); 58aadb30ddSPatrick Venture valueResponseMsg.read(result); 59aadb30ddSPatrick Venture } 60b228bc30SPatrick Williams catch (const sdbusplus::exception_t& ex) 61aadb30ddSPatrick Venture { 62aadb30ddSPatrick Venture log::log<log::level::ERR>("Get Property Failed", 63aadb30ddSPatrick Venture log::entry("WHAT=%s", ex.what())); 64aadb30ddSPatrick Venture throw; 65aadb30ddSPatrick Venture } 66aadb30ddSPatrick Venture 67aadb30ddSPatrick Venture prop = std::get<T>(result); 68aadb30ddSPatrick Venture } 698729eb98SPatrick Venture 708729eb98SPatrick Venture private: 71b228bc30SPatrick Williams sdbusplus::bus_t _bus; 72aadb30ddSPatrick Venture }; 73aadb30ddSPatrick Venture 74aadb30ddSPatrick Venture } // namespace pid_control 75