Trigger: make dbus properties writable

This change allows to modify 'Sensors', 'ReportNames' and 'Thresholds'
dbus properties of Trigger interface. They are required by Redfish to
implement PATCH functionality for Trigger schema.

Some backend changes were required to enable this functionality, and as
such few improvements were made for existing code:
- NumericThreshold and DiscreteThreshold now have common implementation
  where it was possible.
- Internal sensor info structure for Trigger is now the same as the one
  used for Report. This resulted in breaking compatibility with previous
  Trigger persistency data.
- Added getInfo / getParams methods for Sensor and Threshold interfaces.
  They are used by Trigger dbus getters and persistency mechanism now,
  instead of storing this data in Trigger object.

Testing done:
- Unit tests were expanded and are passing
- dbus setters for Sensors and Thresholds are working and modifications
  are reflected by calling appropriate getters.

Signed-off-by: Szymon Dompke <szymon.dompke@intel.com>
Change-Id: I7a14c15a30d78ce872342b5f938aba43c77be9c0
diff --git a/src/discrete_threshold.hpp b/src/discrete_threshold.hpp
index c9bca4d..1f145f4 100644
--- a/src/discrete_threshold.hpp
+++ b/src/discrete_threshold.hpp
@@ -6,10 +6,12 @@
 #include "interfaces/trigger_action.hpp"
 #include "types/duration_types.hpp"
 #include "types/trigger_types.hpp"
+#include "utils/threshold_operations.hpp"
 
 #include <boost/asio/steady_timer.hpp>
 
 #include <chrono>
+#include <map>
 #include <memory>
 #include <vector>
 
@@ -21,23 +23,26 @@
   public:
     DiscreteThreshold(
         boost::asio::io_context& ioc, Sensors sensors,
-        std::vector<std::string> sensorNames,
         std::vector<std::unique_ptr<interfaces::TriggerAction>> actions,
-        Milliseconds dwellTime, double thresholdValue, const std::string& name);
+        Milliseconds dwellTime, double thresholdValue, const std::string& name,
+        const discrete::Severity severity);
     DiscreteThreshold(const DiscreteThreshold&) = delete;
     DiscreteThreshold(DiscreteThreshold&&) = delete;
 
     void initialize() override;
     void sensorUpdated(interfaces::Sensor&, Milliseconds) override;
     void sensorUpdated(interfaces::Sensor&, Milliseconds, double) override;
+    LabeledThresholdParam getThresholdParam() const override;
+    void updateSensors(Sensors newSensors) override;
 
   private:
     boost::asio::io_context& ioc;
-    const Sensors sensors;
     const std::vector<std::unique_ptr<interfaces::TriggerAction>> actions;
     const Milliseconds dwellTime;
     const double thresholdValue;
     const std::string name;
+    const discrete::Severity severity;
+    bool initialized = false;
 
     struct ThresholdDetail
     {
@@ -51,9 +56,15 @@
             dwell(dwell), timer(ioc)
         {}
     };
-    std::vector<ThresholdDetail> details;
+    using SensorDetails =
+        std::unordered_map<std::shared_ptr<interfaces::Sensor>,
+                           std::shared_ptr<ThresholdDetail>>;
+    SensorDetails sensorDetails;
 
-    void startTimer(interfaces::Sensor&, Milliseconds, double);
+    friend ThresholdOperations;
+
+    void startTimer(ThresholdDetail&, Milliseconds, double);
     void commit(const std::string&, Milliseconds, double);
-    ThresholdDetail& getDetails(interfaces::Sensor& sensor);
+    ThresholdDetail& getDetails(const interfaces::Sensor& sensor);
+    std::shared_ptr<ThresholdDetail> makeDetails(const std::string& sensorName);
 };