changed config parsing

This commit is contained in:
Jonas Zeunert
2019-08-06 21:48:40 +02:00
parent 167934b260
commit b17b7c6898
3 changed files with 24 additions and 16 deletions

View File

@@ -16,6 +16,8 @@
#include <iostream>
#include <fstream>
#include <algorithm>
#include <numeric>
int main(int argc, char** argv)
{
@@ -63,17 +65,25 @@ void FlippRServer::parse_server_config_file()
}
catch(const std::exception e)
{
logger().information(FRED("server_config.json not readable!"));
logger().information(e.what());
Application::EXIT_IOERR;
}
logger().information(FCYN("Parsing server_config.json..."));
for(auto &config_json : json->getNames())
Object::NameList keys = json->getNames();
std::sort(keys.begin(), keys.end());
if(!std::includes(keys.begin(), keys.end(), REQUIRED_CONFIG_KEYS.begin(), REQUIRED_CONFIG_KEYS.end()))
{
handle_config_file(config_json, json->get(config_json));
std::string config_keys;
config_keys = std::accumulate(REQUIRED_CONFIG_KEYS.begin(), REQUIRED_CONFIG_KEYS.end(), config_keys);
logger().error("Need all of the following keys to be specified in server_config json" + config_keys);
Application::EXIT_USAGE;
}
this->configs = *json;
config.close();
}
@@ -116,10 +126,10 @@ void FlippRServer::initialize_output_driver()
try
{
lamp_config_stream.open(this->lamp_config);
solenoid_config_stream.open(this->solenoid_config);
sound_config_stream.open(this->sound_config);
display_config_stream.open(this->display_config);
lamp_config_stream.open(this->configs["lamp_config"].toString());
solenoid_config_stream.open(this->configs["solenoid_config"].toString());
sound_config_stream.open(this->configs["sound_config"].toString());
display_config_stream.open(this->configs["display_config"].toString());
}
catch(const std::exception& e)
{
@@ -140,8 +150,8 @@ void FlippRServer::initialize_input_driver()
try
{
input_config_stream.open(this->input_config);
matrix_config_stream.open(this->matrix_config);
input_config_stream.open(this->configs["input_config"].toString());
matrix_config_stream.open(this->configs["matrix_config"].toString());
}
catch(const std::exception& e)
{