blob: 1aa8e37c7a342d4851766ceeb37d8d1ed26df196 [file] [log] [blame]
Matt Spinler8f5e6112021-01-15 10:44:32 -06001#pragma once
2
Tao Linf2e94222023-10-31 17:38:17 +08003#include "dbusUtils.hpp"
4
Amithash Prasadb3f59462025-06-02 21:22:13 -07005#include <phosphor-logging/commit.hpp>
Matt Spinler8f5e6112021-01-15 10:44:32 -06006#include <xyz/openbmc_project/Sensor/Threshold/Critical/server.hpp>
7#include <xyz/openbmc_project/Sensor/Threshold/HardShutdown/server.hpp>
Matt Spinlerb306b032021-02-01 10:05:46 -06008#include <xyz/openbmc_project/Sensor/Threshold/PerformanceLoss/server.hpp>
Matt Spinler8f5e6112021-01-15 10:44:32 -06009#include <xyz/openbmc_project/Sensor/Threshold/SoftShutdown/server.hpp>
10#include <xyz/openbmc_project/Sensor/Threshold/Warning/server.hpp>
Amithash Prasadb3f59462025-06-02 21:22:13 -070011#include <xyz/openbmc_project/Sensor/Threshold/event.hpp>
Amithash Prasad7d2f3232025-06-02 20:31:48 -070012#include <xyz/openbmc_project/Sensor/Value/server.hpp>
Matt Spinler8f5e6112021-01-15 10:44:32 -060013
Tao Linf2e94222023-10-31 17:38:17 +080014const constexpr char* entityManagerBusName =
15 "xyz.openbmc_project.EntityManager";
16namespace phosphor::virtual_sensor
Matt Spinler8f5e6112021-01-15 10:44:32 -060017{
18
19template <typename... T>
Patrick Williams8e11ccc2022-07-22 19:26:57 -050020using ServerObject = typename sdbusplus::server::object_t<T...>;
Matt Spinler8f5e6112021-01-15 10:44:32 -060021
Patrick Williamsfdb826d2021-01-20 14:37:53 -060022namespace threshold_ns =
23 sdbusplus::xyz::openbmc_project::Sensor::Threshold::server;
Amithash Prasad7d2f3232025-06-02 20:31:48 -070024using Unit = sdbusplus::xyz::openbmc_project::Sensor::server::Value::Unit;
Patrick Williamsfdb826d2021-01-20 14:37:53 -060025using CriticalObject = ServerObject<threshold_ns::Critical>;
26using WarningObject = ServerObject<threshold_ns::Warning>;
27using SoftShutdownObject = ServerObject<threshold_ns::SoftShutdown>;
28using HardShutdownObject = ServerObject<threshold_ns::HardShutdown>;
Matt Spinlerb306b032021-02-01 10:05:46 -060029using PerformanceLossObject = ServerObject<threshold_ns::PerformanceLoss>;
Matt Spinler8f5e6112021-01-15 10:44:32 -060030
31template <typename T>
Patrick Williamsfdb826d2021-01-20 14:37:53 -060032struct Threshold;
Matt Spinler8f5e6112021-01-15 10:44:32 -060033
Rashmica Gupta1dff7dc2021-07-27 19:43:31 +100034struct Hysteresis
35{
36 double highHysteresis;
37 double lowHysteresis;
38 auto getHighHysteresis()
39 {
40 return this->highHysteresis;
41 }
42
43 auto getLowHysteresis()
44 {
45 return this->lowHysteresis;
46 }
47
48 auto setHighHysteresis(double value)
49 {
50 this->highHysteresis = value;
51 }
52
53 auto setLowHysteresis(double value)
54 {
55 this->lowHysteresis = value;
56 }
57};
58
Amithash Prasadb3f59462025-06-02 21:22:13 -070059template <typename error>
60auto tryCommit(const std::string& objPath, double value, Unit unit,
61 double thresholdValue)
62 -> std::optional<sdbusplus::message::object_path>
63{
64 try
65 {
66 return lg2::commit(
67 error("SENSOR_NAME", objPath, "READING_VALUE", value, "UNITS", unit,
68 "THRESHOLD_VALUE", thresholdValue));
69 }
70 catch (std::exception&)
71 {
72 lg2::error(
73 "Failed creating a threshold log entry for {SENSOR} with value {VALUE}",
74 "SENSOR", objPath, "VALUE", value);
75 return std::nullopt;
76 }
77}
78
79static inline void tryResolve(
80 std::optional<sdbusplus::message::object_path>& log)
81{
82 if (log)
83 {
84 try
85 {
86 lg2::resolve(*log);
87 }
88 catch (std::exception&)
89 {
90 lg2::error("Failed to resolve: {LOG}", "LOG", *log);
91 }
92 log.reset();
93 }
94}
95
Matt Spinler8f5e6112021-01-15 10:44:32 -060096template <>
Rashmica Gupta1dff7dc2021-07-27 19:43:31 +100097struct Threshold<WarningObject> : public WarningObject, public Hysteresis
Matt Spinler8f5e6112021-01-15 10:44:32 -060098{
Patrick Williamsfdb826d2021-01-20 14:37:53 -060099 static constexpr auto name = "Warning";
100 using WarningObject::WarningObject;
Amithash Prasadb3f59462025-06-02 21:22:13 -0700101 using ReadingAboveUpperWarningThreshold = sdbusplus::error::xyz::
102 openbmc_project::sensor::Threshold::ReadingAboveUpperWarningThreshold;
103 using ReadingBelowLowerWarningThreshold = sdbusplus::error::xyz::
104 openbmc_project::sensor::Threshold::ReadingBelowLowerWarningThreshold;
Tao Lin91799db2022-07-27 21:02:20 +0800105 /** @brief sdbusplus bus client connection. */
Patrick Williams83e3ac32022-11-26 09:41:58 -0600106 sdbusplus::bus_t& bus;
Tao Lin91799db2022-07-27 21:02:20 +0800107 std::string objPath;
Amithash Prasad7d2f3232025-06-02 20:31:48 -0700108 Unit units;
Tao Lin91799db2022-07-27 21:02:20 +0800109
110 /** @brief Virtual sensor path/interface in entityManagerDbus.
111 * This 3 value is used to set thresholds
112 */
113 std::string entityPath;
114 std::string entityInterfaceHigh;
115 std::string entityInterfaceLow;
Amithash Prasadb3f59462025-06-02 21:22:13 -0700116 std::optional<sdbusplus::message::object_path> assertedHighLog;
117 std::optional<sdbusplus::message::object_path> assertedLowLog;
Tao Lin91799db2022-07-27 21:02:20 +0800118
119 /** @brief Constructor to put object onto bus at a dbus path.
120 * @param[in] bus - Bus to attach to.
121 * @param[in] path - Path to attach at.
Amithash Prasad7d2f3232025-06-02 20:31:48 -0700122 * @param[in] units - units
Tao Lin91799db2022-07-27 21:02:20 +0800123 */
Amithash Prasad7d2f3232025-06-02 20:31:48 -0700124 Threshold(sdbusplus::bus_t& bus, const char* path, Unit units) :
125 WarningObject(bus, path), bus(bus), objPath(std::string(path)),
126 units(units)
Tao Lin91799db2022-07-27 21:02:20 +0800127 {}
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600128
129 auto high()
Matt Spinler8f5e6112021-01-15 10:44:32 -0600130 {
Tao Lin91799db2022-07-27 21:02:20 +0800131 return WarningObject::warningHigh();
Matt Spinler8f5e6112021-01-15 10:44:32 -0600132 }
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600133 auto low()
Matt Spinler8f5e6112021-01-15 10:44:32 -0600134 {
Tao Lin91799db2022-07-27 21:02:20 +0800135 return WarningObject::warningLow();
Matt Spinler8f5e6112021-01-15 10:44:32 -0600136 }
137
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600138 template <typename... Args>
139 auto alarmHigh(Args... args)
Matt Spinler8f5e6112021-01-15 10:44:32 -0600140 {
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600141 return warningAlarmHigh(std::forward<Args>(args)...);
Matt Spinler8f5e6112021-01-15 10:44:32 -0600142 }
143
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600144 template <typename... Args>
145 auto alarmLow(Args... args)
Matt Spinler8f5e6112021-01-15 10:44:32 -0600146 {
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600147 return warningAlarmLow(std::forward<Args>(args)...);
Matt Spinler8f5e6112021-01-15 10:44:32 -0600148 }
George Hung4294e6d2021-04-14 20:58:21 +0800149
Amithash Prasadb3f59462025-06-02 21:22:13 -0700150 template <typename V>
151 auto alarmHighSignalAsserted(V value)
George Hung4294e6d2021-04-14 20:58:21 +0800152 {
Amithash Prasadb3f59462025-06-02 21:22:13 -0700153 assertedHighLog = tryCommit<ReadingAboveUpperWarningThreshold>(
154 objPath, value, units, high());
155 return warningHighAlarmAsserted(value);
George Hung4294e6d2021-04-14 20:58:21 +0800156 }
157
158 template <typename... Args>
159 auto alarmHighSignalDeasserted(Args... args)
160 {
Amithash Prasadb3f59462025-06-02 21:22:13 -0700161 tryResolve(assertedHighLog);
George Hung4294e6d2021-04-14 20:58:21 +0800162 return warningHighAlarmDeasserted(std::forward<Args>(args)...);
163 }
164
Amithash Prasadb3f59462025-06-02 21:22:13 -0700165 template <typename V>
166 auto alarmLowSignalAsserted(V value)
George Hung4294e6d2021-04-14 20:58:21 +0800167 {
Amithash Prasadb3f59462025-06-02 21:22:13 -0700168 assertedLowLog = tryCommit<ReadingBelowLowerWarningThreshold>(
169 objPath, value, units, low());
170 return warningLowAlarmAsserted(value);
George Hung4294e6d2021-04-14 20:58:21 +0800171 }
172
173 template <typename... Args>
174 auto alarmLowSignalDeasserted(Args... args)
175 {
Amithash Prasadb3f59462025-06-02 21:22:13 -0700176 tryResolve(assertedLowLog);
George Hung4294e6d2021-04-14 20:58:21 +0800177 return warningLowAlarmDeasserted(std::forward<Args>(args)...);
178 }
Tao Lin91799db2022-07-27 21:02:20 +0800179
180 /** @brief Set value of WarningHigh */
181 virtual double warningHigh(double value)
182 {
Matt Spinlera291ce12023-02-06 15:12:44 -0600183 if (!entityPath.empty() && !entityInterfaceHigh.empty())
184 {
185 // persistThreshold
186 setDbusProperty(bus, entityManagerBusName, entityPath,
187 entityInterfaceHigh, "Value", value);
188 }
Tao Lin91799db2022-07-27 21:02:20 +0800189 return WarningObject::warningHigh(value);
190 }
191
192 /** @brief Set value of WarningLow */
193 virtual double warningLow(double value)
194 {
Matt Spinlera291ce12023-02-06 15:12:44 -0600195 if (!entityPath.empty() && !entityInterfaceLow.empty())
196 {
197 // persistThreshold
198 setDbusProperty(bus, entityManagerBusName, entityPath,
199 entityInterfaceLow, "Value", value);
200 }
Tao Lin91799db2022-07-27 21:02:20 +0800201 return WarningObject::warningLow(value);
202 }
203
204 /** @brief Set the entitymanager interface corresponding to virtualsensor
205 * warningLow
206 */
207 void setEntityInterfaceLow(const std::string& interfaceLow)
208 {
209 entityInterfaceLow = interfaceLow;
210 }
211
212 /** @brief Set the entitymanager interface corresponding to virtualsensor
213 * warningHigh
214 */
215 void setEntityInterfaceHigh(const std::string& interfaceHigh)
216 {
217 entityInterfaceHigh = interfaceHigh;
218 }
219
220 /** @brief Set the entitymanager path corresponding to virtualsensor warning
221 */
222 void setEntityPath(const std::string& path)
223 {
224 entityPath = path;
225 }
Matt Spinler8f5e6112021-01-15 10:44:32 -0600226};
227
228template <>
Rashmica Gupta1dff7dc2021-07-27 19:43:31 +1000229struct Threshold<CriticalObject> : public CriticalObject, public Hysteresis
Matt Spinler8f5e6112021-01-15 10:44:32 -0600230{
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600231 static constexpr auto name = "Critical";
Tao Lin91799db2022-07-27 21:02:20 +0800232
233 /** @brief sdbusplus bus client connection. */
Patrick Williams83e3ac32022-11-26 09:41:58 -0600234 sdbusplus::bus_t& bus;
Tao Lin91799db2022-07-27 21:02:20 +0800235 std::string objPath;
Amithash Prasad7d2f3232025-06-02 20:31:48 -0700236 Unit units;
Tao Lin91799db2022-07-27 21:02:20 +0800237
238 /** @brief Virtual sensor path/interface in entityManagerDbus.
239 * This 3 value is used to set thresholds
240 */
241 std::string entityPath;
242 std::string entityInterfaceHigh;
243 std::string entityInterfaceLow;
Amithash Prasadb3f59462025-06-02 21:22:13 -0700244 std::optional<sdbusplus::message::object_path> assertedHighLog;
245 std::optional<sdbusplus::message::object_path> assertedLowLog;
Tao Lin91799db2022-07-27 21:02:20 +0800246
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600247 using CriticalObject::CriticalObject;
Amithash Prasadb3f59462025-06-02 21:22:13 -0700248 using ReadingAboveUpperCriticalThreshold = sdbusplus::error::xyz::
249 openbmc_project::sensor::Threshold::ReadingAboveUpperCriticalThreshold;
250 using ReadingBelowLowerCriticalThreshold = sdbusplus::error::xyz::
251 openbmc_project::sensor::Threshold::ReadingBelowLowerCriticalThreshold;
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600252
Tao Lin91799db2022-07-27 21:02:20 +0800253 /** @brief Constructor to put object onto bus at a dbus path.
254 * @param[in] bus - Bus to attach to.
255 * @param[in] path - Path to attach at.
Amithash Prasad7d2f3232025-06-02 20:31:48 -0700256 * @param[in] units - units
Tao Lin91799db2022-07-27 21:02:20 +0800257 */
Amithash Prasad7d2f3232025-06-02 20:31:48 -0700258 Threshold(sdbusplus::bus_t& bus, const char* path, Unit units) :
259 CriticalObject(bus, path), bus(bus), objPath(std::string(path)),
260 units(units)
Tao Lin91799db2022-07-27 21:02:20 +0800261 {}
262
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600263 auto high()
Matt Spinler8f5e6112021-01-15 10:44:32 -0600264 {
Tao Lin91799db2022-07-27 21:02:20 +0800265 return CriticalObject::criticalHigh();
Matt Spinler8f5e6112021-01-15 10:44:32 -0600266 }
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600267 auto low()
Matt Spinler8f5e6112021-01-15 10:44:32 -0600268 {
Tao Lin91799db2022-07-27 21:02:20 +0800269 return CriticalObject::criticalLow();
Matt Spinler8f5e6112021-01-15 10:44:32 -0600270 }
271
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600272 template <typename... Args>
273 auto alarmHigh(Args... args)
Matt Spinler8f5e6112021-01-15 10:44:32 -0600274 {
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600275 return criticalAlarmHigh(std::forward<Args>(args)...);
Matt Spinler8f5e6112021-01-15 10:44:32 -0600276 }
277
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600278 template <typename... Args>
279 auto alarmLow(Args... args)
Matt Spinler8f5e6112021-01-15 10:44:32 -0600280 {
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600281 return criticalAlarmLow(std::forward<Args>(args)...);
Matt Spinler8f5e6112021-01-15 10:44:32 -0600282 }
George Hung4294e6d2021-04-14 20:58:21 +0800283
Amithash Prasadb3f59462025-06-02 21:22:13 -0700284 template <typename V>
285 auto alarmHighSignalAsserted(V value)
George Hung4294e6d2021-04-14 20:58:21 +0800286 {
Amithash Prasadb3f59462025-06-02 21:22:13 -0700287 assertedHighLog = tryCommit<ReadingAboveUpperCriticalThreshold>(
288 objPath, value, units, high());
289 return criticalHighAlarmAsserted(value);
George Hung4294e6d2021-04-14 20:58:21 +0800290 }
291
292 template <typename... Args>
293 auto alarmHighSignalDeasserted(Args... args)
294 {
Amithash Prasadb3f59462025-06-02 21:22:13 -0700295 tryResolve(assertedHighLog);
George Hung4294e6d2021-04-14 20:58:21 +0800296 return criticalHighAlarmDeasserted(std::forward<Args>(args)...);
297 }
298
Amithash Prasadb3f59462025-06-02 21:22:13 -0700299 template <typename V>
300 auto alarmLowSignalAsserted(V value)
George Hung4294e6d2021-04-14 20:58:21 +0800301 {
Amithash Prasadb3f59462025-06-02 21:22:13 -0700302 assertedLowLog = tryCommit<ReadingBelowLowerCriticalThreshold>(
303 objPath, value, units, low());
304 return criticalLowAlarmAsserted(value);
George Hung4294e6d2021-04-14 20:58:21 +0800305 }
306
307 template <typename... Args>
308 auto alarmLowSignalDeasserted(Args... args)
309 {
Amithash Prasadb3f59462025-06-02 21:22:13 -0700310 tryResolve(assertedLowLog);
George Hung4294e6d2021-04-14 20:58:21 +0800311 return criticalLowAlarmDeasserted(std::forward<Args>(args)...);
312 }
Tao Lin91799db2022-07-27 21:02:20 +0800313
314 /** @brief Set value of CriticalHigh */
315 virtual double criticalHigh(double value)
316 {
317 // persistThreshold
Matt Spinlera291ce12023-02-06 15:12:44 -0600318 if (!entityPath.empty() && !entityInterfaceHigh.empty())
319 {
320 setDbusProperty(bus, entityManagerBusName, entityPath,
321 entityInterfaceHigh, "Value", value);
322 }
Tao Lin91799db2022-07-27 21:02:20 +0800323 return CriticalObject::criticalHigh(value);
324 }
325
326 /** @brief Set value of CriticalLow */
327 virtual double criticalLow(double value)
328 {
Matt Spinlera291ce12023-02-06 15:12:44 -0600329 if (!entityPath.empty() && !entityInterfaceLow.empty())
330 {
331 setDbusProperty(bus, entityManagerBusName, entityPath,
332 entityInterfaceLow, "Value", value);
333 }
Tao Lin91799db2022-07-27 21:02:20 +0800334 return CriticalObject::criticalLow(value);
335 }
336
337 /** @brief Set the entitymanager interface corresponding to virtualsensor
338 * criticalLow
339 */
340 void setEntityInterfaceLow(const std::string& interfaceLow)
341 {
342 entityInterfaceLow = interfaceLow;
343 }
344
345 /** @brief Set the entitymanager interface corresponding to virtualsensor
346 * criticalLow
347 */
348 void setEntityInterfaceHigh(const std::string& interfaceHigh)
349 {
350 entityInterfaceHigh = interfaceHigh;
351 }
352
353 /** @brief Set the entitymanager path corresponding to virtualsensor warning
354 */
355 void setEntityPath(const std::string& path)
356 {
357 entityPath = path;
358 }
Matt Spinler8f5e6112021-01-15 10:44:32 -0600359};
360
361template <>
Rashmica Gupta1dff7dc2021-07-27 19:43:31 +1000362struct Threshold<SoftShutdownObject> :
363 public SoftShutdownObject,
364 public Hysteresis
Matt Spinler8f5e6112021-01-15 10:44:32 -0600365{
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600366 static constexpr auto name = "SoftShutdown";
Amithash Prasadb3f59462025-06-02 21:22:13 -0700367
Amithash Prasad7d2f3232025-06-02 20:31:48 -0700368 /** @brief sdbusplus bus client connection. */
369 sdbusplus::bus_t& bus;
370 std::string objPath;
371 Unit units;
372
Amithash Prasadb3f59462025-06-02 21:22:13 -0700373 using SoftShutdownObject::SoftShutdownObject;
374 using ReadingAboveUpperSoftShutdownThreshold =
375 sdbusplus::error::xyz::openbmc_project::sensor::Threshold::
376 ReadingAboveUpperSoftShutdownThreshold;
377 using ReadingBelowLowerSoftShutdownThreshold =
378 sdbusplus::error::xyz::openbmc_project::sensor::Threshold::
379 ReadingBelowLowerSoftShutdownThreshold;
380 std::optional<sdbusplus::message::object_path> assertedHighLog;
381 std::optional<sdbusplus::message::object_path> assertedLowLog;
382
Amithash Prasad7d2f3232025-06-02 20:31:48 -0700383 /** @brief Constructor to put object onto bus at a dbus path.
384 * @param[in] bus - Bus to attach to.
385 * @param[in] path - Path to attach at.
386 * @param[in] units - units
387 */
388 Threshold(sdbusplus::bus_t& bus, const char* path, Unit units) :
389 SoftShutdownObject(bus, path), bus(bus), objPath(std::string(path)),
390 units(units)
391 {}
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600392
393 auto high()
Matt Spinler8f5e6112021-01-15 10:44:32 -0600394 {
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600395 return softShutdownHigh();
Matt Spinler8f5e6112021-01-15 10:44:32 -0600396 }
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600397 auto low()
Matt Spinler8f5e6112021-01-15 10:44:32 -0600398 {
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600399 return softShutdownLow();
Matt Spinler8f5e6112021-01-15 10:44:32 -0600400 }
401
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600402 template <typename... Args>
403 auto alarmHigh(Args... args)
Matt Spinler8f5e6112021-01-15 10:44:32 -0600404 {
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600405 return softShutdownAlarmHigh(std::forward<Args>(args)...);
Matt Spinler8f5e6112021-01-15 10:44:32 -0600406 }
407
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600408 template <typename... Args>
409 auto alarmLow(Args... args)
Matt Spinler8f5e6112021-01-15 10:44:32 -0600410 {
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600411 return softShutdownAlarmLow(std::forward<Args>(args)...);
Matt Spinler8f5e6112021-01-15 10:44:32 -0600412 }
George Hung4294e6d2021-04-14 20:58:21 +0800413
Amithash Prasadb3f59462025-06-02 21:22:13 -0700414 template <typename V>
415 auto alarmHighSignalAsserted(V value)
George Hung4294e6d2021-04-14 20:58:21 +0800416 {
Amithash Prasadb3f59462025-06-02 21:22:13 -0700417 assertedHighLog = tryCommit<ReadingAboveUpperSoftShutdownThreshold>(
418 objPath, value, units, high());
419 return softShutdownHighAlarmAsserted(value);
George Hung4294e6d2021-04-14 20:58:21 +0800420 }
421
422 template <typename... Args>
423 auto alarmHighSignalDeasserted(Args... args)
424 {
Amithash Prasadb3f59462025-06-02 21:22:13 -0700425 tryResolve(assertedHighLog);
George Hung4294e6d2021-04-14 20:58:21 +0800426 return softShutdownHighAlarmDeasserted(std::forward<Args>(args)...);
427 }
428
Amithash Prasadb3f59462025-06-02 21:22:13 -0700429 template <typename V>
430 auto alarmLowSignalAsserted(V value)
George Hung4294e6d2021-04-14 20:58:21 +0800431 {
Amithash Prasadb3f59462025-06-02 21:22:13 -0700432 assertedLowLog = tryCommit<ReadingBelowLowerSoftShutdownThreshold>(
433 objPath, value, units, low());
434 return softShutdownLowAlarmAsserted(value);
George Hung4294e6d2021-04-14 20:58:21 +0800435 }
436
437 template <typename... Args>
438 auto alarmLowSignalDeasserted(Args... args)
439 {
Amithash Prasadb3f59462025-06-02 21:22:13 -0700440 tryResolve(assertedLowLog);
George Hung4294e6d2021-04-14 20:58:21 +0800441 return softShutdownLowAlarmDeasserted(std::forward<Args>(args)...);
442 }
Matt Spinler8f5e6112021-01-15 10:44:32 -0600443};
444
445template <>
Rashmica Gupta1dff7dc2021-07-27 19:43:31 +1000446struct Threshold<HardShutdownObject> :
447 public HardShutdownObject,
448 public Hysteresis
Matt Spinler8f5e6112021-01-15 10:44:32 -0600449{
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600450 static constexpr auto name = "HardShutdown";
Amithash Prasadb3f59462025-06-02 21:22:13 -0700451
Amithash Prasad7d2f3232025-06-02 20:31:48 -0700452 /** @brief sdbusplus bus client connection. */
453 sdbusplus::bus_t& bus;
454 std::string objPath;
455 Unit units;
456
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600457 using HardShutdownObject::HardShutdownObject;
Amithash Prasadb3f59462025-06-02 21:22:13 -0700458 using ReadingAboveUpperHardShutdownThreshold =
459 sdbusplus::error::xyz::openbmc_project::sensor::Threshold::
460 ReadingAboveUpperHardShutdownThreshold;
461 using ReadingBelowLowerHardShutdownThreshold =
462 sdbusplus::error::xyz::openbmc_project::sensor::Threshold::
463 ReadingBelowLowerHardShutdownThreshold;
464 std::optional<sdbusplus::message::object_path> assertedHighLog;
465 std::optional<sdbusplus::message::object_path> assertedLowLog;
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600466
Amithash Prasad7d2f3232025-06-02 20:31:48 -0700467 /** @brief Constructor to put object onto bus at a dbus path.
468 * @param[in] bus - Bus to attach to.
469 * @param[in] path - Path to attach at.
470 * @param[in] units - units
471 */
472 Threshold(sdbusplus::bus_t& bus, const char* path, Unit units) :
473 HardShutdownObject(bus, path), bus(bus), objPath(std::string(path)),
474 units(units)
475 {}
476
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600477 auto high()
Matt Spinler8f5e6112021-01-15 10:44:32 -0600478 {
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600479 return hardShutdownHigh();
Matt Spinler8f5e6112021-01-15 10:44:32 -0600480 }
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600481 auto low()
Matt Spinler8f5e6112021-01-15 10:44:32 -0600482 {
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600483 return hardShutdownLow();
Matt Spinler8f5e6112021-01-15 10:44:32 -0600484 }
485
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600486 template <typename... Args>
487 auto alarmHigh(Args... args)
Matt Spinler8f5e6112021-01-15 10:44:32 -0600488 {
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600489 return hardShutdownAlarmHigh(std::forward<Args>(args)...);
Matt Spinler8f5e6112021-01-15 10:44:32 -0600490 }
491
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600492 template <typename... Args>
493 auto alarmLow(Args... args)
Matt Spinler8f5e6112021-01-15 10:44:32 -0600494 {
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600495 return hardShutdownAlarmLow(std::forward<Args>(args)...);
Matt Spinler8f5e6112021-01-15 10:44:32 -0600496 }
George Hung4294e6d2021-04-14 20:58:21 +0800497
Amithash Prasadb3f59462025-06-02 21:22:13 -0700498 template <typename V>
499 auto alarmHighSignalAsserted(V value)
George Hung4294e6d2021-04-14 20:58:21 +0800500 {
Amithash Prasadb3f59462025-06-02 21:22:13 -0700501 assertedHighLog = tryCommit<ReadingAboveUpperHardShutdownThreshold>(
502 objPath, value, units, high());
503 return hardShutdownHighAlarmAsserted(value);
George Hung4294e6d2021-04-14 20:58:21 +0800504 }
505
506 template <typename... Args>
507 auto alarmHighSignalDeasserted(Args... args)
508 {
Amithash Prasadb3f59462025-06-02 21:22:13 -0700509 tryResolve(assertedHighLog);
George Hung4294e6d2021-04-14 20:58:21 +0800510 return hardShutdownHighAlarmDeasserted(std::forward<Args>(args)...);
511 }
512
Amithash Prasadb3f59462025-06-02 21:22:13 -0700513 template <typename V>
514 auto alarmLowSignalAsserted(V value)
George Hung4294e6d2021-04-14 20:58:21 +0800515 {
Amithash Prasadb3f59462025-06-02 21:22:13 -0700516 assertedLowLog = tryCommit<ReadingBelowLowerHardShutdownThreshold>(
517 objPath, value, units, low());
518 return hardShutdownLowAlarmAsserted(value);
George Hung4294e6d2021-04-14 20:58:21 +0800519 }
520
521 template <typename... Args>
522 auto alarmLowSignalDeasserted(Args... args)
523 {
Amithash Prasadb3f59462025-06-02 21:22:13 -0700524 tryResolve(assertedLowLog);
George Hung4294e6d2021-04-14 20:58:21 +0800525 return hardShutdownLowAlarmDeasserted(std::forward<Args>(args)...);
526 }
Matt Spinler8f5e6112021-01-15 10:44:32 -0600527};
528
Matt Spinlerb306b032021-02-01 10:05:46 -0600529template <>
Rashmica Gupta1dff7dc2021-07-27 19:43:31 +1000530struct Threshold<PerformanceLossObject> :
531 public PerformanceLossObject,
532 public Hysteresis
Matt Spinlerb306b032021-02-01 10:05:46 -0600533{
534 static constexpr auto name = "PerformanceLoss";
Amithash Prasad7d2f3232025-06-02 20:31:48 -0700535 /** @brief sdbusplus bus client connection. */
536 sdbusplus::bus_t& bus;
537 std::string objPath;
538 Unit units;
539
Matt Spinlerb306b032021-02-01 10:05:46 -0600540 using PerformanceLossObject::PerformanceLossObject;
Amithash Prasadb3f59462025-06-02 21:22:13 -0700541 using ReadingAboveUpperPerformanceLossThreshold =
542 sdbusplus::error::xyz::openbmc_project::sensor::Threshold::
543 ReadingAboveUpperPerformanceLossThreshold;
544 using ReadingBelowLowerPerformanceLossThreshold =
545 sdbusplus::error::xyz::openbmc_project::sensor::Threshold::
546 ReadingBelowLowerPerformanceLossThreshold;
Rashmica Gupta1dff7dc2021-07-27 19:43:31 +1000547 double performanceLossHighHysteresis;
548 double performanceLossLowHysteresis;
Amithash Prasadb3f59462025-06-02 21:22:13 -0700549 std::optional<sdbusplus::message::object_path> assertedHighLog;
550 std::optional<sdbusplus::message::object_path> assertedLowLog;
Matt Spinlerb306b032021-02-01 10:05:46 -0600551
Amithash Prasad7d2f3232025-06-02 20:31:48 -0700552 /** @brief Constructor to put object onto bus at a dbus path.
553 * @param[in] bus - Bus to attach to.
554 * @param[in] path - Path to attach at.
555 * @param[in] units - units
556 */
557 Threshold(sdbusplus::bus_t& bus, const char* path, Unit units) :
558 PerformanceLossObject(bus, path), bus(bus), objPath(std::string(path)),
559 units(units)
560 {}
561
Matt Spinlerb306b032021-02-01 10:05:46 -0600562 auto high()
563 {
564 return performanceLossHigh();
565 }
566 auto low()
567 {
568 return performanceLossLow();
569 }
570
571 template <typename... Args>
572 auto alarmHigh(Args... args)
573 {
574 return performanceLossAlarmHigh(std::forward<Args>(args)...);
575 }
576
577 template <typename... Args>
578 auto alarmLow(Args... args)
579 {
580 return performanceLossAlarmLow(std::forward<Args>(args)...);
581 }
George Hung4294e6d2021-04-14 20:58:21 +0800582
Amithash Prasadb3f59462025-06-02 21:22:13 -0700583 template <typename V>
584 auto alarmHighSignalAsserted(V value)
George Hung4294e6d2021-04-14 20:58:21 +0800585 {
Amithash Prasadb3f59462025-06-02 21:22:13 -0700586 assertedHighLog = tryCommit<ReadingAboveUpperPerformanceLossThreshold>(
587 objPath, value, units, high());
588 return performanceLossHighAlarmAsserted(value);
George Hung4294e6d2021-04-14 20:58:21 +0800589 }
590
591 template <typename... Args>
592 auto alarmHighSignalDeasserted(Args... args)
593 {
Amithash Prasadb3f59462025-06-02 21:22:13 -0700594 tryResolve(assertedHighLog);
George Hung4294e6d2021-04-14 20:58:21 +0800595 return performanceLossHighAlarmDeasserted(std::forward<Args>(args)...);
596 }
597
Amithash Prasadb3f59462025-06-02 21:22:13 -0700598 template <typename V>
599 auto alarmLowSignalAsserted(V value)
George Hung4294e6d2021-04-14 20:58:21 +0800600 {
Amithash Prasadb3f59462025-06-02 21:22:13 -0700601 assertedLowLog = tryCommit<ReadingBelowLowerPerformanceLossThreshold>(
602 objPath, value, units, low());
603 return performanceLossLowAlarmAsserted(value);
George Hung4294e6d2021-04-14 20:58:21 +0800604 }
605
606 template <typename... Args>
607 auto alarmLowSignalDeasserted(Args... args)
608 {
Amithash Prasadb3f59462025-06-02 21:22:13 -0700609 tryResolve(assertedLowLog);
George Hung4294e6d2021-04-14 20:58:21 +0800610 return performanceLossLowAlarmDeasserted(std::forward<Args>(args)...);
611 }
Matt Spinlerb306b032021-02-01 10:05:46 -0600612};
613
Tao Linf2e94222023-10-31 17:38:17 +0800614} // namespace phosphor::virtual_sensor