changed config parsing
This commit is contained in:
@@ -5,5 +5,4 @@
|
|||||||
"solenoid-config" :"../../contrib/json_example/output/Solenoid_Config.json",
|
"solenoid-config" :"../../contrib/json_example/output/Solenoid_Config.json",
|
||||||
"sound-config" :"../../contrib/json_example/output/Sound_Config.json",
|
"sound-config" :"../../contrib/json_example/output/Sound_Config.json",
|
||||||
"display-config" :"../../contrib/json_example/output/Display_Config.json",
|
"display-config" :"../../contrib/json_example/output/Display_Config.json",
|
||||||
"lamp-config" :"../../contrib/json_example/output/Lamp_Config.json"
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <numeric>
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
@@ -63,17 +65,25 @@ void FlippRServer::parse_server_config_file()
|
|||||||
}
|
}
|
||||||
catch(const std::exception e)
|
catch(const std::exception e)
|
||||||
{
|
{
|
||||||
logger().information(FRED("server_config.json not readable!"));
|
logger().information(e.what());
|
||||||
Application::EXIT_IOERR;
|
Application::EXIT_IOERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
logger().information(FCYN("Parsing server_config.json..."));
|
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();
|
config.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,10 +126,10 @@ void FlippRServer::initialize_output_driver()
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
lamp_config_stream.open(this->lamp_config);
|
lamp_config_stream.open(this->configs["lamp_config"].toString());
|
||||||
solenoid_config_stream.open(this->solenoid_config);
|
solenoid_config_stream.open(this->configs["solenoid_config"].toString());
|
||||||
sound_config_stream.open(this->sound_config);
|
sound_config_stream.open(this->configs["sound_config"].toString());
|
||||||
display_config_stream.open(this->display_config);
|
display_config_stream.open(this->configs["display_config"].toString());
|
||||||
}
|
}
|
||||||
catch(const std::exception& e)
|
catch(const std::exception& e)
|
||||||
{
|
{
|
||||||
@@ -140,8 +150,8 @@ void FlippRServer::initialize_input_driver()
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
input_config_stream.open(this->input_config);
|
input_config_stream.open(this->configs["input_config"].toString());
|
||||||
matrix_config_stream.open(this->matrix_config);
|
matrix_config_stream.open(this->configs["matrix_config"].toString());
|
||||||
}
|
}
|
||||||
catch(const std::exception& e)
|
catch(const std::exception& e)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
#include <Poco/Util/ServerApplication.h>
|
#include <Poco/Util/ServerApplication.h>
|
||||||
#include <Poco/Net/HTTPServer.h>
|
#include <Poco/Net/HTTPServer.h>
|
||||||
|
#include <Poco/Dynamic/Struct.h>
|
||||||
|
|
||||||
namespace flippR_driver
|
namespace flippR_driver
|
||||||
{
|
{
|
||||||
@@ -42,17 +43,15 @@ private:
|
|||||||
private:
|
private:
|
||||||
const std::string DEFAULT_RUNTIME_DIR = "/tmp/flippR_driver-runtime/";
|
const std::string DEFAULT_RUNTIME_DIR = "/tmp/flippR_driver-runtime/";
|
||||||
const std::string SOCKET_NAME = "S.flippR_driver";
|
const std::string SOCKET_NAME = "S.flippR_driver";
|
||||||
|
const std::vector<std::string> REQUIRED_CONFIG_KEYS = {"display-config", "input-config", "lamp-config",
|
||||||
|
"matrix-config", "solenoid-config", "sound-config"};
|
||||||
int input_port;
|
int input_port;
|
||||||
int output_port;
|
int output_port;
|
||||||
|
|
||||||
bool help_requested;
|
bool help_requested;
|
||||||
|
|
||||||
std::string input_config;
|
Poco::DynamicStruct configs;
|
||||||
std::string matrix_config;
|
|
||||||
std::string lamp_config;
|
|
||||||
std::string solenoid_config;
|
|
||||||
std::string sound_config;
|
|
||||||
std::string display_config;
|
|
||||||
std::string server_config;
|
std::string server_config;
|
||||||
|
|
||||||
std::shared_ptr<input::InputDriver> input_driver;
|
std::shared_ptr<input::InputDriver> input_driver;
|
||||||
|
|||||||
Reference in New Issue
Block a user