created AddReportFutureVersion dbus method

New method will support CollectionTimeScope, CollectionDuration

In order to make not breaking interface changes bmcweb will switch to
AddReportFutureVersion, then AddReport will be changed to match
AddReportFutureVersion, then redfish will switch back to use AddReport,
then AddReportFutureVersion will be removed.

Change-Id: I9cc906cc1fa7cdf27be7e433390c516f6bae3c50
Signed-off-by: Krzysztof Grobelny <krzysztof.grobelny@intel.com>
diff --git a/src/interfaces/metric.hpp b/src/interfaces/metric.hpp
index deb3ed6..afca8a6 100644
--- a/src/interfaces/metric.hpp
+++ b/src/interfaces/metric.hpp
@@ -1,7 +1,7 @@
 #pragma once
 
-#include "interfaces/types.hpp"
 #include "metric_value.hpp"
+#include "types/types.hpp"
 
 #include <nlohmann/json.hpp>
 
diff --git a/src/interfaces/report_factory.hpp b/src/interfaces/report_factory.hpp
index 237ae7b..ae07b84 100644
--- a/src/interfaces/report_factory.hpp
+++ b/src/interfaces/report_factory.hpp
@@ -3,7 +3,7 @@
 #include "interfaces/json_storage.hpp"
 #include "interfaces/report.hpp"
 #include "interfaces/report_manager.hpp"
-#include "interfaces/types.hpp"
+#include "types/types.hpp"
 
 #include <boost/asio/spawn.hpp>
 
diff --git a/src/interfaces/types.hpp b/src/interfaces/types.hpp
deleted file mode 100644
index a5ed0db..0000000
--- a/src/interfaces/types.hpp
+++ /dev/null
@@ -1,31 +0,0 @@
-#pragma once
-
-#include "operation_type.hpp"
-#include "utils/labeled_tuple.hpp"
-#include "utils/tstring.hpp"
-
-#include <sdbusplus/message/types.hpp>
-
-#include <string>
-#include <tuple>
-#include <type_traits>
-#include <vector>
-
-using ReadingParameters =
-    std::vector<std::tuple<sdbusplus::message::object_path, std::string,
-                           std::string, std::string>>;
-
-using LabeledSensorParameters =
-    utils::LabeledTuple<std::tuple<std::string, std::string>,
-                        utils::tstring::Service, utils::tstring::Path>;
-
-using LabeledMetricParameters =
-    utils::LabeledTuple<std::tuple<LabeledSensorParameters, OperationType,
-                                   std::string, std::string>,
-                        utils::tstring::SensorPath,
-                        utils::tstring::OperationType, utils::tstring::Id,
-                        utils::tstring::MetricMetadata>;
-
-using Readings = std::tuple<
-    uint64_t,
-    std::vector<std::tuple<std::string, std::string, double, uint64_t>>>;
diff --git a/src/metric.cpp b/src/metric.cpp
index 2a73536..c088e8a 100644
--- a/src/metric.cpp
+++ b/src/metric.cpp
@@ -1,13 +1,13 @@
 #include "metric.hpp"
 
-#include "interfaces/types.hpp"
+#include "types/types.hpp"
 #include "utils/transform.hpp"
 
 #include <algorithm>
 
 Metric::Metric(std::shared_ptr<interfaces::Sensor> sensor,
                OperationType operationType, std::string id,
-               std::string metadata) :
+               std::string metadata, CollectionTimeScope, CollectionDuration) :
     sensor(std::move(sensor)),
     operationType(std::move(operationType)), reading{std::move(id),
                                                      std::move(metadata), 0.,
@@ -52,5 +52,6 @@
     auto sensorPath =
         LabeledSensorParameters(sensor->id().service, sensor->id().path);
     return LabeledMetricParameters(std::move(sensorPath), operationType,
-                                   reading.id, reading.metadata);
+                                   reading.id, reading.metadata, timeScope,
+                                   collectionDuration);
 }
