#pragma once #include "dbushelper_interface.hpp" #include #include #include #include namespace pid_control { class DbusHelper : public DbusHelperInterface { public: static constexpr char sensorintf[] = "xyz.openbmc_project.Sensor.Value"; static constexpr char propertiesintf[] = "org.freedesktop.DBus.Properties"; static constexpr char criticalThreshInf[] = "xyz.openbmc_project.Sensor.Threshold.Critical"; static constexpr char availabilityIntf[] = "xyz.openbmc_project.State.Decorator.Availability"; explicit DbusHelper(sdbusplus::bus::bus bus) : _bus(std::move(bus)) {} ~DbusHelper() = default; DbusHelper(const DbusHelper&) = delete; DbusHelper& operator=(const DbusHelper&) = delete; DbusHelper(DbusHelper&&) = default; DbusHelper& operator=(DbusHelper&&) = default; std::string getService(const std::string& intf, const std::string& path) override; void getProperties(const std::string& service, const std::string& path, SensorProperties* prop) override; bool thresholdsAsserted(const std::string& service, const std::string& path) override; template void getProperty(const std::string& service, const std::string& path, const std::string& interface, const std::string& propertyName, T& prop) { namespace log = phosphor::logging; auto msg = _bus.new_method_call(service.c_str(), path.c_str(), propertiesintf, "Get"); msg.append(interface, propertyName); std::variant result; try { auto valueResponseMsg = _bus.call(msg); valueResponseMsg.read(result); } catch (const sdbusplus::exception::exception& ex) { log::log("Get Property Failed", log::entry("WHAT=%s", ex.what())); throw; } prop = std::get(result); } private: sdbusplus::bus::bus _bus; }; } // namespace pid_control