monitor:  Start checking tach trust

The Fan class now uses the trust::Manager class
to ask if a sensor value is trusted before analyzing
its value against the upper and lower limits.

Change-Id: I81dd468877873ba84753d76395b4a59129824c0b
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
diff --git a/monitor/fan.cpp b/monitor/fan.cpp
index a2e0386..ba0744a 100644
--- a/monitor/fan.cpp
+++ b/monitor/fan.cpp
@@ -39,11 +39,13 @@
 Fan::Fan(Mode mode,
          sdbusplus::bus::bus& bus,
          phosphor::fan::event::EventPtr&  events,
+         std::unique_ptr<trust::Manager>& trust,
          const FanDefinition& def) :
     _bus(bus),
     _name(std::get<fanNameField>(def)),
     _deviation(std::get<fanDeviationField>(def)),
-    _numSensorFailsForNonFunc(std::get<numSensorFailsForNonfuncField>(def))
+    _numSensorFailsForNonFunc(std::get<numSensorFailsForNonfuncField>(def)),
+    _trustManager(trust)
 {
     //Start from a known state of functional
     updateInventory(true);
@@ -64,6 +66,8 @@
                                 std::get<hasTargetField>(s),
                                 std::get<timeoutField>(def),
                                 events));
+
+                _trustManager->registerSensor(_sensors.back());
             }
             catch (InvalidSensorError& e)
             {
@@ -89,6 +93,14 @@
 
 void Fan::tachChanged(TachSensor& sensor)
 {
+    if (_trustManager->active())
+    {
+        if (!_trustManager->checkTrust(sensor))
+        {
+            return;
+        }
+    }
+
     auto running = sensor.timerRunning();
 
     //If this sensor is out of range at this moment, start
diff --git a/monitor/fan.hpp b/monitor/fan.hpp
index 3da75cf..b366c44 100644
--- a/monitor/fan.hpp
+++ b/monitor/fan.hpp
@@ -5,6 +5,7 @@
 #include <vector>
 #include "event.hpp"
 #include "tach_sensor.hpp"
+#include "trust_manager.hpp"
 #include "types.hpp"
 
 namespace phosphor
@@ -89,11 +90,13 @@
          * @param mode - mode of fan monitor
          * @param bus - the dbus object
          * @param events - pointer to sd_event object
+         * @param trust - the tach trust manager
          * @param def - the fan definition structure
          */
         Fan(Mode mode,
             sdbusplus::bus::bus& bus,
             phosphor::fan::event::EventPtr& events,
+            std::unique_ptr<trust::Manager>& trust,
             const FanDefinition& def);
 
         /**
@@ -197,6 +200,11 @@
          * The sensor objects for the fan
          */
         std::vector<std::unique_ptr<TachSensor>> _sensors;
+
+        /**
+         * The tach trust manager object
+         */
+        std::unique_ptr<trust::Manager>& _trustManager;
 };
 
 }
diff --git a/monitor/main.cpp b/monitor/main.cpp
index f887232..060f27a 100644
--- a/monitor/main.cpp
+++ b/monitor/main.cpp
@@ -20,6 +20,7 @@
 #include "event.hpp"
 #include "fan.hpp"
 #include "fan_defs.hpp"
+#include "trust_manager.hpp"
 
 using namespace phosphor::fan::monitor;
 using namespace phosphor::logging;
@@ -60,6 +61,9 @@
         return -1;
     }
 
+    std::unique_ptr<phosphor::fan::trust::Manager> trust =
+            std::make_unique<phosphor::fan::trust::Manager>(trustGroups);
+
     phosphor::fan::event::EventPtr eventPtr{events};
 
     //Attach the event object to the bus object so we can
@@ -68,7 +72,8 @@
 
     for (const auto& fanDef : fanDefinitions)
     {
-        fans.emplace_back(std::make_unique<Fan>(mode, bus, eventPtr, fanDef));
+        fans.emplace_back(std::make_unique<Fan>(
+                mode, bus, eventPtr, trust, fanDef));
     }
 
     if (mode == Mode::init)