Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "utils/conversion.hpp" |
| 4 | |
| 5 | #include <array> |
| 6 | #include <cstdint> |
| 7 | #include <string_view> |
| 8 | #include <type_traits> |
| 9 | |
| 10 | enum class ReportAction : uint32_t |
| 11 | { |
| 12 | emitsReadingsUpdate, |
| 13 | logToMetricReportsCollection |
| 14 | }; |
| 15 | |
| 16 | namespace utils |
| 17 | { |
| 18 | |
Krzysztof Grobelny | 62c08e9 | 2022-09-16 10:28:53 +0200 | [diff] [blame] | 19 | template <> |
| 20 | struct EnumTraits<ReportAction> |
| 21 | { |
| 22 | static constexpr auto propertyName = ConstexprString{"ReportAction"}; |
| 23 | }; |
| 24 | |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 25 | constexpr std::array<std::pair<std::string_view, ReportAction>, 2> |
Krzysztof Grobelny | cff70c1 | 2022-10-27 07:16:08 +0000 | [diff] [blame^] | 26 | convDataReportAction = {{std::make_pair<std::string_view, ReportAction>( |
| 27 | "xyz.openbmc_project.Telemetry.Report." |
| 28 | "ReportActions.EmitsReadingsUpdate", |
| 29 | ReportAction::emitsReadingsUpdate), |
| 30 | std::make_pair<std::string_view, ReportAction>( |
| 31 | "xyz.openbmc_project.Telemetry.Report." |
| 32 | "ReportActions.LogToMetricReportsCollection", |
| 33 | ReportAction::logToMetricReportsCollection)}}; |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 34 | |
| 35 | inline ReportAction toReportAction(std::underlying_type_t<ReportAction> value) |
| 36 | { |
| 37 | return toEnum<ReportAction, minEnumValue(convDataReportAction), |
| 38 | maxEnumValue(convDataReportAction)>(value); |
| 39 | } |
| 40 | |
| 41 | inline ReportAction toReportAction(const std::string& value) |
| 42 | { |
| 43 | return toEnum(convDataReportAction, value); |
| 44 | } |
| 45 | |
| 46 | inline std::string enumToString(ReportAction value) |
| 47 | { |
| 48 | return std::string(enumToString(convDataReportAction, value)); |
| 49 | } |
| 50 | |
Krzysztof Grobelny | 62c08e9 | 2022-09-16 10:28:53 +0200 | [diff] [blame] | 51 | } // namespace utils |