blob: 63e1884be1961727a70f6da16d3179e0048ca03c [file] [log] [blame]
Matt Spinler8f5e6112021-01-15 10:44:32 -06001#pragma once
2
3#include <xyz/openbmc_project/Sensor/Threshold/Critical/server.hpp>
4#include <xyz/openbmc_project/Sensor/Threshold/HardShutdown/server.hpp>
Matt Spinlerb306b032021-02-01 10:05:46 -06005#include <xyz/openbmc_project/Sensor/Threshold/PerformanceLoss/server.hpp>
Matt Spinler8f5e6112021-01-15 10:44:32 -06006#include <xyz/openbmc_project/Sensor/Threshold/SoftShutdown/server.hpp>
7#include <xyz/openbmc_project/Sensor/Threshold/Warning/server.hpp>
8
9namespace phosphor::virtualSensor
10{
11
12template <typename... T>
Patrick Williams8e11ccc2022-07-22 19:26:57 -050013using ServerObject = typename sdbusplus::server::object_t<T...>;
Matt Spinler8f5e6112021-01-15 10:44:32 -060014
Patrick Williamsfdb826d2021-01-20 14:37:53 -060015namespace threshold_ns =
16 sdbusplus::xyz::openbmc_project::Sensor::Threshold::server;
17using CriticalObject = ServerObject<threshold_ns::Critical>;
18using WarningObject = ServerObject<threshold_ns::Warning>;
19using SoftShutdownObject = ServerObject<threshold_ns::SoftShutdown>;
20using HardShutdownObject = ServerObject<threshold_ns::HardShutdown>;
Matt Spinlerb306b032021-02-01 10:05:46 -060021using PerformanceLossObject = ServerObject<threshold_ns::PerformanceLoss>;
Matt Spinler8f5e6112021-01-15 10:44:32 -060022
23template <typename T>
Patrick Williamsfdb826d2021-01-20 14:37:53 -060024struct Threshold;
Matt Spinler8f5e6112021-01-15 10:44:32 -060025
Rashmica Gupta1dff7dc2021-07-27 19:43:31 +100026struct Hysteresis
27{
28 double highHysteresis;
29 double lowHysteresis;
30 auto getHighHysteresis()
31 {
32 return this->highHysteresis;
33 }
34
35 auto getLowHysteresis()
36 {
37 return this->lowHysteresis;
38 }
39
40 auto setHighHysteresis(double value)
41 {
42 this->highHysteresis = value;
43 }
44
45 auto setLowHysteresis(double value)
46 {
47 this->lowHysteresis = value;
48 }
49};
50
Matt Spinler8f5e6112021-01-15 10:44:32 -060051template <>
Rashmica Gupta1dff7dc2021-07-27 19:43:31 +100052struct Threshold<WarningObject> : public WarningObject, public Hysteresis
Matt Spinler8f5e6112021-01-15 10:44:32 -060053{
Patrick Williamsfdb826d2021-01-20 14:37:53 -060054 static constexpr auto name = "Warning";
55 using WarningObject::WarningObject;
Tao Lin91799db2022-07-27 21:02:20 +080056 /** @brief sdbusplus bus client connection. */
57 sdbusplus::bus::bus& bus;
58 std::string objPath;
59
60 /** @brief Virtual sensor path/interface in entityManagerDbus.
61 * This 3 value is used to set thresholds
62 */
63 std::string entityPath;
64 std::string entityInterfaceHigh;
65 std::string entityInterfaceLow;
66
67 /** @brief Constructor to put object onto bus at a dbus path.
68 * @param[in] bus - Bus to attach to.
69 * @param[in] path - Path to attach at.
70 */
71 Threshold(sdbusplus::bus::bus& bus, const char* path) :
72 WarningObject(bus, path), bus(bus), objPath(std::string(path))
73 {}
Patrick Williamsfdb826d2021-01-20 14:37:53 -060074
75 auto high()
Matt Spinler8f5e6112021-01-15 10:44:32 -060076 {
Tao Lin91799db2022-07-27 21:02:20 +080077 return WarningObject::warningHigh();
Matt Spinler8f5e6112021-01-15 10:44:32 -060078 }
Patrick Williamsfdb826d2021-01-20 14:37:53 -060079 auto low()
Matt Spinler8f5e6112021-01-15 10:44:32 -060080 {
Tao Lin91799db2022-07-27 21:02:20 +080081 return WarningObject::warningLow();
Matt Spinler8f5e6112021-01-15 10:44:32 -060082 }
83
Patrick Williamsfdb826d2021-01-20 14:37:53 -060084 template <typename... Args>
85 auto alarmHigh(Args... args)
Matt Spinler8f5e6112021-01-15 10:44:32 -060086 {
Patrick Williamsfdb826d2021-01-20 14:37:53 -060087 return warningAlarmHigh(std::forward<Args>(args)...);
Matt Spinler8f5e6112021-01-15 10:44:32 -060088 }
89
Patrick Williamsfdb826d2021-01-20 14:37:53 -060090 template <typename... Args>
91 auto alarmLow(Args... args)
Matt Spinler8f5e6112021-01-15 10:44:32 -060092 {
Patrick Williamsfdb826d2021-01-20 14:37:53 -060093 return warningAlarmLow(std::forward<Args>(args)...);
Matt Spinler8f5e6112021-01-15 10:44:32 -060094 }
George Hung4294e6d2021-04-14 20:58:21 +080095
96 template <typename... Args>
97 auto alarmHighSignalAsserted(Args... args)
98 {
99 return warningHighAlarmAsserted(std::forward<Args>(args)...);
100 }
101
102 template <typename... Args>
103 auto alarmHighSignalDeasserted(Args... args)
104 {
105 return warningHighAlarmDeasserted(std::forward<Args>(args)...);
106 }
107
108 template <typename... Args>
109 auto alarmLowSignalAsserted(Args... args)
110 {
111 return warningLowAlarmAsserted(std::forward<Args>(args)...);
112 }
113
114 template <typename... Args>
115 auto alarmLowSignalDeasserted(Args... args)
116 {
117 return warningLowAlarmDeasserted(std::forward<Args>(args)...);
118 }
Tao Lin91799db2022-07-27 21:02:20 +0800119
120 /** @brief Set value of WarningHigh */
121 virtual double warningHigh(double value)
122 {
123 // persistThreshold
124 setDbusProperty(bus, entityManagerBusName, entityPath,
125 entityInterfaceHigh, "Value", value);
126 return WarningObject::warningHigh(value);
127 }
128
129 /** @brief Set value of WarningLow */
130 virtual double warningLow(double value)
131 {
132 // persistThreshold
133 setDbusProperty(bus, entityManagerBusName, entityPath,
134 entityInterfaceLow, "Value", value);
135 return WarningObject::warningLow(value);
136 }
137
138 /** @brief Set the entitymanager interface corresponding to virtualsensor
139 * warningLow
140 */
141 void setEntityInterfaceLow(const std::string& interfaceLow)
142 {
143 entityInterfaceLow = interfaceLow;
144 }
145
146 /** @brief Set the entitymanager interface corresponding to virtualsensor
147 * warningHigh
148 */
149 void setEntityInterfaceHigh(const std::string& interfaceHigh)
150 {
151 entityInterfaceHigh = interfaceHigh;
152 }
153
154 /** @brief Set the entitymanager path corresponding to virtualsensor warning
155 */
156 void setEntityPath(const std::string& path)
157 {
158 entityPath = path;
159 }
Matt Spinler8f5e6112021-01-15 10:44:32 -0600160};
161
162template <>
Rashmica Gupta1dff7dc2021-07-27 19:43:31 +1000163struct Threshold<CriticalObject> : public CriticalObject, public Hysteresis
Matt Spinler8f5e6112021-01-15 10:44:32 -0600164{
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600165 static constexpr auto name = "Critical";
Tao Lin91799db2022-07-27 21:02:20 +0800166
167 /** @brief sdbusplus bus client connection. */
168 sdbusplus::bus::bus& bus;
169 std::string objPath;
170
171 /** @brief Virtual sensor path/interface in entityManagerDbus.
172 * This 3 value is used to set thresholds
173 */
174 std::string entityPath;
175 std::string entityInterfaceHigh;
176 std::string entityInterfaceLow;
177
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600178 using CriticalObject::CriticalObject;
179
Tao Lin91799db2022-07-27 21:02:20 +0800180 /** @brief Constructor to put object onto bus at a dbus path.
181 * @param[in] bus - Bus to attach to.
182 * @param[in] path - Path to attach at.
183 */
184 Threshold(sdbusplus::bus::bus& bus, const char* path) :
185 CriticalObject(bus, path), bus(bus), objPath(std::string(path))
186 {}
187
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600188 auto high()
Matt Spinler8f5e6112021-01-15 10:44:32 -0600189 {
Tao Lin91799db2022-07-27 21:02:20 +0800190 return CriticalObject::criticalHigh();
Matt Spinler8f5e6112021-01-15 10:44:32 -0600191 }
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600192 auto low()
Matt Spinler8f5e6112021-01-15 10:44:32 -0600193 {
Tao Lin91799db2022-07-27 21:02:20 +0800194 return CriticalObject::criticalLow();
Matt Spinler8f5e6112021-01-15 10:44:32 -0600195 }
196
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600197 template <typename... Args>
198 auto alarmHigh(Args... args)
Matt Spinler8f5e6112021-01-15 10:44:32 -0600199 {
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600200 return criticalAlarmHigh(std::forward<Args>(args)...);
Matt Spinler8f5e6112021-01-15 10:44:32 -0600201 }
202
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600203 template <typename... Args>
204 auto alarmLow(Args... args)
Matt Spinler8f5e6112021-01-15 10:44:32 -0600205 {
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600206 return criticalAlarmLow(std::forward<Args>(args)...);
Matt Spinler8f5e6112021-01-15 10:44:32 -0600207 }
George Hung4294e6d2021-04-14 20:58:21 +0800208
209 template <typename... Args>
210 auto alarmHighSignalAsserted(Args... args)
211 {
212 return criticalHighAlarmAsserted(std::forward<Args>(args)...);
213 }
214
215 template <typename... Args>
216 auto alarmHighSignalDeasserted(Args... args)
217 {
218 return criticalHighAlarmDeasserted(std::forward<Args>(args)...);
219 }
220
221 template <typename... Args>
222 auto alarmLowSignalAsserted(Args... args)
223 {
224 return criticalLowAlarmAsserted(std::forward<Args>(args)...);
225 }
226
227 template <typename... Args>
228 auto alarmLowSignalDeasserted(Args... args)
229 {
230 return criticalLowAlarmDeasserted(std::forward<Args>(args)...);
231 }
Tao Lin91799db2022-07-27 21:02:20 +0800232
233 /** @brief Set value of CriticalHigh */
234 virtual double criticalHigh(double value)
235 {
236 // persistThreshold
237 setDbusProperty(bus, entityManagerBusName, entityPath,
238 entityInterfaceHigh, "Value", value);
239 return CriticalObject::criticalHigh(value);
240 }
241
242 /** @brief Set value of CriticalLow */
243 virtual double criticalLow(double value)
244 {
245 setDbusProperty(bus, entityManagerBusName, entityPath,
246 entityInterfaceLow, "Value", value);
247 return CriticalObject::criticalLow(value);
248 }
249
250 /** @brief Set the entitymanager interface corresponding to virtualsensor
251 * criticalLow
252 */
253 void setEntityInterfaceLow(const std::string& interfaceLow)
254 {
255 entityInterfaceLow = interfaceLow;
256 }
257
258 /** @brief Set the entitymanager interface corresponding to virtualsensor
259 * criticalLow
260 */
261 void setEntityInterfaceHigh(const std::string& interfaceHigh)
262 {
263 entityInterfaceHigh = interfaceHigh;
264 }
265
266 /** @brief Set the entitymanager path corresponding to virtualsensor warning
267 */
268 void setEntityPath(const std::string& path)
269 {
270 entityPath = path;
271 }
Matt Spinler8f5e6112021-01-15 10:44:32 -0600272};
273
274template <>
Rashmica Gupta1dff7dc2021-07-27 19:43:31 +1000275struct Threshold<SoftShutdownObject> :
276 public SoftShutdownObject,
277 public Hysteresis
Matt Spinler8f5e6112021-01-15 10:44:32 -0600278{
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600279 static constexpr auto name = "SoftShutdown";
280 using SoftShutdownObject::SoftShutdownObject;
281
282 auto high()
Matt Spinler8f5e6112021-01-15 10:44:32 -0600283 {
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600284 return softShutdownHigh();
Matt Spinler8f5e6112021-01-15 10:44:32 -0600285 }
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600286 auto low()
Matt Spinler8f5e6112021-01-15 10:44:32 -0600287 {
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600288 return softShutdownLow();
Matt Spinler8f5e6112021-01-15 10:44:32 -0600289 }
290
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600291 template <typename... Args>
292 auto alarmHigh(Args... args)
Matt Spinler8f5e6112021-01-15 10:44:32 -0600293 {
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600294 return softShutdownAlarmHigh(std::forward<Args>(args)...);
Matt Spinler8f5e6112021-01-15 10:44:32 -0600295 }
296
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600297 template <typename... Args>
298 auto alarmLow(Args... args)
Matt Spinler8f5e6112021-01-15 10:44:32 -0600299 {
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600300 return softShutdownAlarmLow(std::forward<Args>(args)...);
Matt Spinler8f5e6112021-01-15 10:44:32 -0600301 }
George Hung4294e6d2021-04-14 20:58:21 +0800302
303 template <typename... Args>
304 auto alarmHighSignalAsserted(Args... args)
305 {
306 return softShutdownHighAlarmAsserted(std::forward<Args>(args)...);
307 }
308
309 template <typename... Args>
310 auto alarmHighSignalDeasserted(Args... args)
311 {
312 return softShutdownHighAlarmDeasserted(std::forward<Args>(args)...);
313 }
314
315 template <typename... Args>
316 auto alarmLowSignalAsserted(Args... args)
317 {
318 return softShutdownLowAlarmAsserted(std::forward<Args>(args)...);
319 }
320
321 template <typename... Args>
322 auto alarmLowSignalDeasserted(Args... args)
323 {
324 return softShutdownLowAlarmDeasserted(std::forward<Args>(args)...);
325 }
Matt Spinler8f5e6112021-01-15 10:44:32 -0600326};
327
328template <>
Rashmica Gupta1dff7dc2021-07-27 19:43:31 +1000329struct Threshold<HardShutdownObject> :
330 public HardShutdownObject,
331 public Hysteresis
Matt Spinler8f5e6112021-01-15 10:44:32 -0600332{
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600333 static constexpr auto name = "HardShutdown";
334 using HardShutdownObject::HardShutdownObject;
335
336 auto high()
Matt Spinler8f5e6112021-01-15 10:44:32 -0600337 {
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600338 return hardShutdownHigh();
Matt Spinler8f5e6112021-01-15 10:44:32 -0600339 }
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600340 auto low()
Matt Spinler8f5e6112021-01-15 10:44:32 -0600341 {
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600342 return hardShutdownLow();
Matt Spinler8f5e6112021-01-15 10:44:32 -0600343 }
344
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600345 template <typename... Args>
346 auto alarmHigh(Args... args)
Matt Spinler8f5e6112021-01-15 10:44:32 -0600347 {
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600348 return hardShutdownAlarmHigh(std::forward<Args>(args)...);
Matt Spinler8f5e6112021-01-15 10:44:32 -0600349 }
350
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600351 template <typename... Args>
352 auto alarmLow(Args... args)
Matt Spinler8f5e6112021-01-15 10:44:32 -0600353 {
Patrick Williamsfdb826d2021-01-20 14:37:53 -0600354 return hardShutdownAlarmLow(std::forward<Args>(args)...);
Matt Spinler8f5e6112021-01-15 10:44:32 -0600355 }
George Hung4294e6d2021-04-14 20:58:21 +0800356
357 template <typename... Args>
358 auto alarmHighSignalAsserted(Args... args)
359 {
360 return hardShutdownHighAlarmAsserted(std::forward<Args>(args)...);
361 }
362
363 template <typename... Args>
364 auto alarmHighSignalDeasserted(Args... args)
365 {
366 return hardShutdownHighAlarmDeasserted(std::forward<Args>(args)...);
367 }
368
369 template <typename... Args>
370 auto alarmLowSignalAsserted(Args... args)
371 {
372 return hardShutdownLowAlarmAsserted(std::forward<Args>(args)...);
373 }
374
375 template <typename... Args>
376 auto alarmLowSignalDeasserted(Args... args)
377 {
378 return hardShutdownLowAlarmDeasserted(std::forward<Args>(args)...);
379 }
Matt Spinler8f5e6112021-01-15 10:44:32 -0600380};
381
Matt Spinlerb306b032021-02-01 10:05:46 -0600382template <>
Rashmica Gupta1dff7dc2021-07-27 19:43:31 +1000383struct Threshold<PerformanceLossObject> :
384 public PerformanceLossObject,
385 public Hysteresis
Matt Spinlerb306b032021-02-01 10:05:46 -0600386{
387 static constexpr auto name = "PerformanceLoss";
388 using PerformanceLossObject::PerformanceLossObject;
Rashmica Gupta1dff7dc2021-07-27 19:43:31 +1000389 double performanceLossHighHysteresis;
390 double performanceLossLowHysteresis;
Matt Spinlerb306b032021-02-01 10:05:46 -0600391
392 auto high()
393 {
394 return performanceLossHigh();
395 }
396 auto low()
397 {
398 return performanceLossLow();
399 }
400
401 template <typename... Args>
402 auto alarmHigh(Args... args)
403 {
404 return performanceLossAlarmHigh(std::forward<Args>(args)...);
405 }
406
407 template <typename... Args>
408 auto alarmLow(Args... args)
409 {
410 return performanceLossAlarmLow(std::forward<Args>(args)...);
411 }
George Hung4294e6d2021-04-14 20:58:21 +0800412
413 template <typename... Args>
414 auto alarmHighSignalAsserted(Args... args)
415 {
416 return performanceLossHighAlarmAsserted(std::forward<Args>(args)...);
417 }
418
419 template <typename... Args>
420 auto alarmHighSignalDeasserted(Args... args)
421 {
422 return performanceLossHighAlarmDeasserted(std::forward<Args>(args)...);
423 }
424
425 template <typename... Args>
426 auto alarmLowSignalAsserted(Args... args)
427 {
428 return performanceLossLowAlarmAsserted(std::forward<Args>(args)...);
429 }
430
431 template <typename... Args>
432 auto alarmLowSignalDeasserted(Args... args)
433 {
434 return performanceLossLowAlarmDeasserted(std::forward<Args>(args)...);
435 }
Matt Spinlerb306b032021-02-01 10:05:46 -0600436};
437
Matt Spinler8f5e6112021-01-15 10:44:32 -0600438} // namespace phosphor::virtualSensor