Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "types/collection_duration.hpp" |
| 4 | #include "types/collection_time_scope.hpp" |
| 5 | #include "types/operation_type.hpp" |
| 6 | #include "utils/labeled_tuple.hpp" |
| 7 | #include "utils/tstring.hpp" |
| 8 | |
| 9 | #include <sdbusplus/message/types.hpp> |
| 10 | |
| 11 | #include <chrono> |
| 12 | #include <string> |
| 13 | #include <tuple> |
| 14 | #include <type_traits> |
| 15 | #include <vector> |
| 16 | |
| 17 | using ReadingParametersPastVersion = |
| 18 | std::vector<std::tuple<sdbusplus::message::object_path, std::string, |
| 19 | std::string, std::string>>; |
| 20 | |
| 21 | using ReadingParameters = std::vector< |
| 22 | std::tuple<std::vector<sdbusplus::message::object_path>, std::string, |
| 23 | std::string, std::string, std::string, uint64_t>>; |
| 24 | |
| 25 | using LabeledSensorParameters = |
| 26 | utils::LabeledTuple<std::tuple<std::string, std::string>, |
| 27 | utils::tstring::Service, utils::tstring::Path>; |
| 28 | |
| 29 | using LabeledMetricParameters = utils::LabeledTuple< |
| 30 | std::tuple<std::vector<LabeledSensorParameters>, OperationType, std::string, |
| 31 | std::string, CollectionTimeScope, CollectionDuration>, |
| 32 | utils::tstring::SensorPath, utils::tstring::OperationType, |
| 33 | utils::tstring::Id, utils::tstring::MetricMetadata, |
| 34 | utils::tstring::CollectionTimeScope, utils::tstring::CollectionDuration>; |
| 35 | |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame^] | 36 | using ReadingData = std::tuple<std::string, std::string, double, uint64_t>; |
| 37 | |
| 38 | using Readings = std::tuple<uint64_t, std::vector<ReadingData>>; |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 39 | |
| 40 | ReadingParameters |
| 41 | toReadingParameters(const std::vector<LabeledMetricParameters>& labeled); |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame^] | 42 | |
| 43 | enum class ReportUpdates |
| 44 | { |
| 45 | Overwrite = 0, |
| 46 | AppendStopsWhenFull, |
| 47 | AppendWrapsWhenFull, |
| 48 | NewReport |
| 49 | }; |
| 50 | |
| 51 | namespace details |
| 52 | { |
| 53 | constexpr std::array<std::pair<std::string_view, ReportUpdates>, 5> |
| 54 | convDataReportUpdates = { |
| 55 | std::make_pair("Overwrite", ReportUpdates::Overwrite), |
| 56 | std::make_pair("AppendStopsWhenFull", |
| 57 | ReportUpdates::AppendStopsWhenFull), |
| 58 | std::make_pair("AppendWrapsWhenFull", |
| 59 | ReportUpdates::AppendWrapsWhenFull), |
| 60 | std::make_pair("NewReport", ReportUpdates::NewReport)}; |
| 61 | |
| 62 | } // namespace details |
| 63 | |
| 64 | inline ReportUpdates stringToReportUpdates(const std::string& str) |
| 65 | { |
| 66 | return utils::stringToEnum(details::convDataReportUpdates, str); |
| 67 | } |
| 68 | |
| 69 | inline std::string reportUpdatesToString(ReportUpdates v) |
| 70 | { |
| 71 | return std::string(utils::enumToString(details::convDataReportUpdates, v)); |
| 72 | } |
| 73 | |
| 74 | enum class ReportingType |
| 75 | { |
| 76 | OnChange = 0, |
| 77 | OnRequest, |
| 78 | Periodic |
| 79 | }; |
| 80 | |
| 81 | namespace details |
| 82 | { |
| 83 | constexpr std::array<std::pair<std::string_view, ReportingType>, 3> |
| 84 | convDataReportingType = { |
| 85 | std::make_pair("OnChange", ReportingType::OnChange), |
| 86 | std::make_pair("OnRequest", ReportingType::OnRequest), |
| 87 | std::make_pair("Periodic", ReportingType::Periodic)}; |
| 88 | |
| 89 | } // namespace details |
| 90 | |
| 91 | inline ReportingType stringToReportingType(const std::string& str) |
| 92 | { |
| 93 | return utils::stringToEnum(details::convDataReportingType, str); |
| 94 | } |
| 95 | |
| 96 | inline std::string reportingTypeToString(ReportingType v) |
| 97 | { |
| 98 | return std::string(utils::enumToString(details::convDataReportingType, v)); |
| 99 | } |