1 #pragma once 2 3 #include <sdbusplus/bus.hpp> 4 #include <sdbusplus/bus/match.hpp> 5 6 namespace phosphor::virtual_sensor 7 { 8 9 class VirtualSensor; 10 11 class DbusSensor 12 { 13 public: 14 DbusSensor() = delete; 15 virtual ~DbusSensor() = default; 16 17 /** @brief Constructs DbusSensor 18 * 19 * @param[in] bus - Handle to system dbus 20 * @param[in] path - The Dbus path of sensor 21 */ 22 DbusSensor(sdbusplus::bus_t& bus, const std::string& path, 23 VirtualSensor& virtualSensor); 24 25 /** @brief Get sensor value from local */ 26 double getSensorValue(); 27 28 private: 29 /** @brief sdbusplus bus client connection. */ 30 sdbusplus::bus_t& bus; 31 32 /** @brief complete path for sensor */ 33 std::string path{}; 34 35 /** @brief service name for the sensor daemon */ 36 std::string servName{}; 37 38 /** @brief point to the VirtualSensor */ 39 VirtualSensor& virtualSensor; 40 41 /** @brief signal for sensor value change */ 42 sdbusplus::bus::match_t signalPropChange; 43 44 /** @brief signal for sensor interface remove */ 45 sdbusplus::bus::match_t signalRemove; 46 47 /** @brief Match for this dbus sensor service destroy */ 48 std::unique_ptr<sdbusplus::bus::match_t> signalNameOwnerChanged; 49 50 /** @brief dbus sensor value */ 51 double value = std::numeric_limits<double>::quiet_NaN(); 52 53 /** @brief Get sensor value property from D-bus interface */ 54 void initSensorValue(); 55 56 /** @brief Handle for this dbus sensor NameOwnerChanged */ 57 void handleDbusSignalNameOwnerChanged(sdbusplus::message_t& msg); 58 59 /** @brief Handle for this dbus sensor PropertyChanged */ 60 void handleDbusSignalPropChange(sdbusplus::message_t& msg); 61 62 /** @brief Handle for this dbus sensor InterfaceRemove */ 63 void handleDbusSignalRemove(sdbusplus::message_t& msg); 64 }; 65 66 } // namespace phosphor::virtual_sensor 67