blob: 41d8c697f978700c8292760ab5a1c62bbfbfd29b [file] [log] [blame]
Tao Linf2e94222023-10-31 17:38:17 +08001#pragma once
Vijay Khemka7452a862020-08-11 16:01:23 -07002
3#include <sdbusplus/bus.hpp>
Patrick Williamsb57d7372021-11-19 12:26:08 -06004#include <sdbusplus/bus/match.hpp>
Vijay Khemka7452a862020-08-11 16:01:23 -07005
Tao Linf2e94222023-10-31 17:38:17 +08006namespace phosphor::virtual_sensor
7{
Vijay Khemka7452a862020-08-11 16:01:23 -07008
Tao Linf2e94222023-10-31 17:38:17 +08009class VirtualSensor;
Vijay Khemka51f898e2020-09-09 22:24:18 -070010
Vijay Khemka7452a862020-08-11 16:01:23 -070011class 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 */
Tao Linf2e94222023-10-31 17:38:17 +080022 DbusSensor(sdbusplus::bus_t& bus, const std::string& path,
23 VirtualSensor& virtualSensor);
Vijay Khemka7452a862020-08-11 16:01:23 -070024
Tao Linf2e94222023-10-31 17:38:17 +080025 /** @brief Get sensor value from local */
26 double getSensorValue();
Vijay Khemka7452a862020-08-11 16:01:23 -070027
28 private:
29 /** @brief sdbusplus bus client connection. */
Patrick Williams8e11ccc2022-07-22 19:26:57 -050030 sdbusplus::bus_t& bus;
Tao Linf2e94222023-10-31 17:38:17 +080031
Vijay Khemka7452a862020-08-11 16:01:23 -070032 /** @brief complete path for sensor */
George Liu1204b432021-12-29 17:24:48 +080033 std::string path{};
Tao Linf2e94222023-10-31 17:38:17 +080034
Vijay Khemka7452a862020-08-11 16:01:23 -070035 /** @brief service name for the sensor daemon */
George Liu1204b432021-12-29 17:24:48 +080036 std::string servName{};
Tao Linf2e94222023-10-31 17:38:17 +080037
38 /** @brief point to the VirtualSensor */
39 VirtualSensor& virtualSensor;
40
Vijay Khemka51f898e2020-09-09 22:24:18 -070041 /** @brief signal for sensor value change */
Tao Linf2e94222023-10-31 17:38:17 +080042 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);
Vijay Khemka7452a862020-08-11 16:01:23 -070064};
Tao Linf2e94222023-10-31 17:38:17 +080065
66} // namespace phosphor::virtual_sensor