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/numeric_threshold.hpp b/src/numeric_threshold.hpp
index 2aff15c..02480a4 100644
--- a/src/numeric_threshold.hpp
+++ b/src/numeric_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:
NumericThreshold(
boost::asio::io_context& ioc, Sensors sensors,
- std::vector<std::string> sensorNames,
std::vector<std::unique_ptr<interfaces::TriggerAction>> actions,
Milliseconds dwellTime, numeric::Direction direction,
- double thresholdValue);
- ~NumericThreshold();
+ double thresholdValue, numeric::Type type);
+ ~NumericThreshold()
+ {}
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 numeric::Direction direction;
const double thresholdValue;
+ const numeric::Type type;
+ bool initialized = false;
struct ThresholdDetail
{
@@ -52,10 +57,15 @@
prevValue(prevValue), 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(const std::string&, Milliseconds, double, bool&,
- boost::asio::steady_timer&);
+ 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);
};