Merge branch 'master' of github.com:swinginbird/flippr-code

This commit is contained in:
Johannes Wendel
2019-08-06 20:56:04 +02:00

View File

@@ -37,16 +37,8 @@ using namespace Poco;
FlippRServer::FlippRServer() :
help_requested(false),
input_port(9980),
output_port(9981),
input_config("Not set"),
matrix_config("Not set"),
lamp_config("Not set"),
solenoid_config("Not set"),
sound_config("Not set"),
display_config("Not set")
{
this->parse_server_config_file();
}
output_port(9981)
{}
void FlippRServer::parse_server_config_file()
{
@@ -99,6 +91,7 @@ void FlippRServer::uninitialize()
*/
void FlippRServer::initialize(Application &self)
{
this->parse_server_config_file();
//Todo May restructure with subsystems
//make this one application and subsystems ServerApplications
@@ -161,21 +154,13 @@ void FlippRServer::initialize_input_driver()
int FlippRServer::main(const std::vector<std::string>& args)
{
if(help_requested)
return Application::EXIT_OK;
std::unique_ptr<HTTPServer> output_server(this->build_output_server());
output_server->start();
std::unique_ptr<TCPServer> input_server(this->build_input_server());
logger().information("Server running!");
waitForTerminationRequest();
this->output_driver->deactivate_all_lamps();
this->output_driver->deactivate_displays();
output_server->stop();
if(!help_requested)
{
logger().information("Server running!");
waitForTerminationRequest();
}
return Application::EXIT_OK;
}
HTTPServer* FlippRServer::build_output_server()
@@ -206,17 +191,17 @@ void FlippRServer::defineOptions(OptionSet& options)
ServerApplication::defineOptions(options);
options.addOption(
Option("help", "h", "display argument help information")
Option("help", "h", "display this help")
.required(false)
.repeatable(false)
.callback(OptionCallback<FlippRServer>(
this, &FlippRServer::handle_help)));
options.addOption(Option("input-port", "i", "Define the port for the TCP-Input-Server, which represents the flipper inputs. Default 9980")
.required(false)
.repeatable(false)
.callback(OptionCallback<FlippRServer>(this, &FlippRServer::handle_config_file))
.argument("input-port", true));
.required(false)
.repeatable(false)
.callback(OptionCallback<FlippRServer>(this, &FlippRServer::handle_config_file))
.argument("input-port", true));
options.addOption(Option("output-port", "o", "Define the port for the HTTP-Output-Server, which represents the flipper outputs. Default 9981")
.required(false)
@@ -224,64 +209,16 @@ void FlippRServer::defineOptions(OptionSet& options)
.callback(OptionCallback<FlippRServer>(this, &FlippRServer::handle_config_file))
.argument("output-port", true));
options.addOption(Option("input-config", "I", "Specify where the input-config file is located. Only needed when not in this folder.")
.required(this->input_config == "Not set")
options.addOption(Option("server-config", "s", "Specify where the server-config file with paths to the other configs is located. Only needed when not in this folder.")
.required(true)
.repeatable(false)
.callback(OptionCallback<FlippRServer>(this, &FlippRServer::handle_config_file))
.argument("input-config", true));
options.addOption(Option("matrix-config", "M", "Specify where the matrix-config file is located. Only needed when not in this folder.")
.required(this->matrix_config == "Not set")
.repeatable(false)
.callback(OptionCallback<FlippRServer>(this, &FlippRServer::handle_config_file))
.argument("matric-config", true));
options.addOption(Option("lamp-config", "L", "Specify where the lamp-config file is located. Only needed when not in this folder.")
.required(this->lamp_config == "Not set")
.repeatable(false)
.callback(OptionCallback<FlippRServer>(this, &FlippRServer::handle_config_file))
.argument("lamp-config", true));
options.addOption(Option("solenoid-config", "N", "Specify where the solenoid-config file is located. Only needed when not in this folder.")
.required(this->solenoid_config == "Not set")
.repeatable(false)
.callback(OptionCallback<FlippRServer>(this, &FlippRServer::handle_config_file))
.argument("solenoid-config", true));
options.addOption(Option("sound-config", "S", "Specify where the sound-config file is located. Only needed when not in this folder.")
.required(this->sound_config == "Not set")
.repeatable(false)
.callback(OptionCallback<FlippRServer>(this, &FlippRServer::handle_config_file))
.argument("sound-config", true));
options.addOption(Option("display-config", "D", "Specify where the display-config file is located. Only needed when not in this folder.")
.required(this->display_config == "Not set")
.repeatable(false)
.callback(OptionCallback<FlippRServer>(this, &FlippRServer::handle_config_file))
.argument("display-config", true));
options.addOption(Option("server-config", "s", "Specify where the server-config file is located. Only needed when not in this folder.")
.required(this->display_config == "Not set")
.repeatable(false)
.callback(OptionCallback<FlippRServer>(this, &FlippRServer::handle_config_file))
.argument("server-config", true));
.argument("server-config", true));
}
void FlippRServer::handle_config_file(const std::string &name, const std::string &value)
{
if(name == "input-config")
this->input_config = value;
else if(name == "matrix-config")
this->matrix_config = value;
else if(name == "lamp-config")
this->lamp_config = value;
else if(name == "solenoid-config")
this->solenoid_config = value;
else if(name == "sound-config")
this->sound_config = value;
else if(name == "display-config")
this->display_config = value;
else if(name == "input-port")
if(name == "input-port")
this->input_port = std::stoi(value);
else if(name == "output-port")
this->output_port = std::stoi(value);
@@ -301,9 +238,7 @@ void FlippRServer::handle_help(const std::string& name, const std::string& value
helpFormatter.setCommand(commandName());
helpFormatter.setUsage("OPTIONS");
helpFormatter.setHeader(
"The FlippR-Server, appropriate config-files must either be located in the actual folder\
or the paths must be specified by commandline options. \
The config file paths as well as the port settings can be specified in a a file server_config.json");
"The FlippR-Server, one must specify a json with all needed config files.");
helpFormatter.format(std::cout);
stopOptionsProcessing();
help_requested = true;