blob: 114138fd229a5e75af43b45898bc443a49c514c1 [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
Matt Spinler8f5e6112021-01-15 10:44:32 -06005#include <xyz/openbmc_project/Sensor/Threshold/Critical/server.hpp>
6#include <xyz/openbmc_project/Sensor/Threshold/HardShutdown/server.hpp>
Matt Spinlerb306b032021-02-01 10:05:46 -06007#include <xyz/openbmc_project/Sensor/Threshold/PerformanceLoss/server.hpp>
Matt Spinler8f5e6112021-01-15 10:44:32 -06008#include <xyz/openbmc_project/Sensor/Threshold/SoftShutdown/server.hpp>
9#include <xyz/openbmc_project/Sensor/Threshold/Warning/server.hpp>
10
Tao Linf2e94222023-10-31 17:38:17 +080011const constexpr char* entityManagerBusName =
12 "xyz.openbmc_project.EntityManager";
13namespace phosphor::virtual_sensor
Matt Spinler8f5e6112021-01-15 10:44:32 -060014{
15
16template <typename... T>
Patrick Williams8e11ccc2022-07-22 19:26:57 -050017using ServerObject = typename sdbusplus::server::object_t<T...>;
Matt Spinler8f5e6112021-01-15 10:44:32 -060018
Patrick Williamsfdb826d2021-01-20 14:37:53 -060019namespace threshold_ns =
20 sdbusplus::xyz::openbmc_project::Sensor::Threshold::server;
21using CriticalObject = ServerObject<threshold_ns::Critical>;
22using WarningObject = ServerObject<threshold_ns::Warning>;
23using SoftShutdownObject = ServerObject<threshold_ns::SoftShutdown>;
24using HardShutdownObject = ServerObject<threshold_ns::HardShutdown>;
Matt Spinlerb306b032021-02-01 10:05:46 -060025using PerformanceLossObject = ServerObject<threshold_ns::PerformanceLoss>;
Matt Spinler8f5e6112021-01-15 10:44:32 -060026
27template <typename T>
Patrick Williamsfdb826d2021-01-20 14:37:53 -060028struct Threshold;
Matt Spinler8f5e6112021-01-15 10:44:32 -060029
Rashmica Gupta1dff7dc2021-07-27 19:43:31 +100030struct Hysteresis
31{
32 double highHysteresis;
33 double lowHysteresis;
34 auto getHighHysteresis()
35 {
36 return this->highHysteresis;
37 }
38
39 auto getLowHysteresis()
40 {
41 return this->lowHysteresis;
42 }
43
44 auto setHighHysteresis(double value)
45 {
46 this->highHysteresis = value;
47 }
48
49 auto setLowHysteresis(double value)
50 {
51 this->lowHysteresis = value;
52 }
53};
54
Matt Spinler8f5e6112021-01-15 10:44:32 -060055template <>
Rashmica Gupta1dff7dc2021-07-27 19:43:31 +100056struct Threshold<WarningObject> : public WarningObject, public Hysteresis
Matt Spinler8f5e6112021-01-15 10:44:32 -060057{
Patrick Williamsfdb826d2021-01-20 14:37:53 -060058 static constexpr auto name = "Warning";
59 using WarningObject::WarningObject;
Tao Lin91799db2022-07-27 21:02:20 +080060 /** @brief sdbusplus bus client connection. */
Patrick Williams83e3ac32022-11-26 09:41:58 -060061 sdbusplus::bus_t& bus;
Tao Lin91799db2022-07-27 21:02:20 +080062 std::string objPath;
63
64 /** @brief Virtual sensor path/interface in entityManagerDbus.
65 * This 3 value is used to set thresholds
66 */
67 std::string entityPath;
68 std::string entityInterfaceHigh;
69 std::string entityInterfaceLow;
70
71 /** @brief Constructor to put object onto bus at a dbus path.
72 * @param[in] bus - Bus to attach to.
73 * @param[in] path - Path to attach at.
74 */
Patrick Williams83e3ac32022-11-26 09:41:58 -060075 Threshold(sdbusplus::bus_t& bus, const char* path) :
Tao Lin91799db2022-07-27 21:02:20 +080076 WarningObject(bus, path), bus(bus), objPath(std::string(path))
77 {}
Patrick Williamsfdb826d2021-01-20 14:37:53 -060078
79 auto high()
Matt Spinler8f5e6112021-01-15 10:44:32 -060080 {
Tao Lin91799db2022-07-27 21:02:20 +080081 return WarningObject::warningHigh();
Matt Spinler8f5e6112021-01-15 10:44:32 -060082 }
Patrick Williamsfdb826d2021-01-20 14:37:53 -060083 auto low()
Matt Spinler8f5e6112021-01-15 10:44:32 -060084 {
Tao Lin91799db2022-07-27 21:02:20 +080085 return WarningObject::warningLow();
Matt Spinler8f5e6112021-01-15 10:44:32 -060086 }
87
Patrick Williamsfdb826d2021-01-20 14:37:53 -060088 template <typename... Args>
89 auto alarmHigh(Args... args)
Matt Spinler8f5e6112021-01-15 10:44:32 -060090 {
Patrick Williamsfdb826d2021-01-20 14:37:53 -060091 return warningAlarmHigh(std::forward<Args>(args)...);
Matt Spinler8f5e6112021-01-15 10:44:32 -060092 }
93
Patrick Williamsfdb826d2021-01-20 14:37:53 -060094 template <typename... Args>
95 auto alarmLow(Args... args)
Matt Spinler8f5e6112021-01-15 10:44:32 -060096 {
Patrick Williamsfdb826d2021-01-20 14:37:53 -060097 return warningAlarmLow(std::forward<Args>(args)...);
Matt Spinler8f5e6112021-01-15 10:44:32 -060098 }
George Hung4294e6d2021-04-14 20:58:21 +080099
100 template <typename... Args>
101 auto alarmHighSignalAsserted(Args... args)
102 {
103 return warningHighAlarmAsserted(std::forward<Args>(args)...);
104 }
105
106 template <typename... Args>
107 auto alarmHighSignalDeasserted(Args... args)
108 {
109 return warningHighAlarmDeasserted(std::forward<Args>(args)...);
110 }
111
112 template <typename... Args>
113 auto alarmLowSignalAsserted(Args... args)
114 {
115 return warningLowAlarmAsserted(std::forward<Args>(args)...);
116 }
117
118 template <typename... Args>
119 auto alarmLowSignalDeasserted(Args... args)
120 {
121 return warningLowAlarmDeasserted(std::forward<Args>(args)...);
122 }
Tao Lin91799db2022-07-27 21:02:20 +0800123
124 /** @brief Set value of WarningHigh */
125 virtual double warningHigh(double value)
126 {
Matt Spinlera291ce12023-02-06 15:12:44 -0600127 if (!entityPath.empty() && !entityInterfaceHigh.empty())
128 {
129 // persistThreshold
130 setDbusProperty(bus, entityManagerBusName, entityPath,
131 entityInterfaceHigh, "Value", value);
132 }
Tao Lin91799db2022-07-27 21:02:20 +0800133 return WarningObject::warningHigh(value);
134 }
135
136 /** @brief Set value of WarningLow */
137 virtual double warningLow(double value)
138 {
Matt Spinlera291ce12023-02-06 15:12:44 -0600139 if (!entityPath.empty() && !entityInterfaceLow.empty())
140 {
141 // persistThreshold
142 setDbusProperty(bus, entityManagerBusName, entityPath,
143 entityInterfaceLow, "Value", value);
144 }
Tao Lin91799db2022-07-27 21:02:20 +0800145 return WarningObject::warningLow(value);
146 }
147
148 /** @brief Set the entitymanager interface corresponding to virtualsensor
149 * warningLow
150 */
151 void setEntityInterfaceLow(const std::string& interfaceLow)
152 {
153 entityInterfaceLow = interfaceLow;
154 }
155
156 /** @brief Set the entitymanager interface corresponding to virtualsensor
157 * warningHigh
158 */
159 void setEntityInterfaceHigh(const std::string& interfaceHigh)
160 {
161 entityInterfaceHigh = interfaceHigh;
162 }
163
164 /** @brief Set the entitymanager path corresponding to virtualsensor warning
165 */
166 void setEntityPath(const std::string& path)
167 {
168 entityPath = path;
169 }
Matt Spinler8f5e6112021-01-15 10:44:32 -0600170};
171
172template <>
Rashmica Gupta1dff7dc2021-07-27 19:43:31 +1000173struct Threshold<CriticalObject> : public CriticalObject, public Hysteresis
Matt Spinler8f5e6112021-01-15 10:44:32 -0600174{
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600175 static constexpr auto name = "Critical";
Tao Lin91799db2022-07-27 21:02:20 +0800176
177 /** @brief sdbusplus bus client connection. */
Patrick Williams83e3ac32022-11-26 09:41:58 -0600178 sdbusplus::bus_t& bus;
Tao Lin91799db2022-07-27 21:02:20 +0800179 std::string objPath;
180
181 /** @brief Virtual sensor path/interface in entityManagerDbus.
182 * This 3 value is used to set thresholds
183 */
184 std::string entityPath;
185 std::string entityInterfaceHigh;
186 std::string entityInterfaceLow;
187
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600188 using CriticalObject::CriticalObject;
189
Tao Lin91799db2022-07-27 21:02:20 +0800190 /** @brief Constructor to put object onto bus at a dbus path.
191 * @param[in] bus - Bus to attach to.
192 * @param[in] path - Path to attach at.
193 */
Patrick Williams83e3ac32022-11-26 09:41:58 -0600194 Threshold(sdbusplus::bus_t& bus, const char* path) :
Tao Lin91799db2022-07-27 21:02:20 +0800195 CriticalObject(bus, path), bus(bus), objPath(std::string(path))
196 {}
197
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600198 auto high()
Matt Spinler8f5e6112021-01-15 10:44:32 -0600199 {
Tao Lin91799db2022-07-27 21:02:20 +0800200 return CriticalObject::criticalHigh();
Matt Spinler8f5e6112021-01-15 10:44:32 -0600201 }
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600202 auto low()
Matt Spinler8f5e6112021-01-15 10:44:32 -0600203 {
Tao Lin91799db2022-07-27 21:02:20 +0800204 return CriticalObject::criticalLow();
Matt Spinler8f5e6112021-01-15 10:44:32 -0600205 }
206
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600207 template <typename... Args>
208 auto alarmHigh(Args... args)
Matt Spinler8f5e6112021-01-15 10:44:32 -0600209 {
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600210 return criticalAlarmHigh(std::forward<Args>(args)...);
Matt Spinler8f5e6112021-01-15 10:44:32 -0600211 }
212
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600213 template <typename... Args>
214 auto alarmLow(Args... args)
Matt Spinler8f5e6112021-01-15 10:44:32 -0600215 {
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600216 return criticalAlarmLow(std::forward<Args>(args)...);
Matt Spinler8f5e6112021-01-15 10:44:32 -0600217 }
George Hung4294e6d2021-04-14 20:58:21 +0800218
219 template <typename... Args>
220 auto alarmHighSignalAsserted(Args... args)
221 {
222 return criticalHighAlarmAsserted(std::forward<Args>(args)...);
223 }
224
225 template <typename... Args>
226 auto alarmHighSignalDeasserted(Args... args)
227 {
228 return criticalHighAlarmDeasserted(std::forward<Args>(args)...);
229 }
230
231 template <typename... Args>
232 auto alarmLowSignalAsserted(Args... args)
233 {
234 return criticalLowAlarmAsserted(std::forward<Args>(args)...);
235 }
236
237 template <typename... Args>
238 auto alarmLowSignalDeasserted(Args... args)
239 {
240 return criticalLowAlarmDeasserted(std::forward<Args>(args)...);
241 }
Tao Lin91799db2022-07-27 21:02:20 +0800242
243 /** @brief Set value of CriticalHigh */
244 virtual double criticalHigh(double value)
245 {
246 // persistThreshold
Matt Spinlera291ce12023-02-06 15:12:44 -0600247 if (!entityPath.empty() && !entityInterfaceHigh.empty())
248 {
249 setDbusProperty(bus, entityManagerBusName, entityPath,
250 entityInterfaceHigh, "Value", value);
251 }
Tao Lin91799db2022-07-27 21:02:20 +0800252 return CriticalObject::criticalHigh(value);
253 }
254
255 /** @brief Set value of CriticalLow */
256 virtual double criticalLow(double value)
257 {
Matt Spinlera291ce12023-02-06 15:12:44 -0600258 if (!entityPath.empty() && !entityInterfaceLow.empty())
259 {
260 setDbusProperty(bus, entityManagerBusName, entityPath,
261 entityInterfaceLow, "Value", value);
262 }
Tao Lin91799db2022-07-27 21:02:20 +0800263 return CriticalObject::criticalLow(value);
264 }
265
266 /** @brief Set the entitymanager interface corresponding to virtualsensor
267 * criticalLow
268 */
269 void setEntityInterfaceLow(const std::string& interfaceLow)
270 {
271 entityInterfaceLow = interfaceLow;
272 }
273
274 /** @brief Set the entitymanager interface corresponding to virtualsensor
275 * criticalLow
276 */
277 void setEntityInterfaceHigh(const std::string& interfaceHigh)
278 {
279 entityInterfaceHigh = interfaceHigh;
280 }
281
282 /** @brief Set the entitymanager path corresponding to virtualsensor warning
283 */
284 void setEntityPath(const std::string& path)
285 {
286 entityPath = path;
287 }
Matt Spinler8f5e6112021-01-15 10:44:32 -0600288};
289
290template <>
Rashmica Gupta1dff7dc2021-07-27 19:43:31 +1000291struct Threshold<SoftShutdownObject> :
292 public SoftShutdownObject,
293 public Hysteresis
Matt Spinler8f5e6112021-01-15 10:44:32 -0600294{
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600295 static constexpr auto name = "SoftShutdown";
296 using SoftShutdownObject::SoftShutdownObject;
297
298 auto high()
Matt Spinler8f5e6112021-01-15 10:44:32 -0600299 {
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600300 return softShutdownHigh();
Matt Spinler8f5e6112021-01-15 10:44:32 -0600301 }
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600302 auto low()
Matt Spinler8f5e6112021-01-15 10:44:32 -0600303 {
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600304 return softShutdownLow();
Matt Spinler8f5e6112021-01-15 10:44:32 -0600305 }
306
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600307 template <typename... Args>
308 auto alarmHigh(Args... args)
Matt Spinler8f5e6112021-01-15 10:44:32 -0600309 {
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600310 return softShutdownAlarmHigh(std::forward<Args>(args)...);
Matt Spinler8f5e6112021-01-15 10:44:32 -0600311 }
312
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600313 template <typename... Args>
314 auto alarmLow(Args... args)
Matt Spinler8f5e6112021-01-15 10:44:32 -0600315 {
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600316 return softShutdownAlarmLow(std::forward<Args>(args)...);
Matt Spinler8f5e6112021-01-15 10:44:32 -0600317 }
George Hung4294e6d2021-04-14 20:58:21 +0800318
319 template <typename... Args>
320 auto alarmHighSignalAsserted(Args... args)
321 {
322 return softShutdownHighAlarmAsserted(std::forward<Args>(args)...);
323 }
324
325 template <typename... Args>
326 auto alarmHighSignalDeasserted(Args... args)
327 {
328 return softShutdownHighAlarmDeasserted(std::forward<Args>(args)...);
329 }
330
331 template <typename... Args>
332 auto alarmLowSignalAsserted(Args... args)
333 {
334 return softShutdownLowAlarmAsserted(std::forward<Args>(args)...);
335 }
336
337 template <typename... Args>
338 auto alarmLowSignalDeasserted(Args... args)
339 {
340 return softShutdownLowAlarmDeasserted(std::forward<Args>(args)...);
341 }
Matt Spinler8f5e6112021-01-15 10:44:32 -0600342};
343
344template <>
Rashmica Gupta1dff7dc2021-07-27 19:43:31 +1000345struct Threshold<HardShutdownObject> :
346 public HardShutdownObject,
347 public Hysteresis
Matt Spinler8f5e6112021-01-15 10:44:32 -0600348{
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600349 static constexpr auto name = "HardShutdown";
350 using HardShutdownObject::HardShutdownObject;
351
352 auto high()
Matt Spinler8f5e6112021-01-15 10:44:32 -0600353 {
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600354 return hardShutdownHigh();
Matt Spinler8f5e6112021-01-15 10:44:32 -0600355 }
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600356 auto low()
Matt Spinler8f5e6112021-01-15 10:44:32 -0600357 {
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600358 return hardShutdownLow();
Matt Spinler8f5e6112021-01-15 10:44:32 -0600359 }
360
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600361 template <typename... Args>
362 auto alarmHigh(Args... args)
Matt Spinler8f5e6112021-01-15 10:44:32 -0600363 {
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600364 return hardShutdownAlarmHigh(std::forward<Args>(args)...);
Matt Spinler8f5e6112021-01-15 10:44:32 -0600365 }
366
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600367 template <typename... Args>
368 auto alarmLow(Args... args)
Matt Spinler8f5e6112021-01-15 10:44:32 -0600369 {
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600370 return hardShutdownAlarmLow(std::forward<Args>(args)...);
Matt Spinler8f5e6112021-01-15 10:44:32 -0600371 }
George Hung4294e6d2021-04-14 20:58:21 +0800372
373 template <typename... Args>
374 auto alarmHighSignalAsserted(Args... args)
375 {
376 return hardShutdownHighAlarmAsserted(std::forward<Args>(args)...);
377 }
378
379 template <typename... Args>
380 auto alarmHighSignalDeasserted(Args... args)
381 {
382 return hardShutdownHighAlarmDeasserted(std::forward<Args>(args)...);
383 }
384
385 template <typename... Args>
386 auto alarmLowSignalAsserted(Args... args)
387 {
388 return hardShutdownLowAlarmAsserted(std::forward<Args>(args)...);
389 }
390
391 template <typename... Args>
392 auto alarmLowSignalDeasserted(Args... args)
393 {
394 return hardShutdownLowAlarmDeasserted(std::forward<Args>(args)...);
395 }
Matt Spinler8f5e6112021-01-15 10:44:32 -0600396};
397
Matt Spinlerb306b032021-02-01 10:05:46 -0600398template <>
Rashmica Gupta1dff7dc2021-07-27 19:43:31 +1000399struct Threshold<PerformanceLossObject> :
400 public PerformanceLossObject,
401 public Hysteresis
Matt Spinlerb306b032021-02-01 10:05:46 -0600402{
403 static constexpr auto name = "PerformanceLoss";
404 using PerformanceLossObject::PerformanceLossObject;
Rashmica Gupta1dff7dc2021-07-27 19:43:31 +1000405 double performanceLossHighHysteresis;
406 double performanceLossLowHysteresis;
Matt Spinlerb306b032021-02-01 10:05:46 -0600407
408 auto high()
409 {
410 return performanceLossHigh();
411 }
412 auto low()
413 {
414 return performanceLossLow();
415 }
416
417 template <typename... Args>
418 auto alarmHigh(Args... args)
419 {
420 return performanceLossAlarmHigh(std::forward<Args>(args)...);
421 }
422
423 template <typename... Args>
424 auto alarmLow(Args... args)
425 {
426 return performanceLossAlarmLow(std::forward<Args>(args)...);
427 }
George Hung4294e6d2021-04-14 20:58:21 +0800428
429 template <typename... Args>
430 auto alarmHighSignalAsserted(Args... args)
431 {
432 return performanceLossHighAlarmAsserted(std::forward<Args>(args)...);
433 }
434
435 template <typename... Args>
436 auto alarmHighSignalDeasserted(Args... args)
437 {
438 return performanceLossHighAlarmDeasserted(std::forward<Args>(args)...);
439 }
440
441 template <typename... Args>
442 auto alarmLowSignalAsserted(Args... args)
443 {
444 return performanceLossLowAlarmAsserted(std::forward<Args>(args)...);
445 }
446
447 template <typename... Args>
448 auto alarmLowSignalDeasserted(Args... args)
449 {
450 return performanceLossLowAlarmDeasserted(std::forward<Args>(args)...);
451 }
Matt Spinlerb306b032021-02-01 10:05:46 -0600452};
453
Tao Linf2e94222023-10-31 17:38:17 +0800454} // namespace phosphor::virtual_sensor