summaryrefslogtreecommitdiffstats
path: root/monitor/trust_manager.hpp
diff options
context:
space:
mode:
authorMatt Spinler <spinler@us.ibm.com>2017-09-28 11:57:47 -0500
committerMatt Spinler <spinler@us.ibm.com>2017-10-11 09:24:59 -0500
commit136e23dd27dbff225fd7b68cb624e4b612cf790f (patch)
tree95dcfc105cd23b72901ab7ff765a70270fed0455 /monitor/trust_manager.hpp
parent0ada59f968b6f51ccb561dd60da36c6bfbf2ae5d (diff)
downloadphosphor-fan-presence-136e23dd27dbff225fd7b68cb624e4b612cf790f.tar.gz
phosphor-fan-presence-136e23dd27dbff225fd7b68cb624e4b612cf790f.zip
monitor: Add trust manager class
This class contains the trust groups, and is the interface for asking if a sensor value can be trusted or not. It will also start and stop timers on all sensors in the same group as the timer in question whose trust value just changed. This class will be used by the Fan class in the speed change callback function to check if a sensor is trusted before analyzing its value. Change-Id: I134be095b6b5222f7bc0e457078cf01f75a36219 Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Diffstat (limited to 'monitor/trust_manager.hpp')
-rw-r--r--monitor/trust_manager.hpp146
1 files changed, 146 insertions, 0 deletions
diff --git a/monitor/trust_manager.hpp b/monitor/trust_manager.hpp
new file mode 100644
index 0000000..d78e647
--- /dev/null
+++ b/monitor/trust_manager.hpp
@@ -0,0 +1,146 @@
+#pragma once
+
+#include <memory>
+#include <vector>
+#include "tach_sensor.hpp"
+#include "trust_group.hpp"
+#include "types.hpp"
+
+namespace phosphor
+{
+namespace fan
+{
+namespace trust
+{
+
+/**
+ * @class Manager
+ *
+ * The sensor trust manager class. It can be asked if a tach sensor's
+ * reading can be trusted or not, based on the trust groups the sensor
+ * is in.
+ *
+ * When it finds a group's trust status changing, it will either stop or
+ * start the tach error timers for the group's sensors accordingly.
+ *
+ * See the trust::Group documentation for more details on sensor trust.
+ */
+class Manager
+{
+ public:
+
+ Manager() = delete;
+ Manager(const Manager&) = delete;
+ Manager& operator=(const Manager&) = delete;
+ Manager(Manager&&) = default;
+ Manager& operator=(Manager&&) = default;
+ ~Manager() = default;
+
+ /**
+ * Constructor
+ *
+ * @param[in] functions - trust group creation function vector
+ */
+ explicit Manager(const std::vector<monitor::CreateGroupFunction>& functions)
+ {
+ for (auto& create : functions)
+ {
+ groups.emplace_back(create());
+ }
+ }
+
+ /**
+ * Says if trust groups have been created and
+ * need to be checked.
+ *
+ * @return bool - If there are any trust groups
+ */
+ inline bool active() const
+ {
+ return !groups.empty();
+ }
+
+ /**
+ * Checks if a sensor value can be trusted
+ *
+ * Checks if the sensor is trusted in each group
+ * it belongs to. Only considered trusted if it is
+ * trusted in all groups it belongs to.
+ *
+ * While checking group trust, the code will also check
+ * if the trust status has just changed. If the status
+ * just changed to false, it will stop the tach error
+ * timers for that group so these untrusted sensors won't
+ * cause errors. If changed to true, it will start those timers
+ * back up again.
+ *
+ * Note this means groups should be designed such that
+ * in the same call to this function a sensor shouldn't
+ * make one group change to trusted and another to untrusted.
+ *
+ * @param[in] sensor - the sensor to check
+ *
+ * @return bool - if sensor is trusted in all groups or not
+ */
+ bool checkTrust(
+ const monitor::TachSensor& sensor)
+ {
+ auto trusted = true;
+
+ for (auto& group : groups)
+ {
+ if (group->inGroup(sensor))
+ {
+ bool trust, changed;
+ std::tie(trust, changed) = group->checkTrust(sensor);
+
+ if (!trust)
+ {
+ trusted = false;
+
+ if (changed)
+ {
+ group->stopTimers();
+ }
+ }
+ else
+ {
+ if (changed)
+ {
+ group->startTimers();
+ }
+ }
+ }
+ }
+
+ return trusted;
+ }
+
+ /**
+ * Registers a sensor with any trust groups that are interested
+ *
+ * @param[in] sensor - the sensor to register
+ */
+ void registerSensor(
+ std::unique_ptr<monitor::TachSensor>& sensor)
+ {
+ std::for_each(
+ groups.begin(),
+ groups.end(),
+ [&sensor](auto& group)
+ {
+ group->registerSensor(sensor);
+ });
+ }
+
+ private:
+
+ /**
+ * The list of sensor trust groups
+ */
+ std::vector<std::unique_ptr<Group>> groups;
+};
+
+}
+}
+}
OpenPOWER on IntegriCloud