Add support for EmitReadingsUpdate property

EmitReadingsUpdate property determines whether Readings
property emits PropertiesChange signal on update.
EmitReadingsUpdate can be used to reduce broadcasting of
signals from Telemetry to lower DBus utilization and hide
Readings update information from other DBus applications.

Tested:
 - Verify if properties are properly propated during Report
   creation.
 - Verify if emitting PropertiesCahgned signal for Readings
   property is disabled when emitReadingsUpdate is set to false.
 - Unit tests are passed with success.

Change-Id: I81be5bc17de6d583dd5820e091d077d474fe424e
Signed-off-by: Wludzik, Jozef <jozef.wludzik@intel.com>
diff --git a/src/report.cpp b/src/report.cpp
index c1b7d5f..4d91787 100644
--- a/src/report.cpp
+++ b/src/report.cpp
@@ -4,6 +4,7 @@
 #include "utils/transform.hpp"
 
 #include <phosphor-logging/log.hpp>
+#include <sdbusplus/vtable.hpp>
 
 #include <numeric>
 
@@ -83,9 +84,14 @@
                     return true;
                 },
                 [this](const auto&) { return persistency; });
+
+            auto readingsFlag = sdbusplus::vtable::property_::none;
+            if (emitsReadingsUpdate)
+            {
+                readingsFlag = sdbusplus::vtable::property_::emits_change;
+            }
             dbusIface.register_property_r(
-                "Readings", readings,
-                sdbusplus::vtable::property_::emits_change,
+                "Readings", readings, readingsFlag,
                 [this](const auto&) { return readings; });
             dbusIface.register_property_r(
                 "ReportingType", reportingType,
diff --git a/tests/src/dbus_environment.cpp b/tests/src/dbus_environment.cpp
index 71568f9..4780cc5 100644
--- a/tests/src/dbus_environment.cpp
+++ b/tests/src/dbus_environment.cpp
@@ -62,11 +62,7 @@
 std::function<void()> DbusEnvironment::setPromise(std::string_view name)
 {
     auto promise = std::make_shared<std::promise<bool>>();
-
-    {
-        futures[std::string(name)].emplace_back(promise->get_future());
-    }
-
+    futures[std::string(name)].emplace_back(promise->get_future());
     return [p = std::move(promise)]() { p->set_value(true); };
 }
 
diff --git a/tests/src/test_report.cpp b/tests/src/test_report.cpp
index ca556b0..b13317d 100644
--- a/tests/src/test_report.cpp
+++ b/tests/src/test_report.cpp
@@ -167,6 +167,27 @@
                 Eq(defaultParams.interval().count()));
 }
 
+TEST_F(TestReport, settingEmitsReadingsUpdateHaveNoEffect)
+{
+    EXPECT_THAT(setProperty(sut->getPath(), "EmitsReadingsUpdate",
+                            !defaultParams.emitReadingUpdate())
+                    .value(),
+                Eq(boost::system::errc::read_only_file_system));
+    EXPECT_THAT(getProperty<bool>(sut->getPath(), "EmitsReadingsUpdate"),
+                Eq(defaultParams.emitReadingUpdate()));
+}
+
+TEST_F(TestReport, settingLogToMetricReportCollectionHaveNoEffect)
+{
+    EXPECT_THAT(setProperty(sut->getPath(), "LogToMetricReportsCollection",
+                            !defaultParams.logToMetricReportCollection())
+                    .value(),
+                Eq(boost::system::errc::read_only_file_system));
+    EXPECT_THAT(
+        getProperty<bool>(sut->getPath(), "LogToMetricReportsCollection"),
+        Eq(defaultParams.logToMetricReportCollection()));
+}
+
 TEST_F(TestReport, settingPersistencyToFalseRemovesReportFromStorage)
 {
     EXPECT_CALL(storageMock, remove(to_file_path(sut->getName())));
@@ -311,6 +332,7 @@
     public TestReport,
     public WithParamInterface<ReportParams>
 {
+  public:
     void SetUp() override
     {
         sut = makeReport(GetParam());
@@ -387,6 +409,7 @@
     public TestReport,
     public WithParamInterface<ReportParams>
 {
+  public:
     void SetUp() override
     {
         sut = makeReport(GetParam());
@@ -487,10 +510,31 @@
     sut = makeReport(ReportParams());
 }
 
-TEST_F(TestReportInitialization, readingsPropertiesChangedSingalEmits)
+TEST_F(TestReportInitialization,
+       emitReadingsUpdateIsTrueReadingsPropertiesChangedSingalEmits)
 {
-    sut = makeReport(defaultParams.reportingType("Periodic"));
-    EXPECT_CALL(readingsUpdated, Call());
+    EXPECT_CALL(readingsUpdated, Call())
+        .WillOnce(
+            InvokeWithoutArgs(DbusEnvironment::setPromise("readingsUpdated")));
+
+    const auto elapsed = DbusEnvironment::measureTime([this] {
+        sut = makeReport(
+            defaultParams.reportingType("Periodic").emitReadingUpdate(true));
+        makeMonitor();
+        EXPECT_TRUE(DbusEnvironment::waitForFuture("readingsUpdated"));
+    });
+
+    EXPECT_THAT(elapsed, AllOf(Ge(defaultParams.interval()),
+                               Lt(defaultParams.interval() * 2)));
+}
+
+TEST_F(TestReportInitialization,
+       emitReadingsUpdateIsFalseReadingsPropertiesChangesSigalDoesNotEmits)
+{
+    EXPECT_CALL(readingsUpdated, Call()).Times(0);
+
+    sut = makeReport(
+        defaultParams.reportingType("Periodic").emitReadingUpdate(false));
     makeMonitor();
-    DbusEnvironment::sleepFor(defaultParams.interval() + 1ms);
+    DbusEnvironment::sleepFor(defaultParams.interval() * 2);
 }