Report: Add TriggerIds property

This change is adding TriggerIds property for Report interface. It is an
array of strings, each representing id of trigger which may update given
report Readings property, due to UpdateReport action. This properly is
read-only, but it can be changed in the runtime, when:
- New Trigger is made using AddTrigger dbus method, when ReportId
  argument contains id of given report.
- Trigger is deleted from dbus, and its ReportNames property included id
  of given report.
- ReportNames property of any trigger is updated to include (or not) id
  of given report.

When this property is modified by service, signal will be emitted on
dbus for property change.

When there is existing trigger with id of non-existing report in its
ReportNames property, its id will be added to TriggerIds property of
such report, the moment it is created by user.

Testing done:
- new UTs were made, all UTs are passing.
- manual testing on dbus interface was successful.

Signed-off-by: Szymon Dompke <szymon.dompke@intel.com>
Change-Id: I1c4c94ce751ddaee001e3cadde3ea60aa8e1c224
diff --git a/src/report.cpp b/src/report.cpp
index 8acf182..6439d41 100644
--- a/src/report.cpp
+++ b/src/report.cpp
@@ -21,7 +21,8 @@
                interfaces::ReportManager& reportManager,
                interfaces::JsonStorage& reportStorageIn,
                std::vector<std::shared_ptr<interfaces::Metric>> metricsIn,
-               const bool enabledIn, std::unique_ptr<interfaces::Clock> clock) :
+               const bool enabledIn, std::unique_ptr<interfaces::Clock> clock,
+               const std::vector<std::string>& triggerIdsIn) :
     id(reportId),
     name(reportName), reportingType(reportingTypeIn), interval(intervalIn),
     reportActions(std::move(reportActionsIn)),
@@ -30,6 +31,7 @@
     reportUpdates(reportUpdatesIn),
     readingsBuffer(deduceBufferSize(reportUpdates, reportingType)),
     objServer(objServer), metrics(std::move(metricsIn)), timer(ioc),
+    triggerIds(triggerIdsIn.begin(), triggerIdsIn.end()),
     reportStorage(reportStorageIn), enabled(enabledIn), clock(std::move(clock))
 {
     readingParameters =
@@ -257,6 +259,12 @@
             return 1;
         },
         [this](const auto&) { return utils::enumToString(reportUpdates); });
+    dbusIface->register_property_r(
+        "TriggerIds", std::vector<std::string>{},
+        sdbusplus::vtable::property_::emits_change, [this](const auto&) {
+            return std::vector<std::string>(triggerIds.begin(),
+                                            triggerIds.end());
+        });
     dbusIface->register_method("Update", [this] {
         if (reportingType == ReportingType::onRequest)
         {
@@ -362,8 +370,28 @@
 
     return true;
 }
+
 interfaces::JsonStorage::FilePath Report::fileName() const
 {
     return interfaces::JsonStorage::FilePath{
         std::to_string(std::hash<std::string>{}(id))};
 }
+
+void Report::updateTriggerIds(const std::string& triggerId,
+                              TriggerIdUpdate updateType)
+{
+    if (updateType == TriggerIdUpdate::Add)
+    {
+        if (triggerIds.insert(triggerId).second)
+        {
+            reportIface->signal_property("TriggerIds");
+        }
+    }
+    else if (updateType == TriggerIdUpdate::Remove)
+    {
+        if (triggerIds.erase(triggerId) > 0)
+        {
+            reportIface->signal_property("TriggerIds");
+        }
+    }
+}