1 #pragma once
2 
3 #include "utils/conversion.hpp"
4 
5 #include <sdbusplus/exception.hpp>
6 
7 #include <array>
8 #include <cstdint>
9 #include <string_view>
10 #include <type_traits>
11 
12 enum class ReportingType : uint32_t
13 {
14     periodic,
15     onRequest,
16     onChange
17 };
18 
19 namespace utils
20 {
21 
22 template <>
23 struct EnumTraits<ReportingType>
24 {
25     static constexpr auto propertyName = ConstexprString{"ReportingType"};
26 };
27 
28 constexpr std::array<std::pair<std::string_view, ReportingType>, 3>
29     convDataReportingType = {
30         {std::make_pair<std::string_view, ReportingType>(
31              "xyz.openbmc_project.Telemetry.Report.ReportingType.OnChange",
32              ReportingType::onChange),
33          std::make_pair<std::string_view, ReportingType>(
34              "xyz.openbmc_project.Telemetry.Report.ReportingType.OnRequest",
35              ReportingType::onRequest),
36          std::make_pair<std::string_view, ReportingType>(
37              "xyz.openbmc_project.Telemetry.Report.ReportingType.Periodic",
38              ReportingType::periodic)}};
39 
40 inline ReportingType
toReportingType(std::underlying_type_t<ReportingType> value)41     toReportingType(std::underlying_type_t<ReportingType> value)
42 {
43     return toEnum<ReportingType, minEnumValue(convDataReportingType),
44                   maxEnumValue(convDataReportingType)>(value);
45 }
46 
toReportingType(const std::string & value)47 inline ReportingType toReportingType(const std::string& value)
48 {
49     return toEnum(convDataReportingType, value);
50 }
51 
enumToString(ReportingType value)52 inline std::string enumToString(ReportingType value)
53 {
54     return std::string(enumToString(convDataReportingType, value));
55 }
56 
57 } // namespace utils
58