config: error on invalid configuration

Since the default led priority is no longer 'Blink', the priority now
has to be explicitly defined when using either group priority or led
priority.

If a configuration does not define the priority, the configuration is
invalid and in the yaml case, phosphor-led-manager should fail to build,
in the json case, the process should exit due to the configuration
error.

The config validation has been extracted into it's own file and made
separate from json config parsing.

So every config will go through the same validation even if its been
created via yaml.

Change-Id: Ifda65942b0768d6c0d3b25076f7a1236b46b3d9f
Signed-off-by: Alexander Hansen <alexander.hansen@9elements.com>
diff --git a/manager/config-validator.hpp b/manager/config-validator.hpp
new file mode 100644
index 0000000..5d9ff5f
--- /dev/null
+++ b/manager/config-validator.hpp
@@ -0,0 +1,68 @@
+#include "grouplayout.hpp"
+#include "ledlayout.hpp"
+
+#include <phosphor-logging/lg2.hpp>
+#include <sdbusplus/bus.hpp>
+
+namespace phosphor
+{
+namespace led
+{
+namespace error
+{
+enum ConfigValidationError
+{
+    // An LED has different priorities assigned to it in different groups
+    LedPriorityMismatch,
+
+    // LED priority was needed but not assigned
+    MissingLedPriority,
+
+    // Mixup of the 2 configuration options
+    MixedLedAndGroupPriority,
+
+    // An invalid group priority was assigned
+    InvalidGroupPriority,
+
+    // Group priorities were not unique
+    DuplicateGroupPriority,
+};
+}
+
+class ConfigValidationException : std::runtime_error
+{
+  public:
+    error::ConfigValidationError reason;
+
+    ConfigValidationException(const error::ConfigValidationError& err,
+                              const std::string& msg) :
+        std::runtime_error(msg), reason(err)
+    {
+        lg2::error(msg.c_str());
+    }
+
+    ConfigValidationException(const error::ConfigValidationError& err,
+                              const std::string& groupName,
+                              const std::string& msg) :
+        std::runtime_error(msg), reason(err)
+    {
+        lg2::error("Configuration Validation Error in Group {GROUP}: {MSG}",
+                   "GROUP", groupName, "MSG", msg.c_str());
+    }
+
+    ConfigValidationException(const error::ConfigValidationError& err,
+                              const std::string& groupName,
+                              const std::string& ledName,
+                              const std::string& msg) :
+        std::runtime_error(msg), reason(err)
+    {
+        lg2::error(
+            "Configuration Validation Error in Group {GROUP}, Led {LED}: {MSG}",
+            "GROUP", groupName, "LED", ledName, "MSG", msg.c_str());
+    }
+};
+
+void validateConfigV1(const phosphor::led::GroupMap& ledMap);
+
+} // namespace led
+} // namespace phosphor