Tao Lin | f2e9422 | 2023-10-31 17:38:17 +0800 | [diff] [blame] | 1 | #pragma once |
Vijay Khemka | 7452a86 | 2020-08-11 16:01:23 -0700 | [diff] [blame] | 2 | |
| 3 | #include <sdbusplus/bus.hpp> |
Patrick Williams | b57d737 | 2021-11-19 12:26:08 -0600 | [diff] [blame] | 4 | #include <sdbusplus/bus/match.hpp> |
Vijay Khemka | 7452a86 | 2020-08-11 16:01:23 -0700 | [diff] [blame] | 5 | |
Tao Lin | f2e9422 | 2023-10-31 17:38:17 +0800 | [diff] [blame] | 6 | namespace phosphor::virtual_sensor |
| 7 | { |
Vijay Khemka | 7452a86 | 2020-08-11 16:01:23 -0700 | [diff] [blame] | 8 | |
Tao Lin | f2e9422 | 2023-10-31 17:38:17 +0800 | [diff] [blame] | 9 | class VirtualSensor; |
Vijay Khemka | 51f898e | 2020-09-09 22:24:18 -0700 | [diff] [blame] | 10 | |
Vijay Khemka | 7452a86 | 2020-08-11 16:01:23 -0700 | [diff] [blame] | 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 | */ |
Tao Lin | f2e9422 | 2023-10-31 17:38:17 +0800 | [diff] [blame] | 22 | DbusSensor(sdbusplus::bus_t& bus, const std::string& path, |
| 23 | VirtualSensor& virtualSensor); |
Vijay Khemka | 7452a86 | 2020-08-11 16:01:23 -0700 | [diff] [blame] | 24 | |
Tao Lin | f2e9422 | 2023-10-31 17:38:17 +0800 | [diff] [blame] | 25 | /** @brief Get sensor value from local */ |
| 26 | double getSensorValue(); |
Vijay Khemka | 7452a86 | 2020-08-11 16:01:23 -0700 | [diff] [blame] | 27 | |
| 28 | private: |
| 29 | /** @brief sdbusplus bus client connection. */ |
Patrick Williams | 8e11ccc | 2022-07-22 19:26:57 -0500 | [diff] [blame] | 30 | sdbusplus::bus_t& bus; |
Tao Lin | f2e9422 | 2023-10-31 17:38:17 +0800 | [diff] [blame] | 31 | |
Vijay Khemka | 7452a86 | 2020-08-11 16:01:23 -0700 | [diff] [blame] | 32 | /** @brief complete path for sensor */ |
George Liu | 1204b43 | 2021-12-29 17:24:48 +0800 | [diff] [blame] | 33 | std::string path{}; |
Tao Lin | f2e9422 | 2023-10-31 17:38:17 +0800 | [diff] [blame] | 34 | |
Vijay Khemka | 7452a86 | 2020-08-11 16:01:23 -0700 | [diff] [blame] | 35 | /** @brief service name for the sensor daemon */ |
George Liu | 1204b43 | 2021-12-29 17:24:48 +0800 | [diff] [blame] | 36 | std::string servName{}; |
Tao Lin | f2e9422 | 2023-10-31 17:38:17 +0800 | [diff] [blame] | 37 | |
| 38 | /** @brief point to the VirtualSensor */ |
| 39 | VirtualSensor& virtualSensor; |
| 40 | |
Vijay Khemka | 51f898e | 2020-09-09 22:24:18 -0700 | [diff] [blame] | 41 | /** @brief signal for sensor value change */ |
Tao Lin | f2e9422 | 2023-10-31 17:38:17 +0800 | [diff] [blame] | 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); |
Vijay Khemka | 7452a86 | 2020-08-11 16:01:23 -0700 | [diff] [blame] | 64 | }; |
Tao Lin | f2e9422 | 2023-10-31 17:38:17 +0800 | [diff] [blame] | 65 | |
| 66 | } // namespace phosphor::virtual_sensor |