#include "ExternalSensor.hpp" #include "SensorPaths.hpp" #include #include #include #include #include #include #include #include #include #include #include #include ExternalSensor::ExternalSensor( const std::string& objectType, sdbusplus::asio::object_server& objectServer, std::shared_ptr& conn, const std::string& sensorName, const std::string& sensorUnits, std::vector&& _thresholds, const std::string& sensorConfiguration, const double& maxReading, const double& minReading, const PowerState& powerState) : // TODO(): When the Mutable feature is integrated, // make sure all ExternalSensor instances are mutable, // because that is the entire point of ExternalSensor, // to accept sensor values written by an external source. Sensor(boost::replace_all_copy(sensorName, " ", "_"), std::move(_thresholds), sensorConfiguration, objectType, maxReading, minReading, conn, powerState), std::enable_shared_from_this(), objServer(objectServer) { // The caller must specify what physical characteristic // an external sensor is expected to be measuring, such as temperature, // as, unlike others, this is not implied by device type name. std::string dbusPath = sensors::getPathForUnits(sensorUnits); if (dbusPath.empty()) { throw std::runtime_error("Units not in allow list"); } std::string objectPath = sensors::objectPathPrefix; objectPath += dbusPath; objectPath += '/'; objectPath += sensorName; sensorInterface = objectServer.add_interface( objectPath, "xyz.openbmc_project.Sensor.Value"); if (thresholds::hasWarningInterface(thresholds)) { thresholdInterfaceWarning = objectServer.add_interface( objectPath, "xyz.openbmc_project.Sensor.Threshold.Warning"); } if (thresholds::hasCriticalInterface(thresholds)) { thresholdInterfaceCritical = objectServer.add_interface( objectPath, "xyz.openbmc_project.Sensor.Threshold.Critical"); } association = objectServer.add_interface(objectPath, association::interface); setInitialProperties(conn); } ExternalSensor::~ExternalSensor() { objServer.remove_interface(association); objServer.remove_interface(thresholdInterfaceCritical); objServer.remove_interface(thresholdInterfaceWarning); objServer.remove_interface(sensorInterface); } void ExternalSensor::checkThresholds(void) { thresholds::checkThresholds(this); }