thresholds.hpp (7a5285de708b2f46d47f37920c784314b4ad55aa) thresholds.hpp (043d32306e00484afc446a44789b61869ea14f84)
1#pragma once
2
3#include "env.hpp"
4
5/** @class Thresholds
6 * @brief Threshold type traits.
7 *
8 * @tparam T - The threshold type.

--- 45 unchanged lines hidden (view full) ---

54 * @tparam T - The threshold type.
55 *
56 * @param[in] iface - An sdbusplus server threshold instance.
57 * @param[in] value - The sensor reading to compare to thresholds.
58 */
59template <typename T>
60void checkThresholds(std::experimental::any& iface, int64_t value)
61{
1#pragma once
2
3#include "env.hpp"
4
5/** @class Thresholds
6 * @brief Threshold type traits.
7 *
8 * @tparam T - The threshold type.

--- 45 unchanged lines hidden (view full) ---

54 * @tparam T - The threshold type.
55 *
56 * @param[in] iface - An sdbusplus server threshold instance.
57 * @param[in] value - The sensor reading to compare to thresholds.
58 */
59template <typename T>
60void checkThresholds(std::experimental::any& iface, int64_t value)
61{
62 auto realIface = std::experimental::any_cast<std::shared_ptr<T>>
63 (iface);
62 auto realIface = std::experimental::any_cast<std::shared_ptr<T>>(iface);
64 auto lo = (*realIface.*Thresholds<T>::getLo)();
65 auto hi = (*realIface.*Thresholds<T>::getHi)();
66 (*realIface.*Thresholds<T>::alarmLo)(value <= lo);
67 (*realIface.*Thresholds<T>::alarmHi)(value >= hi);
68}
69
70/** @brief addThreshold
71 *
72 * Look for a configured threshold value in the environment and
73 * create an sdbusplus server threshold if found.
74 *
75 * @tparam T - The threshold type.
76 *
77 * @param[in] sensorType - sensor type, like 'temp'
78 * @param[in] sensorID - sensor ID, like '5'
79 * @param[in] value - The sensor reading.
80 * @param[in] info - The sdbusplus server connection and interfaces.
81 */
82template <typename T>
63 auto lo = (*realIface.*Thresholds<T>::getLo)();
64 auto hi = (*realIface.*Thresholds<T>::getHi)();
65 (*realIface.*Thresholds<T>::alarmLo)(value <= lo);
66 (*realIface.*Thresholds<T>::alarmHi)(value >= hi);
67}
68
69/** @brief addThreshold
70 *
71 * Look for a configured threshold value in the environment and
72 * create an sdbusplus server threshold if found.
73 *
74 * @tparam T - The threshold type.
75 *
76 * @param[in] sensorType - sensor type, like 'temp'
77 * @param[in] sensorID - sensor ID, like '5'
78 * @param[in] value - The sensor reading.
79 * @param[in] info - The sdbusplus server connection and interfaces.
80 */
81template <typename T>
83auto addThreshold(const std::string& sensorType,
84 const std::string& sensorID,
85 int64_t value,
86 ObjectInfo& info)
82auto addThreshold(const std::string& sensorType, const std::string& sensorID,
83 int64_t value, ObjectInfo& info)
87{
88 static constexpr bool deferSignals = true;
89
90 auto& bus = *std::get<sdbusplus::bus::bus*>(info);
91 auto& objPath = std::get<std::string>(info);
92 auto& obj = std::get<Object>(info);
93 std::shared_ptr<T> iface;
94

--- 19 unchanged lines hidden ---
84{
85 static constexpr bool deferSignals = true;
86
87 auto& bus = *std::get<sdbusplus::bus::bus*>(info);
88 auto& objPath = std::get<std::string>(info);
89 auto& obj = std::get<Object>(info);
90 std::shared_ptr<T> iface;
91

--- 19 unchanged lines hidden ---