monitor: Subscribe to tach target and feedback services

Subscribes to nameOwnerChanged signals for the services of the sensor
and target interfaces for each configured fan. If those services go
offline, the fan tach sensors should get marked nonfunctional due to no
longer receiving updated target or feedback values. In this design, we
use the existing method of determining when a fan tach sensor should be
marked nonfunctional to allow a recovery window, wherein a brief
offline/online transition (such as during a restart) will not trigger a
nonfunctional state change.

Change-Id: I0a935ccad5a864dc952d023185356a1ef1226830
Signed-off-by: Mike Capps <mikepcapps@gmail.com>
diff --git a/monitor/system.hpp b/monitor/system.hpp
index 6725b00..a690567 100644
--- a/monitor/system.hpp
+++ b/monitor/system.hpp
@@ -37,6 +37,10 @@
 
 using json = nlohmann::json;
 
+// Mapping from service name to sensor
+using SensorMapType =
+    std::map<std::string, std::set<std::shared_ptr<TachSensor>>>;
+
 class System
 {
   public:
@@ -164,6 +168,11 @@
     ThermalAlertObject _thermalAlert;
 
     /**
+     * @brief The tach sensors D-Bus match objects
+     */
+    std::vector<std::unique_ptr<sdbusplus::bus::match::match>> _sensorMatch;
+
+    /**
      * @brief If start() has been called
      */
     bool _started = false;
@@ -177,6 +186,14 @@
     json captureSensorData();
 
     /**
+     * @brief Builds a mapping for sensors to be identified
+     *        for a given service name.
+     *
+     * @return a map of service_name->[sensor1,sensor2...]
+     */
+    SensorMapType buildNameOwnerChangedMap() const;
+
+    /**
      * @brief Retrieve the configured trust groups
      *
      * @param[in] jsonObj - JSON object to parse from
@@ -216,6 +233,16 @@
     void updateFanHealth(const Fan& fan);
 
     /**
+     * @brief callback when a tach sensor signal goes offline
+     *
+     * @param[in] msg - D-Bus message containing details (inc. service name)
+     *
+     * @param[in] sensorMap - map providing sensor access for each service
+     */
+    void tachSignalOffline(sdbusplus::message::message& msg,
+                           const SensorMapType& sensorMap);
+
+    /**
      * @brief The function that runs when the power state changes
      *
      * @param[in] powerStateOn - If power is now on or not