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/on_change_threshold.cpp b/src/on_change_threshold.cpp
index e278c7f..fe3d1dd 100644
--- a/src/on_change_threshold.cpp
+++ b/src/on_change_threshold.cpp
@@ -3,10 +3,10 @@
 #include <phosphor-logging/log.hpp>
 
 OnChangeThreshold::OnChangeThreshold(
-    Sensors sensorsIn, std::vector<std::string> sensorNamesIn,
+    Sensors sensorsIn,
     std::vector<std::unique_ptr<interfaces::TriggerAction>> actionsIn) :
     sensors(std::move(sensorsIn)),
-    sensorNames(std::move(sensorNamesIn)), actions(std::move(actionsIn))
+    actions(std::move(actionsIn))
 {}
 
 void OnChangeThreshold::initialize()
@@ -15,6 +15,39 @@
     {
         sensor->registerForUpdates(weak_from_this());
     }
+    initialized = true;
+}
+
+void OnChangeThreshold::updateSensors(Sensors newSensors)
+{
+    Sensors oldSensors = sensors;
+
+    for (const auto& sensor : newSensors)
+    {
+        auto it =
+            std::find_if(oldSensors.begin(), oldSensors.end(),
+                         [&sensor](const auto& s) { return sensor == s; });
+        if (it != oldSensors.end())
+        {
+            oldSensors.erase(it);
+            continue;
+        }
+
+        if (initialized)
+        {
+            sensor->registerForUpdates(weak_from_this());
+        }
+    }
+
+    if (initialized)
+    {
+        for (auto& sensor : oldSensors)
+        {
+            sensor->unregisterFromUpdates(weak_from_this());
+        }
+    }
+
+    sensors = std::move(newSensors);
 }
 
 void OnChangeThreshold::sensorUpdated(interfaces::Sensor& sensor,
@@ -24,11 +57,7 @@
 void OnChangeThreshold::sensorUpdated(interfaces::Sensor& sensor,
                                       Milliseconds timestamp, double value)
 {
-    auto it =
-        std::find_if(sensors.begin(), sensors.end(),
-                     [&sensor](const auto& x) { return &sensor == x.get(); });
-    auto index = std::distance(sensors.begin(), it);
-    commit(sensorNames.at(index), timestamp, value);
+    commit(sensor.getName(), timestamp, value);
 }
 
 void OnChangeThreshold::commit(const std::string& sensorName,
@@ -39,3 +68,8 @@
         action->commit(sensorName, timestamp, value);
     }
 }
+
+LabeledThresholdParam OnChangeThreshold::getThresholdParam() const
+{
+    return {};
+}