From 1b922f7319f821fe3daf302a8c68131aaa94f586 Mon Sep 17 00:00:00 2001 From: neodarz Date: Fri, 6 Sep 2019 18:04:40 +0200 Subject: Change code to use Restbed --- main.cpp | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index c0cdb0d..05a6232 100644 --- a/main.cpp +++ b/main.cpp @@ -8,10 +8,11 @@ #include "config.h" #include "api/umosapi.h" +#include "service.hpp" + std::map config; using namespace std; -using namespace Pistache; int main(int argc, char *argv[]) { @@ -26,16 +27,16 @@ int main(int argc, char *argv[]) { config_path.append("/.config/umosapi/config.txt"); bool showHelp = false; - int config_port = 9080; + config["port"] = "9080"; int thr = 2; auto cli = clara::detail::Help(showHelp) | clara::detail::Opt( config_path, "config" )["-c"]["--config"]("Config file path. Default `~/.config/umosapi/config.txt`.") - | clara::detail::Opt( config_port, "port" )["-p"]["--port"]("Port to listen. Default: `9080`.") + | clara::detail::Opt( config["port"], "port" )["-p"]["--port"]("Port to listen. Default: `9080`.") | clara::detail::Opt( thr, "treads" )["-t"]["--threads"]("Number of threads. Default: `2`."); auto result = cli.parse( clara::detail::Args( argc, argv ) ); if( !result ) { - std::cerr << "Error in command line: " << result.errorMessage() << std::endl; + std::cerr << "ERROR: Error in command line: " << result.errorMessage() << std::endl; std::cerr << cli << std::endl; exit(1); } @@ -45,27 +46,35 @@ int main(int argc, char *argv[]) { exit(1); } - Address addr(Ipv4::any(), Port(config_port)); + //Address addr(Ipv4::any(), Port(config["port"])); - cout << "Using " << hardware_concurrency() << " cores"; + cout << "INFO: Using " << std::thread::hardware_concurrency() << " cores"; cout << " - " << thr << " threads" << endl; - cout << "Listen on 0.0.0.0:" << config_port << endl; + cout << "INFO: Listen on 0.0.0.0:" << config["port"] << endl; - cout << "Using config file '" << config_path << "'" << endl; + cout << "INFO: Using config file '" << config_path << "'" << endl; if (!std::filesystem::exists(config_path)) { - cout << "Error fatal : config file '" << config_path << "' not found" << endl; - cout << "config.txt is search here: ~/.config/umosapi/config.txt" << endl; + cout << "ERROR: Error fatal : config file '" << config_path << "' not found" << endl; + cout << "ERROR: config.txt is search here: ~/.config/umosapi/config.txt" << endl; exit (EXIT_FAILURE); } load_config(config_path); - cout << "Using swaggerui " << config["swaggerui"] << " path" << endl; - cout << "Using mongoURI " << config["mongoURI"] << endl; + //cout << "Using swaggerui " << config["swaggerui"] << " path" << endl; + cout << "INFO: No support for swagger for the moment" << endl; + cout << "INFO: Using mongoURI " << config["mongoURI"] << endl; + /* UmosapiService umosapi(addr); umosapi.init(thr); umosapi.start(config["swaggerui"]); + */ + + UmosapiService umosapi; + umosapi.init(); + umosapi.start(std::stoi(config["port"]), thr); + } -- cgit v1.2.1 From 5b66830ca806e00f415d6ee83b15e410130de371 Mon Sep 17 00:00:00 2001 From: neodarz Date: Mon, 9 Sep 2019 15:42:58 +0200 Subject: Add some adjustement to make server more stable --- main.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index 05a6232..9cf4127 100644 --- a/main.cpp +++ b/main.cpp @@ -77,4 +77,6 @@ int main(int argc, char *argv[]) { umosapi.init(); umosapi.start(std::stoi(config["port"]), thr); + return EXIT_SUCCESS; + } -- cgit v1.2.1 From bc6aeaa834d666221171d302d4f101ce65608898 Mon Sep 17 00:00:00 2001 From: neodarz Date: Mon, 9 Sep 2019 17:17:44 +0200 Subject: Refactoring some code to be more readable --- main.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index 9cf4127..dd3b794 100644 --- a/main.cpp +++ b/main.cpp @@ -12,8 +12,6 @@ std::map config; -using namespace std; - int main(int argc, char *argv[]) { string config_path = ""; @@ -73,7 +71,7 @@ int main(int argc, char *argv[]) { umosapi.start(config["swaggerui"]); */ - UmosapiService umosapi; + UmosapiService::Api umosapi; umosapi.init(); umosapi.start(std::stoi(config["port"]), thr); -- cgit v1.2.1 From 260ce7465a66427832da15caae0077323dc9750a Mon Sep 17 00:00:00 2001 From: neodarz Date: Mon, 9 Sep 2019 17:56:09 +0200 Subject: Refactoring a little more --- main.cpp | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index dd3b794..2ca3399 100644 --- a/main.cpp +++ b/main.cpp @@ -8,13 +8,12 @@ #include "config.h" #include "api/umosapi.h" -#include "service.hpp" std::map config; int main(int argc, char *argv[]) { - string config_path = ""; + std::string config_path = ""; const char *homedir; if ((homedir = getenv("XDG_CONFIG_HOME")) == NULL || (homedir = getenv("HOME")) == NULL) { @@ -44,32 +43,23 @@ int main(int argc, char *argv[]) { exit(1); } - //Address addr(Ipv4::any(), Port(config["port"])); + std::cout << "INFO: Using " << std::thread::hardware_concurrency() << " cores"; + std::cout << " - " << thr << " threads" << std::endl; + std::cout << "INFO: Listen on 0.0.0.0:" << config["port"] << std::endl; - cout << "INFO: Using " << std::thread::hardware_concurrency() << " cores"; - cout << " - " << thr << " threads" << endl; - cout << "INFO: Listen on 0.0.0.0:" << config["port"] << endl; - - cout << "INFO: Using config file '" << config_path << "'" << endl; + std::cout << "INFO: Using config file '" << config_path << "'" << std::endl; if (!std::filesystem::exists(config_path)) { - cout << "ERROR: Error fatal : config file '" << config_path << "' not found" << endl; - cout << "ERROR: config.txt is search here: ~/.config/umosapi/config.txt" << endl; + std::cout << "ERROR: Error fatal : config file '" << config_path << "' not found" << std::endl; + std::cout << "ERROR: config.txt is search here: ~/.config/umosapi/config.txt" << std::endl; exit (EXIT_FAILURE); } load_config(config_path); - //cout << "Using swaggerui " << config["swaggerui"] << " path" << endl; - cout << "INFO: No support for swagger for the moment" << endl; - cout << "INFO: Using mongoURI " << config["mongoURI"] << endl; - /* - - UmosapiService umosapi(addr); - - umosapi.init(thr); - umosapi.start(config["swaggerui"]); - */ + std::cout << "Using swaggerui " << config["swaggerui"] << " path" << std::endl; + std::cout << "INFO: No support for swagger for the moment" << std::endl; + std::cout << "INFO: Using mongoURI " << config["mongoURI"] << std::endl; UmosapiService::Api umosapi; umosapi.init(); -- cgit v1.2.1