Tao Lin | f2e9422 | 2023-10-31 17:38:17 +0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Vijay Khemka | 7452a86 | 2020-08-11 16:01:23 -0700 | [diff] [blame] | 3 | #include "dbusSensor.hpp" |
Vijay Khemka | 92d648b | 2020-08-21 18:55:07 -0700 | [diff] [blame] | 4 | #include "exprtkTools.hpp" |
Matt Spinler | 8f5e611 | 2021-01-15 10:44:32 -0600 | [diff] [blame] | 5 | #include "thresholds.hpp" |
| 6 | |
Vijay Khemka | abcc94f | 2020-08-11 15:27:44 -0700 | [diff] [blame] | 7 | #include <nlohmann/json.hpp> |
Patrick Williams | 82b39c6 | 2021-07-28 16:22:27 -0500 | [diff] [blame] | 8 | #include <phosphor-logging/lg2.hpp> |
Vijay Khemka | abcc94f | 2020-08-11 15:27:44 -0700 | [diff] [blame] | 9 | #include <sdbusplus/bus.hpp> |
Lei YU | 0fcf0e1 | 2021-06-04 11:14:17 +0800 | [diff] [blame] | 10 | #include <xyz/openbmc_project/Association/Definitions/server.hpp> |
Vijay Khemka | abcc94f | 2020-08-11 15:27:44 -0700 | [diff] [blame] | 11 | #include <xyz/openbmc_project/Sensor/Value/server.hpp> |
| 12 | |
| 13 | #include <map> |
| 14 | #include <string> |
| 15 | |
Tao Lin | f2e9422 | 2023-10-31 17:38:17 +0800 | [diff] [blame] | 16 | namespace phosphor::virtual_sensor |
Vijay Khemka | abcc94f | 2020-08-11 15:27:44 -0700 | [diff] [blame] | 17 | { |
| 18 | |
Patrick Williams | 82b39c6 | 2021-07-28 16:22:27 -0500 | [diff] [blame] | 19 | PHOSPHOR_LOG2_USING_WITH_FLAGS; |
| 20 | |
Rashmica Gupta | e7efe13 | 2021-07-27 19:42:11 +1000 | [diff] [blame] | 21 | using BasicVariantType = |
| 22 | std::variant<std::string, int64_t, uint64_t, double, int32_t, uint32_t, |
| 23 | int16_t, uint16_t, uint8_t, bool, std::vector<std::string>>; |
| 24 | |
| 25 | using PropertyMap = std::map<std::string, BasicVariantType>; |
| 26 | |
| 27 | using InterfaceMap = std::map<std::string, PropertyMap>; |
| 28 | |
| 29 | using ManagedObjectType = |
| 30 | std::map<sdbusplus::message::object_path, InterfaceMap>; |
| 31 | |
Vijay Khemka | abcc94f | 2020-08-11 15:27:44 -0700 | [diff] [blame] | 32 | using Json = nlohmann::json; |
Matt Spinler | ce67522 | 2021-01-14 16:38:09 -0600 | [diff] [blame] | 33 | |
| 34 | template <typename... T> |
Patrick Williams | 8e11ccc | 2022-07-22 19:26:57 -0500 | [diff] [blame] | 35 | using ServerObject = typename sdbusplus::server::object_t<T...>; |
Matt Spinler | ce67522 | 2021-01-14 16:38:09 -0600 | [diff] [blame] | 36 | |
Vijay Khemka | abcc94f | 2020-08-11 15:27:44 -0700 | [diff] [blame] | 37 | using ValueIface = sdbusplus::xyz::openbmc_project::Sensor::server::Value; |
Matt Spinler | ce67522 | 2021-01-14 16:38:09 -0600 | [diff] [blame] | 38 | using ValueObject = ServerObject<ValueIface>; |
Vijay Khemka | abcc94f | 2020-08-11 15:27:44 -0700 | [diff] [blame] | 39 | |
Lei YU | 0fcf0e1 | 2021-06-04 11:14:17 +0800 | [diff] [blame] | 40 | using AssociationIface = |
| 41 | sdbusplus::xyz::openbmc_project::Association::server::Definitions; |
| 42 | using AssociationObject = ServerObject<AssociationIface>; |
| 43 | |
Vijay Khemka | abcc94f | 2020-08-11 15:27:44 -0700 | [diff] [blame] | 44 | class SensorParam |
| 45 | { |
| 46 | public: |
| 47 | SensorParam() = delete; |
| 48 | virtual ~SensorParam() = default; |
| 49 | |
| 50 | enum ParamType |
| 51 | { |
| 52 | constParam, |
| 53 | dbusParam |
| 54 | }; |
| 55 | |
| 56 | /** @brief Constructs SensorParam (type = constParam) |
| 57 | * |
| 58 | * @param[in] value - Value of constant parameter |
| 59 | */ |
Patrick Williams | 1226f20 | 2023-05-10 07:51:16 -0500 | [diff] [blame] | 60 | explicit SensorParam(double value) : value(value), paramType(constParam) {} |
Vijay Khemka | abcc94f | 2020-08-11 15:27:44 -0700 | [diff] [blame] | 61 | |
Vijay Khemka | 7452a86 | 2020-08-11 16:01:23 -0700 | [diff] [blame] | 62 | /** @brief Constructs SensorParam (type = dbusParam) |
| 63 | * |
| 64 | * @param[in] bus - Handle to system dbus |
| 65 | * @param[in] path - The Dbus path of sensor |
Vijay Khemka | 51f898e | 2020-09-09 22:24:18 -0700 | [diff] [blame] | 66 | * @param[in] ctx - sensor context for update |
Vijay Khemka | 7452a86 | 2020-08-11 16:01:23 -0700 | [diff] [blame] | 67 | */ |
Tao Lin | f2e9422 | 2023-10-31 17:38:17 +0800 | [diff] [blame] | 68 | SensorParam(sdbusplus::bus_t& bus, const std::string& path, |
| 69 | VirtualSensor& ctx) : |
Vijay Khemka | 51f898e | 2020-09-09 22:24:18 -0700 | [diff] [blame] | 70 | dbusSensor(std::make_unique<DbusSensor>(bus, path, ctx)), |
Vijay Khemka | 7452a86 | 2020-08-11 16:01:23 -0700 | [diff] [blame] | 71 | paramType(dbusParam) |
| 72 | {} |
| 73 | |
Vijay Khemka | abcc94f | 2020-08-11 15:27:44 -0700 | [diff] [blame] | 74 | /** @brief Get sensor value property from D-bus interface */ |
| 75 | double getParamValue(); |
| 76 | |
| 77 | private: |
Vijay Khemka | 7452a86 | 2020-08-11 16:01:23 -0700 | [diff] [blame] | 78 | std::unique_ptr<DbusSensor> dbusSensor = nullptr; |
Tao Lin | f2e9422 | 2023-10-31 17:38:17 +0800 | [diff] [blame] | 79 | |
| 80 | /** @brief virtual sensor value */ |
| 81 | double value = std::numeric_limits<double>::quiet_NaN(); |
Vijay Khemka | abcc94f | 2020-08-11 15:27:44 -0700 | [diff] [blame] | 82 | ParamType paramType; |
| 83 | }; |
| 84 | |
Matt Spinler | ce67522 | 2021-01-14 16:38:09 -0600 | [diff] [blame] | 85 | class VirtualSensor : public ValueObject |
Vijay Khemka | abcc94f | 2020-08-11 15:27:44 -0700 | [diff] [blame] | 86 | { |
| 87 | public: |
| 88 | VirtualSensor() = delete; |
| 89 | virtual ~VirtualSensor() = default; |
| 90 | |
| 91 | /** @brief Constructs VirtualSensor |
| 92 | * |
| 93 | * @param[in] bus - Handle to system dbus |
| 94 | * @param[in] objPath - The Dbus path of sensor |
| 95 | * @param[in] sensorConfig - Json object for sensor config |
| 96 | */ |
Patrick Williams | 8e11ccc | 2022-07-22 19:26:57 -0500 | [diff] [blame] | 97 | VirtualSensor(sdbusplus::bus_t& bus, const char* objPath, |
Vijay Khemka | 32a7156 | 2020-09-10 15:29:18 -0700 | [diff] [blame] | 98 | const Json& sensorConfig, const std::string& name) : |
Patrick Williams | 150d5f6 | 2024-08-16 15:21:45 -0400 | [diff] [blame] | 99 | ValueObject(bus, objPath, action::defer_emit), bus(bus), name(name) |
Vijay Khemka | abcc94f | 2020-08-11 15:27:44 -0700 | [diff] [blame] | 100 | { |
Matt Spinler | ce67522 | 2021-01-14 16:38:09 -0600 | [diff] [blame] | 101 | initVirtualSensor(sensorConfig, objPath); |
Vijay Khemka | abcc94f | 2020-08-11 15:27:44 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Rashmica Gupta | e7efe13 | 2021-07-27 19:42:11 +1000 | [diff] [blame] | 104 | /** @brief Constructs VirtualSensor |
| 105 | * |
| 106 | * @param[in] bus - Handle to system dbus |
| 107 | * @param[in] objPath - The Dbus path of sensor |
| 108 | * @param[in] ifacemap - All the sensor information |
| 109 | * @param[in] name - Virtual sensor name |
| 110 | * @param[in] type - Virtual sensor type/unit |
| 111 | * @param[in] calcType - Calculation used to calculate sensor value |
Tao Lin | dc77701 | 2022-07-27 20:41:46 +0800 | [diff] [blame] | 112 | * @param[in] entityPath - Virtual sensor path in entityManager Dbus |
Rashmica Gupta | e7efe13 | 2021-07-27 19:42:11 +1000 | [diff] [blame] | 113 | * |
| 114 | */ |
Patrick Williams | 8e11ccc | 2022-07-22 19:26:57 -0500 | [diff] [blame] | 115 | VirtualSensor(sdbusplus::bus_t& bus, const char* objPath, |
Rashmica Gupta | e7efe13 | 2021-07-27 19:42:11 +1000 | [diff] [blame] | 116 | const InterfaceMap& ifacemap, const std::string& name, |
Tao Lin | dc77701 | 2022-07-27 20:41:46 +0800 | [diff] [blame] | 117 | const std::string& type, const std::string& calculationType, |
| 118 | const std::string& entityPath) : |
Patrick Williams | 150d5f6 | 2024-08-16 15:21:45 -0400 | [diff] [blame] | 119 | ValueObject(bus, objPath, action::defer_emit), bus(bus), name(name), |
| 120 | entityPath(entityPath) |
Rashmica Gupta | e7efe13 | 2021-07-27 19:42:11 +1000 | [diff] [blame] | 121 | { |
| 122 | initVirtualSensor(ifacemap, objPath, type, calculationType); |
| 123 | } |
| 124 | |
Vijay Khemka | abcc94f | 2020-08-11 15:27:44 -0700 | [diff] [blame] | 125 | /** @brief Set sensor value */ |
| 126 | void setSensorValue(double value); |
Tao Lin | f2e9422 | 2023-10-31 17:38:17 +0800 | [diff] [blame] | 127 | |
Vijay Khemka | 3ed9a51 | 2020-08-21 16:13:05 -0700 | [diff] [blame] | 128 | /** @brief Update sensor at regular intrval */ |
| 129 | void updateVirtualSensor(); |
Tao Lin | f2e9422 | 2023-10-31 17:38:17 +0800 | [diff] [blame] | 130 | |
Rashmica Gupta | 304fd0e | 2021-08-10 16:50:44 +1000 | [diff] [blame] | 131 | /** @brief Check if sensor value is in valid range */ |
| 132 | bool sensorInRange(double value); |
Vijay Khemka | abcc94f | 2020-08-11 15:27:44 -0700 | [diff] [blame] | 133 | |
| 134 | /** @brief Map of list of parameters */ |
| 135 | using ParamMap = |
| 136 | std::unordered_map<std::string, std::unique_ptr<SensorParam>>; |
| 137 | ParamMap paramMap; |
| 138 | |
| 139 | private: |
| 140 | /** @brief sdbusplus bus client connection. */ |
Patrick Williams | 8e11ccc | 2022-07-22 19:26:57 -0500 | [diff] [blame] | 141 | sdbusplus::bus_t& bus; |
Vijay Khemka | 32a7156 | 2020-09-10 15:29:18 -0700 | [diff] [blame] | 142 | /** @brief name of sensor */ |
| 143 | std::string name; |
Tao Lin | dc77701 | 2022-07-27 20:41:46 +0800 | [diff] [blame] | 144 | |
| 145 | /** @brief Virtual sensor path in entityManager Dbus. |
| 146 | * This value is used to set thresholds/create association |
| 147 | */ |
| 148 | std::string entityPath; |
Vijay Khemka | abcc94f | 2020-08-11 15:27:44 -0700 | [diff] [blame] | 149 | /** @brief Expression string for virtual sensor value calculations */ |
| 150 | std::string exprStr; |
Vijay Khemka | 3ed9a51 | 2020-08-21 16:13:05 -0700 | [diff] [blame] | 151 | /** @brief symbol table from exprtk */ |
| 152 | exprtk::symbol_table<double> symbols{}; |
| 153 | /** @brief expression from exprtk to calculate sensor value */ |
| 154 | exprtk::expression<double> expression{}; |
Matt Spinler | 9f1ef4f | 2020-11-09 15:59:11 -0600 | [diff] [blame] | 155 | /** @brief The vecops package so the expression can use vectors */ |
| 156 | exprtk::rtl::vecops::package<double> vecopsPackage; |
Rashmica Gupta | e7efe13 | 2021-07-27 19:42:11 +1000 | [diff] [blame] | 157 | /** @brief The maximum valid value for an input sensor **/ |
| 158 | double maxValidInput = std::numeric_limits<double>::infinity(); |
| 159 | /** @brief The minimum valid value for an input sensor **/ |
| 160 | double minValidInput = -std::numeric_limits<double>::infinity(); |
Vijay Khemka | abcc94f | 2020-08-11 15:27:44 -0700 | [diff] [blame] | 161 | |
Matt Spinler | ce67522 | 2021-01-14 16:38:09 -0600 | [diff] [blame] | 162 | /** @brief The critical threshold interface object */ |
Patrick Williams | fdb826d | 2021-01-20 14:37:53 -0600 | [diff] [blame] | 163 | std::unique_ptr<Threshold<CriticalObject>> criticalIface; |
Matt Spinler | ce67522 | 2021-01-14 16:38:09 -0600 | [diff] [blame] | 164 | /** @brief The warning threshold interface object */ |
Patrick Williams | fdb826d | 2021-01-20 14:37:53 -0600 | [diff] [blame] | 165 | std::unique_ptr<Threshold<WarningObject>> warningIface; |
Matt Spinler | ce67522 | 2021-01-14 16:38:09 -0600 | [diff] [blame] | 166 | /** @brief The soft shutdown threshold interface object */ |
Patrick Williams | fdb826d | 2021-01-20 14:37:53 -0600 | [diff] [blame] | 167 | std::unique_ptr<Threshold<SoftShutdownObject>> softShutdownIface; |
Matt Spinler | ce67522 | 2021-01-14 16:38:09 -0600 | [diff] [blame] | 168 | /** @brief The hard shutdown threshold interface object */ |
Patrick Williams | fdb826d | 2021-01-20 14:37:53 -0600 | [diff] [blame] | 169 | std::unique_ptr<Threshold<HardShutdownObject>> hardShutdownIface; |
Matt Spinler | b306b03 | 2021-02-01 10:05:46 -0600 | [diff] [blame] | 170 | /** @brief The performance loss threshold interface object */ |
| 171 | std::unique_ptr<Threshold<PerformanceLossObject>> perfLossIface; |
Matt Spinler | ce67522 | 2021-01-14 16:38:09 -0600 | [diff] [blame] | 172 | |
Lei YU | 0fcf0e1 | 2021-06-04 11:14:17 +0800 | [diff] [blame] | 173 | /** @brief The association interface object */ |
| 174 | std::unique_ptr<AssociationObject> associationIface; |
| 175 | |
Lei YU | 0ab9d83 | 2022-07-19 07:12:50 +0000 | [diff] [blame] | 176 | static FuncMaxIgnoreNaN<double> funcMaxIgnoreNaN; |
Lei YU | 87d3511 | 2022-10-24 05:54:25 +0000 | [diff] [blame] | 177 | static FuncSumIgnoreNaN<double> funcSumIgnoreNaN; |
Lei YU | c77b6b3 | 2023-06-08 12:02:05 +0000 | [diff] [blame] | 178 | static FuncIfNan<double> funcIfNan; |
Lei YU | 0ab9d83 | 2022-07-19 07:12:50 +0000 | [diff] [blame] | 179 | |
Vijay Khemka | abcc94f | 2020-08-11 15:27:44 -0700 | [diff] [blame] | 180 | /** @brief Read config from json object and initialize sensor data |
| 181 | * for each virtual sensor |
| 182 | */ |
Matt Spinler | ce67522 | 2021-01-14 16:38:09 -0600 | [diff] [blame] | 183 | void initVirtualSensor(const Json& sensorConfig, |
| 184 | const std::string& objPath); |
| 185 | |
Rashmica Gupta | e7efe13 | 2021-07-27 19:42:11 +1000 | [diff] [blame] | 186 | /** @brief Read config from interface map and initialize sensor data |
| 187 | * for each virtual sensor |
| 188 | */ |
| 189 | void initVirtualSensor(const InterfaceMap& interfaceMap, |
| 190 | const std::string& objPath, |
| 191 | const std::string& sensorType, |
| 192 | const std::string& calculationType); |
| 193 | |
| 194 | /** @brief Returns which calculation function or expression to use */ |
Rashmica Gupta | 304fd0e | 2021-08-10 16:50:44 +1000 | [diff] [blame] | 195 | double calculateValue(const std::string& sensortype, |
| 196 | const VirtualSensor::ParamMap& paramMap); |
Rashmica Gupta | 3e99919 | 2021-06-09 16:17:04 +1000 | [diff] [blame] | 197 | /** @brief create threshold objects from json config */ |
| 198 | void createThresholds(const Json& threshold, const std::string& objPath); |
Rashmica Gupta | e7efe13 | 2021-07-27 19:42:11 +1000 | [diff] [blame] | 199 | /** @brief parse config from entity manager **/ |
| 200 | void parseConfigInterface(const PropertyMap& propertyMap, |
| 201 | const std::string& sensorType, |
| 202 | const std::string& interface); |
Rashmica Gupta | 3e99919 | 2021-06-09 16:17:04 +1000 | [diff] [blame] | 203 | |
Vijay Khemka | 32a7156 | 2020-09-10 15:29:18 -0700 | [diff] [blame] | 204 | /** @brief Check Sensor threshold and update alarm and log */ |
Patrick Williams | fdb826d | 2021-01-20 14:37:53 -0600 | [diff] [blame] | 205 | template <typename V, typename T> |
| 206 | void checkThresholds(V value, T& threshold) |
Matt Spinler | 8f5e611 | 2021-01-15 10:44:32 -0600 | [diff] [blame] | 207 | { |
Patrick Williams | fdb826d | 2021-01-20 14:37:53 -0600 | [diff] [blame] | 208 | if (!threshold) |
| 209 | return; |
Matt Spinler | 8f5e611 | 2021-01-15 10:44:32 -0600 | [diff] [blame] | 210 | |
Patrick Williams | fdb826d | 2021-01-20 14:37:53 -0600 | [diff] [blame] | 211 | static constexpr auto tname = T::element_type::name; |
| 212 | |
| 213 | auto alarmHigh = threshold->alarmHigh(); |
Rashmica Gupta | 1dff7dc | 2021-07-27 19:43:31 +1000 | [diff] [blame] | 214 | auto highHysteresis = threshold->getHighHysteresis(); |
Matt Spinler | a4fe665 | 2021-01-28 14:02:59 -0600 | [diff] [blame] | 215 | if ((!alarmHigh && value >= threshold->high()) || |
Rashmica Gupta | 1dff7dc | 2021-07-27 19:43:31 +1000 | [diff] [blame] | 216 | (alarmHigh && value < (threshold->high() - highHysteresis))) |
Patrick Williams | fdb826d | 2021-01-20 14:37:53 -0600 | [diff] [blame] | 217 | { |
| 218 | if (!alarmHigh) |
Matt Spinler | 8f5e611 | 2021-01-15 10:44:32 -0600 | [diff] [blame] | 219 | { |
Patrick Williams | 82b39c6 | 2021-07-28 16:22:27 -0500 | [diff] [blame] | 220 | error("ASSERT: sensor {SENSOR} is above the upper threshold " |
| 221 | "{THRESHOLD}.", |
| 222 | "SENSOR", name, "THRESHOLD", tname); |
George Hung | 4294e6d | 2021-04-14 20:58:21 +0800 | [diff] [blame] | 223 | threshold->alarmHighSignalAsserted(value); |
Matt Spinler | 8f5e611 | 2021-01-15 10:44:32 -0600 | [diff] [blame] | 224 | } |
Patrick Williams | fdb826d | 2021-01-20 14:37:53 -0600 | [diff] [blame] | 225 | else |
Matt Spinler | 8f5e611 | 2021-01-15 10:44:32 -0600 | [diff] [blame] | 226 | { |
Patrick Williams | 82b39c6 | 2021-07-28 16:22:27 -0500 | [diff] [blame] | 227 | info("DEASSERT: sensor {SENSOR} is under the upper threshold " |
| 228 | "{THRESHOLD}.", |
| 229 | "SENSOR", name, "THRESHOLD", tname); |
George Hung | 4294e6d | 2021-04-14 20:58:21 +0800 | [diff] [blame] | 230 | threshold->alarmHighSignalDeasserted(value); |
Matt Spinler | 8f5e611 | 2021-01-15 10:44:32 -0600 | [diff] [blame] | 231 | } |
Patrick Williams | fdb826d | 2021-01-20 14:37:53 -0600 | [diff] [blame] | 232 | threshold->alarmHigh(!alarmHigh); |
| 233 | } |
| 234 | |
| 235 | auto alarmLow = threshold->alarmLow(); |
Rashmica Gupta | 1dff7dc | 2021-07-27 19:43:31 +1000 | [diff] [blame] | 236 | auto lowHysteresis = threshold->getLowHysteresis(); |
Matt Spinler | a4fe665 | 2021-01-28 14:02:59 -0600 | [diff] [blame] | 237 | if ((!alarmLow && value <= threshold->low()) || |
Rashmica Gupta | 1dff7dc | 2021-07-27 19:43:31 +1000 | [diff] [blame] | 238 | (alarmLow && value > (threshold->low() + lowHysteresis))) |
Patrick Williams | fdb826d | 2021-01-20 14:37:53 -0600 | [diff] [blame] | 239 | { |
| 240 | if (!alarmLow) |
| 241 | { |
Patrick Williams | 82b39c6 | 2021-07-28 16:22:27 -0500 | [diff] [blame] | 242 | error("ASSERT: sensor {SENSOR} is below the lower threshold " |
| 243 | "{THRESHOLD}.", |
| 244 | "SENSOR", name, "THRESHOLD", tname); |
George Hung | 4294e6d | 2021-04-14 20:58:21 +0800 | [diff] [blame] | 245 | threshold->alarmLowSignalAsserted(value); |
Patrick Williams | fdb826d | 2021-01-20 14:37:53 -0600 | [diff] [blame] | 246 | } |
| 247 | else |
| 248 | { |
Patrick Williams | 82b39c6 | 2021-07-28 16:22:27 -0500 | [diff] [blame] | 249 | info("DEASSERT: sensor {SENSOR} is above the lower threshold " |
| 250 | "{THRESHOLD}.", |
| 251 | "SENSOR", name, "THRESHOLD", tname); |
George Hung | 4294e6d | 2021-04-14 20:58:21 +0800 | [diff] [blame] | 252 | threshold->alarmLowSignalDeasserted(value); |
Patrick Williams | fdb826d | 2021-01-20 14:37:53 -0600 | [diff] [blame] | 253 | } |
| 254 | threshold->alarmLow(!alarmLow); |
Matt Spinler | 8f5e611 | 2021-01-15 10:44:32 -0600 | [diff] [blame] | 255 | } |
| 256 | } |
Tao Lin | dc77701 | 2022-07-27 20:41:46 +0800 | [diff] [blame] | 257 | |
| 258 | /** @brief Create Association from entityPath*/ |
| 259 | void createAssociation(const std::string& objPath, |
| 260 | const std::string& entityPath); |
Vijay Khemka | abcc94f | 2020-08-11 15:27:44 -0700 | [diff] [blame] | 261 | }; |
| 262 | |
| 263 | class VirtualSensors |
| 264 | { |
| 265 | public: |
| 266 | VirtualSensors() = delete; |
| 267 | virtual ~VirtualSensors() = default; |
| 268 | |
| 269 | /** @brief Constructs VirtualSensors |
| 270 | * |
| 271 | * @param[in] bus - Handle to system dbus |
| 272 | */ |
Patrick Williams | 8e11ccc | 2022-07-22 19:26:57 -0500 | [diff] [blame] | 273 | explicit VirtualSensors(sdbusplus::bus_t& bus) : bus(bus) |
Vijay Khemka | abcc94f | 2020-08-11 15:27:44 -0700 | [diff] [blame] | 274 | { |
| 275 | createVirtualSensors(); |
| 276 | } |
Rashmica Gupta | e7efe13 | 2021-07-27 19:42:11 +1000 | [diff] [blame] | 277 | /** @brief Calls createVirtualSensor when interface added */ |
Patrick Williams | 8e11ccc | 2022-07-22 19:26:57 -0500 | [diff] [blame] | 278 | void propertiesChanged(sdbusplus::message_t& msg); |
Vijay Khemka | abcc94f | 2020-08-11 15:27:44 -0700 | [diff] [blame] | 279 | |
| 280 | private: |
| 281 | /** @brief sdbusplus bus client connection. */ |
Patrick Williams | 8e11ccc | 2022-07-22 19:26:57 -0500 | [diff] [blame] | 282 | sdbusplus::bus_t& bus; |
Manojkiran Eda | 5f07fa3 | 2024-06-17 14:26:17 +0530 | [diff] [blame] | 283 | /** @brief Get virtual sensor config from DBus**/ |
Rashmica Gupta | e7efe13 | 2021-07-27 19:42:11 +1000 | [diff] [blame] | 284 | ManagedObjectType getObjectsFromDBus(); |
Vijay Khemka | abcc94f | 2020-08-11 15:27:44 -0700 | [diff] [blame] | 285 | /** @brief Parsing virtual sensor config JSON file */ |
Patrick Williams | 32dff21 | 2023-02-09 13:54:18 -0600 | [diff] [blame] | 286 | Json parseConfigFile(); |
Vijay Khemka | abcc94f | 2020-08-11 15:27:44 -0700 | [diff] [blame] | 287 | |
Rashmica Gupta | e7efe13 | 2021-07-27 19:42:11 +1000 | [diff] [blame] | 288 | /** @brief Matches for virtual sensors */ |
Patrick Williams | 8e11ccc | 2022-07-22 19:26:57 -0500 | [diff] [blame] | 289 | std::vector<std::unique_ptr<sdbusplus::bus::match_t>> matches; |
Vijay Khemka | abcc94f | 2020-08-11 15:27:44 -0700 | [diff] [blame] | 290 | /** @brief Map of the object VirtualSensor */ |
| 291 | std::unordered_map<std::string, std::unique_ptr<VirtualSensor>> |
| 292 | virtualSensorsMap; |
| 293 | |
Rashmica Gupta | e7efe13 | 2021-07-27 19:42:11 +1000 | [diff] [blame] | 294 | /** @brief Create list of virtual sensors from JSON config*/ |
Vijay Khemka | abcc94f | 2020-08-11 15:27:44 -0700 | [diff] [blame] | 295 | void createVirtualSensors(); |
Rashmica Gupta | e7efe13 | 2021-07-27 19:42:11 +1000 | [diff] [blame] | 296 | /** @brief Create list of virtual sensors from DBus config */ |
| 297 | void createVirtualSensorsFromDBus(const std::string& calculationType); |
| 298 | /** @brief Setup matches for virtual sensors */ |
| 299 | void setupMatches(); |
Vijay Khemka | abcc94f | 2020-08-11 15:27:44 -0700 | [diff] [blame] | 300 | }; |
| 301 | |
Tao Lin | f2e9422 | 2023-10-31 17:38:17 +0800 | [diff] [blame] | 302 | } // namespace phosphor::virtual_sensor |