blob: ae0b60aeff3e98f083e041f3bcecc88fe42bf662 [file] [log] [blame]
Krzysztof Grobelny51497a02021-11-09 14:56:22 +01001#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
12enum class ReportingType : uint32_t
13{
14 periodic,
15 onRequest,
16 onChange
17};
18
19namespace utils
20{
21
22template <>
23struct EnumTraits<ReportingType>
24{
25 [[noreturn]] static void throwConversionError()
26 {
27 throw sdbusplus::exception::SdBusError(
28 static_cast<int>(std::errc::invalid_argument),
29 "Invalid reportingType");
30 }
31};
32
33constexpr std::array<std::pair<std::string_view, ReportingType>, 3>
34 convDataReportingType = {{std::make_pair<std::string_view, ReportingType>(
35 "Periodic", ReportingType::periodic),
36 std::make_pair<std::string_view, ReportingType>(
37 "OnRequest", ReportingType::onRequest),
38 std::make_pair<std::string_view, ReportingType>(
39 "OnChange", ReportingType::onChange)}};
40
41inline ReportingType
42 toReportingType(std::underlying_type_t<ReportingType> value)
43{
44 return toEnum<ReportingType, minEnumValue(convDataReportingType),
45 maxEnumValue(convDataReportingType)>(value);
46}
47
48inline ReportingType toReportingType(const std::string& value)
49{
50 return toEnum(convDataReportingType, value);
51}
52
53inline std::string enumToString(ReportingType value)
54{
55 return std::string(enumToString(convDataReportingType, value));
56}
57
58} // namespace utils