summaryrefslogtreecommitdiffstats
path: root/presence/fallback.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'presence/fallback.hpp')
-rw-r--r--presence/fallback.hpp79
1 files changed, 79 insertions, 0 deletions
diff --git a/presence/fallback.hpp b/presence/fallback.hpp
new file mode 100644
index 0000000..a1a5b29
--- /dev/null
+++ b/presence/fallback.hpp
@@ -0,0 +1,79 @@
+#pragma once
+
+#include <functional>
+#include <vector>
+#include "fan.hpp"
+#include "rpolicy.hpp"
+
+namespace phosphor
+{
+namespace fan
+{
+namespace presence
+{
+
+class PresenceSensor;
+
+/**
+ * @class Fallback
+ * @brief Fallback redundancy policy.
+ *
+ * The fallback redundancy policy falls back to
+ * subsequent presence sensors when the active
+ * sensor indicates not present and a fallback
+ * sensor indicates the fan is present.
+ */
+class Fallback : public RedundancyPolicy
+{
+ public:
+ Fallback() = delete;
+ Fallback(const Fallback&) = default;
+ Fallback& operator=(const Fallback&) = default;
+ Fallback(Fallback&&) = default;
+ Fallback& operator=(Fallback&&) = default;
+ ~Fallback() = default;
+
+ /**
+ * @brief Construct a fallback policy.
+ *
+ * @param[in] fan - The fan associated with the policy.
+ * @param[in] s - The set of sensors associated with the policy.
+ */
+ Fallback(
+ const Fan& fan,
+ const std::vector<std::reference_wrapper<PresenceSensor>>& s) :
+ RedundancyPolicy(fan), sensors(s)
+ {
+ activeSensor = sensors.begin();
+ }
+
+ /**
+ * @brief stateChanged
+ *
+ * Update the inventory and execute the fallback
+ * policy.
+ *
+ * @param[in] present - The new presence state according
+ * to the active sensor.
+ */
+ void stateChanged(bool present) override;
+
+ /**
+ * @brief monitor
+ *
+ * Start monitoring the fan.
+ */
+ void monitor() override;
+
+ private:
+
+ /** @brief All presence sensors in the redundancy set. */
+ std::vector<std::reference_wrapper<PresenceSensor>> sensors;
+
+ /** @brief The active presence sensor. */
+ decltype(sensors)::iterator activeSensor;
+};
+
+} // namespace presence
+} // namespace fan
+} // namespace phosphor
OpenPOWER on IntegriCloud