diff --git a/src/metric.hpp b/src/metric.hpp
index aab4d15..549603f 100644
--- a/src/metric.hpp
+++ b/src/metric.hpp
@@ -11,7 +11,8 @@
 {
   public:
     Metric(std::shared_ptr<interfaces::Sensor> sensor,
-           OperationType operationType, std::string id, std::string metadata);
+           OperationType operationType, std::string id, std::string metadata,
+           CollectionTimeScope, CollectionDuration);
 
     void initialize() override;
     const MetricValue& getReading() const override;
@@ -25,4 +26,6 @@
     std::shared_ptr<interfaces::Sensor> sensor;
     OperationType operationType;
     MetricValue reading;
+    CollectionTimeScope timeScope;
+    CollectionDuration collectionDuration;
 };
diff --git a/src/report.hpp b/src/report.hpp
index 97afe03..6fe4e9e 100644
--- a/src/report.hpp
+++ b/src/report.hpp
@@ -4,7 +4,7 @@
 #include "interfaces/metric.hpp"
 #include "interfaces/report.hpp"
 #include "interfaces/report_manager.hpp"
-#include "interfaces/types.hpp"
+#include "types/types.hpp"
 
 #include <boost/asio/io_context.hpp>
 #include <boost/asio/steady_timer.hpp>
