1 #pragma once
2 
3 #include "grouplayout.hpp"
4 #include "ledlayout.hpp"
5 
6 #include <phosphor-logging/lg2.hpp>
7 #include <sdbusplus/bus.hpp>
8 
9 namespace phosphor
10 {
11 namespace led
12 {
13 namespace error
14 {
15 enum ConfigValidationError
16 {
17     // An LED has different priorities assigned to it in different groups
18     LedPriorityMismatch,
19 
20     // LED priority was needed but not assigned
21     MissingLedPriority,
22 
23     // Mixup of the 2 configuration options
24     MixedLedAndGroupPriority,
25 
26     // An invalid group priority was assigned
27     InvalidGroupPriority,
28 
29     // Group priorities were not unique
30     DuplicateGroupPriority,
31 };
32 }
33 
34 class ConfigValidationException : std::runtime_error
35 {
36   public:
37     error::ConfigValidationError reason;
38 
ConfigValidationException(const error::ConfigValidationError & err,const std::string & msg)39     ConfigValidationException(const error::ConfigValidationError& err,
40                               const std::string& msg) :
41         std::runtime_error(msg), reason(err)
42     {
43         lg2::error(msg.c_str());
44     }
45 
ConfigValidationException(const error::ConfigValidationError & err,const std::string & groupName,const std::string & msg)46     ConfigValidationException(const error::ConfigValidationError& err,
47                               const std::string& groupName,
48                               const std::string& msg) :
49         std::runtime_error(msg), reason(err)
50     {
51         lg2::error("Configuration Validation Error in Group {GROUP}: {MSG}",
52                    "GROUP", groupName, "MSG", msg.c_str());
53     }
54 
ConfigValidationException(const error::ConfigValidationError & err,const std::string & groupName,const std::string & ledName,const std::string & msg)55     ConfigValidationException(const error::ConfigValidationError& err,
56                               const std::string& groupName,
57                               const std::string& ledName,
58                               const std::string& msg) :
59         std::runtime_error(msg), reason(err)
60     {
61         lg2::error(
62             "Configuration Validation Error in Group {GROUP}, Led {LED}: {MSG}",
63             "GROUP", groupName, "LED", ledName, "MSG", msg.c_str());
64     }
65 };
66 
67 void validateConfigV1(const phosphor::led::GroupMap& ledMap);
68 
69 } // namespace led
70 } // namespace phosphor
71