entity-manager: runtime schema validation

Uncomment the schema validation code and create a meson option to enable
this code path. The option is by default false, so the default codepath
is untouched.

Tested: Not tested, since the schemas can be validated at build time.
Whoever wants to experiment with this code, feel free to test it.
At least now it is as easy as enabling a meson option.

Change-Id: Icc2226e2e08ede5cff5a5f97bc29c8e38b117ff8
Signed-off-by: Alexander Hansen <alexander.hansen@9elements.com>
diff --git a/meson.options b/meson.options
index d658c8b..bd962e4 100644
--- a/meson.options
+++ b/meson.options
@@ -29,6 +29,12 @@
     description: 'Run JSON schema validation during the build.',
 )
 option(
+    'runtime-validate-json',
+    type: 'boolean',
+    value: false,
+    description: 'Run JSON schema validation at runtime.',
+)
+option(
     'gpio-presence',
     type: 'boolean',
     value: true,
diff --git a/src/entity_manager/configuration.cpp b/src/entity_manager/configuration.cpp
index bd78f1b..137f4e3 100644
--- a/src/entity_manager/configuration.cpp
+++ b/src/entity_manager/configuration.cpp
@@ -83,15 +83,12 @@
             std::cerr << "syntax error in " << jsonPath.string() << "\n";
             continue;
         }
-        /*
-        * todo(james): reenable this once less things are in flight
-        *
-        if (!validateJson(schema, data))
+
+        if (ENABLE_RUNTIME_VALIDATE_JSON && !validateJson(schema, data))
         {
             std::cerr << "Error validating " << jsonPath.string() << "\n";
             continue;
         }
-        */
 
         if (data.type() == nlohmann::json::value_t::array)
         {
diff --git a/src/entity_manager/meson.build b/src/entity_manager/meson.build
index 622cf53..0fe71dd 100644
--- a/src/entity_manager/meson.build
+++ b/src/entity_manager/meson.build
@@ -1,3 +1,11 @@
+cpp_args_em = cpp_args + ['-DBOOST_ASIO_DISABLE_THREADS']
+
+if get_option('runtime-validate-json')
+    cpp_args_em += ['-DENABLE_RUNTIME_VALIDATE_JSON=true']
+else
+    cpp_args_em += ['-DENABLE_RUNTIME_VALIDATE_JSON=false']
+endif
+
 executable(
     'entity-manager',
     'entity_manager.cpp',
@@ -10,7 +18,7 @@
     'topology.cpp',
     'utils.cpp',
     '../utils.cpp',
-    cpp_args: cpp_args + ['-DBOOST_ASIO_DISABLE_THREADS'],
+    cpp_args: cpp_args_em,
     dependencies: [
         boost,
         nlohmann_json_dep,