diff --git a/src/report_factory.cpp b/src/report_factory.cpp
index 9dfdbb0..0e598f3 100644
--- a/src/report_factory.cpp
+++ b/src/report_factory.cpp
@@ -43,7 +43,8 @@
             -> std::shared_ptr<interfaces::Metric> {
             return std::make_shared<Metric>(
                 getSensor(param.at_index<0>()), param.at_index<1>(),
-                param.at_index<2>(), param.at_index<3>());
+                param.at_index<2>(), param.at_index<3>(), param.at_index<4>(),
+                param.at_index<5>());
         });
 
     return std::make_unique<Report>(
@@ -69,7 +70,8 @@
     auto tree = utils::getSubTreeSensors(yield, bus);
 
     return utils::transform(metricParams, [&tree](const auto& item) {
-        const auto& [sensorPath, operationType, id, metadata] = item;
+        const auto& [sensorPath, operationType, id, metadata,
+                     collectionTimeScope, collectionDuration] = item;
 
         auto it = std::find_if(
             tree.begin(), tree.end(),
@@ -80,7 +82,10 @@
             const auto& [service, ifaces] = it->second.front();
             return LabeledMetricParameters(
                 LabeledSensorParameters(service, sensorPath),
-                utils::stringToOperationType(operationType), id, metadata);
+                utils::stringToOperationType(operationType), id, metadata,
+                utils::stringToCollectionTimeScope(collectionTimeScope),
+                CollectionDuration(
+                    std::chrono::milliseconds(collectionDuration)));
         }
 
         throw sdbusplus::exception::SdBusError(
diff --git a/src/report_manager.cpp b/src/report_manager.cpp
index 9ea6026..38b9f16 100644
--- a/src/report_manager.cpp
+++ b/src/report_manager.cpp
@@ -1,7 +1,7 @@
 #include "report_manager.hpp"
 
-#include "interfaces/types.hpp"
 #include "report.hpp"
+#include "types/types.hpp"
 #include "utils/conversion.hpp"
 #include "utils/transform.hpp"
 
@@ -11,6 +11,19 @@
 #include <stdexcept>
 #include <system_error>
 
+ReadingParameters
+    convertToReadingParameters(ReadingParametersPastVersion params)
+{
+    return utils::transform(params, [](const auto& param) {
+        using namespace std::chrono_literals;
+
+        return ReadingParameters::value_type(
+            std::get<0>(param), std::get<1>(param), std::get<2>(param),
+            std::get<3>(param), utils::enumToString(CollectionTimeScope::point),
+            0u);
+    });
+}
+
 ReportManager::ReportManager(
     std::unique_ptr<interfaces::ReportFactory> reportFactoryIn,
     std::unique_ptr<interfaces::JsonStorage> reportStorageIn,
@@ -38,7 +51,25 @@
                                     const bool emitsReadingsUpdate,
                                     const bool logToMetricReportsCollection,
                                     const uint64_t interval,
-                                    ReadingParameters metricParams) {
+                                    ReadingParametersPastVersion metricParams) {
+                    return addReport(yield, reportName, reportingType,
+                                     emitsReadingsUpdate,
+                                     logToMetricReportsCollection,
+                                     std::chrono::milliseconds(interval),
+                                     convertToReadingParameters(
+                                         std::move(metricParams)))
+                        .getPath();
+                });
+
+            dbusIface.register_method(
+                "AddReportFutureVersion",
+                [this](boost::asio::yield_context& yield,
+                       const std::string& reportName,
+                       const std::string& reportingType,
+                       const bool emitsReadingsUpdate,
+                       const bool logToMetricReportsCollection,
+                       const uint64_t interval,
+                       ReadingParameters metricParams) {
                     return addReport(yield, reportName, reportingType,
                                      emitsReadingsUpdate,
                                      logToMetricReportsCollection,
@@ -144,7 +175,8 @@
                 sdbusplus::message::object_path(
                     param.at_index<0>().at_label<Path>()),
                 utils::enumToString(param.at_index<1>()), param.at_index<2>(),
-                param.at_index<3>());
+                param.at_index<3>(), utils::enumToString(param.at_index<4>()),
+                param.at_index<5>().t.count());
         });
 
     verifyAddReport(reportName, reportingType, interval, metricParams);
diff --git a/src/trigger.cpp b/src/trigger.cpp
index 471ad10..d6e51bc 100644
--- a/src/trigger.cpp
+++ b/src/trigger.cpp
@@ -1,6 +1,6 @@
 #include "trigger.hpp"
 
-#include "interfaces/types.hpp"
+#include "types/types.hpp"
 
 Trigger::Trigger(
     boost::asio::io_context& ioc,
diff --git a/src/types/collection_duration.hpp b/src/types/collection_duration.hpp
new file mode 100644
index 0000000..dc70d4f
--- /dev/null
+++ b/src/types/collection_duration.hpp
@@ -0,0 +1,18 @@
+#pragma once
+
+#include <boost/serialization/strong_typedef.hpp>
+#include <nlohmann/json.hpp>
+
+#include <chrono>
+
+BOOST_STRONG_TYPEDEF(std::chrono::milliseconds, CollectionDuration)
+
+inline void to_json(nlohmann::json& json, const CollectionDuration& value)
+{
+    json = value.t.count();
+}
+
+inline void from_json(const nlohmann::json& json, CollectionDuration& value)
+{
+    value = CollectionDuration(std::chrono::milliseconds(json.get<uint64_t>()));
+}
diff --git a/src/types/collection_time_scope.hpp b/src/types/collection_time_scope.hpp
new file mode 100644
index 0000000..d2694d2
--- /dev/null
+++ b/src/types/collection_time_scope.hpp
@@ -0,0 +1,46 @@
+#pragma once
+
+#include "utils/conversion.hpp"
+
+#include <array>
+#include <cstdint>
+#include <string_view>
+#include <type_traits>
+
+enum class CollectionTimeScope : uint32_t
+{
+    point,
+    interval,
+    startup
+};
+
+namespace utils
+{
+
+constexpr std::array<std::pair<std::string_view, CollectionTimeScope>, 3>
+    convDataCollectionTimeScope = {
+        {std::make_pair<std::string_view, CollectionTimeScope>(
+             "Point", CollectionTimeScope::point),
+         std::make_pair<std::string_view, CollectionTimeScope>(
+             "Interval", CollectionTimeScope::interval),
+         std::make_pair<std::string_view, CollectionTimeScope>(
+             "StartupInterval", CollectionTimeScope::startup)}};
+
+inline CollectionTimeScope
+    toCollectionTimeScope(std::underlying_type_t<CollectionTimeScope> value)
+{
+    return toEnum<CollectionTimeScope, CollectionTimeScope::point,
+                  CollectionTimeScope::startup>(value);
+}
+
+inline CollectionTimeScope stringToCollectionTimeScope(const std::string& value)
+{
+    return stringToEnum(convDataCollectionTimeScope, value);
+}
+
+inline std::string enumToString(CollectionTimeScope value)
+{
+    return std::string(enumToString(convDataCollectionTimeScope, value));
+}
+
+} // namespace utils
\ No newline at end of file
diff --git a/src/operation_type.hpp b/src/types/operation_type.hpp
similarity index 100%
rename from src/operation_type.hpp
rename to src/types/operation_type.hpp
diff --git a/src/types/types.hpp b/src/types/types.hpp
new file mode 100644
index 0000000..93f3b27
--- /dev/null
+++ b/src/types/types.hpp
@@ -0,0 +1,38 @@
+#pragma once
+
+#include "types/collection_duration.hpp"
+#include "types/collection_time_scope.hpp"
+#include "types/operation_type.hpp"
+#include "utils/labeled_tuple.hpp"
+#include "utils/tstring.hpp"
+
+#include <sdbusplus/message/types.hpp>
+
+#include <chrono>
+#include <string>
+#include <tuple>
+#include <type_traits>
+#include <vector>
+
+using ReadingParametersPastVersion =
+    std::vector<std::tuple<sdbusplus::message::object_path, std::string,
+                           std::string, std::string>>;
+
+using ReadingParameters =
+    std::vector<std::tuple<sdbusplus::message::object_path, std::string,
+                           std::string, std::string, std::string, uint64_t>>;
+
+using LabeledSensorParameters =
+    utils::LabeledTuple<std::tuple<std::string, std::string>,
+                        utils::tstring::Service, utils::tstring::Path>;
+
+using LabeledMetricParameters = utils::LabeledTuple<
+    std::tuple<LabeledSensorParameters, OperationType, std::string, std::string,
+               CollectionTimeScope, CollectionDuration>,
+    utils::tstring::SensorPath, utils::tstring::OperationType,
+    utils::tstring::Id, utils::tstring::MetricMetadata,
+    utils::tstring::CollectionTimeScope, utils::tstring::CollectionDuration>;
+
+using Readings = std::tuple<
+    uint64_t,
+    std::vector<std::tuple<std::string, std::string, double, uint64_t>>>;
diff --git a/src/utils/labeled_tuple.hpp b/src/utils/labeled_tuple.hpp
index 795f37f..a224141 100644
--- a/src/utils/labeled_tuple.hpp
+++ b/src/utils/labeled_tuple.hpp
@@ -170,15 +170,15 @@
 };
 
 template <class... Args, class... Labels>
-void to_json(nlohmann::json& json,
-             const LabeledTuple<std::tuple<Args...>, Labels...>& tuple)
+inline void to_json(nlohmann::json& json,
+                    const LabeledTuple<std::tuple<Args...>, Labels...>& tuple)
 {
     json = tuple.to_json();
 }
 
 template <class... Args, class... Labels>
-void from_json(const nlohmann::json& json,
-               LabeledTuple<std::tuple<Args...>, Labels...>& tuple)
+inline void from_json(const nlohmann::json& json,
+                      LabeledTuple<std::tuple<Args...>, Labels...>& tuple)
 {
     tuple.from_json(json);
 }
diff --git a/src/utils/tstring.hpp b/src/utils/tstring.hpp
index a8d3e90..3e85ba5 100644
--- a/src/utils/tstring.hpp
+++ b/src/utils/tstring.hpp
@@ -56,5 +56,21 @@
     }
 };
 
+struct CollectionTimeScope
+{
+    static std::string str()
+    {
+        return "collectionTimeScope";
+    }
+};
+
+struct CollectionDuration
+{
+    static std::string str()
+    {
+        return "collectionDuration";
+    }
+};
+
 } // namespace tstring
 } // namespace utils