aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--CMakeLists.txt2
-rw-r--r--api/umosapi.cpp (renamed from umosapi.cpp)77
-rw-r--r--api/umosapi.h (renamed from umosapi.h)0
-rw-r--r--main.cpp71
-rw-r--r--shared.h2
5 files changed, 78 insertions, 74 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0d2a615..b4a15ed 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -43,7 +43,7 @@ endif(NOT JSONC_FOUND)
#add_executable(umosapi test.cpp)
-add_executable(umosapi umosapi.cpp config.cpp umosapi.h config.h shared.h)
+add_executable(umosapi main.cpp config.cpp api/umosapi.cpp api/umosapi.h config.h shared.h)
set_property(TARGET umosapi PROPERTY CXX_STANDARD 17)
diff --git a/umosapi.cpp b/api/umosapi.cpp
index 72c4728..65f28d2 100644
--- a/umosapi.cpp
+++ b/api/umosapi.cpp
@@ -1,10 +1,3 @@
-#include "umosapi.h"
-
-#include <string.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <pwd.h>
-
#include <bsoncxx/builder/stream/document.hpp>
#include <bsoncxx/json.hpp>
@@ -19,14 +12,9 @@
#include <nlohmann/json.hpp>
-#include "clara.hpp"
-#include "shared.h"
-#include "config.h"
-
-std::map<std::string, std::string> config;
+#include "umosapi.h"
+#include "../shared.h"
-using namespace std;
-using namespace Pistache;
using bsoncxx::builder::stream::close_array;
using bsoncxx::builder::stream::close_document;
@@ -37,7 +25,8 @@ using bsoncxx::builder::stream::open_document;
using json = nlohmann::json;
-using namespace clara;
+using namespace std;
+using namespace Pistache;
namespace Generic {
void handleReady(const Rest::Request&, Http::ResponseWriter response) {
@@ -184,61 +173,3 @@ void UmosapiService::addUObject(const Rest::Request& request, Http::ResponseWrit
response.send(Http::Code::Ok, json_object_to_json_string_ext(jsonObject, JSON_C_TO_STRING_SPACED | JSON_C_TO_STRING_PRETTY), MIME(Application, Json));
json_object_put(jsonObject);
}
-
-
-int main(int argc, char *argv[]) {
-
- string config_path = "";
- const char *homedir;
-
- if ((homedir = getenv("XDG_CONFIG_HOME")) == NULL || (homedir = getenv("HOME")) == NULL) {
- homedir = getpwuid(getuid())->pw_dir;
- }
-
- config_path.append(homedir);
- config_path.append("/.config/umosapi/config.txt");
-
- bool showHelp = false;
- int 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( 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 << cli << std::endl;
- exit(1);
- }
-
- if ( showHelp ) {
- std::cerr << cli << std::endl;
- exit(1);
- }
-
- Address addr(Ipv4::any(), Port(config_port));
-
- cout << "Using " << hardware_concurrency() << " cores";
- cout << " - " << thr << " threads" << endl;
- cout << "Listen on 0.0.0.0:" << config_port << endl;
-
- cout << "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;
- exit (EXIT_FAILURE);
- }
-
- load_config(config_path);
-
- cout << "Using swaggerui " << config["swaggerui"] << " path" << endl;
- cout << "Using mongoURI " << config["mongoURI"] << endl;
-
- UmosapiService umosapi(addr);
-
- umosapi.init(thr);
- umosapi.start(config["swaggerui"]);
-}
diff --git a/umosapi.h b/api/umosapi.h
index 684f9d5..684f9d5 100644
--- a/umosapi.h
+++ b/api/umosapi.h
diff --git a/main.cpp b/main.cpp
new file mode 100644
index 0000000..c0cdb0d
--- /dev/null
+++ b/main.cpp
@@ -0,0 +1,71 @@
+#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <pwd.h>
+
+#include "clara.hpp"
+#include "shared.h"
+#include "config.h"
+#include "api/umosapi.h"
+
+std::map<std::string, std::string> config;
+
+using namespace std;
+using namespace Pistache;
+
+int main(int argc, char *argv[]) {
+
+ string config_path = "";
+ const char *homedir;
+
+ if ((homedir = getenv("XDG_CONFIG_HOME")) == NULL || (homedir = getenv("HOME")) == NULL) {
+ homedir = getpwuid(getuid())->pw_dir;
+ }
+
+ config_path.append(homedir);
+ config_path.append("/.config/umosapi/config.txt");
+
+ bool showHelp = false;
+ int 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( 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 << cli << std::endl;
+ exit(1);
+ }
+
+ if ( showHelp ) {
+ std::cerr << cli << std::endl;
+ exit(1);
+ }
+
+ Address addr(Ipv4::any(), Port(config_port));
+
+ cout << "Using " << hardware_concurrency() << " cores";
+ cout << " - " << thr << " threads" << endl;
+ cout << "Listen on 0.0.0.0:" << config_port << endl;
+
+ cout << "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;
+ exit (EXIT_FAILURE);
+ }
+
+ load_config(config_path);
+
+ cout << "Using swaggerui " << config["swaggerui"] << " path" << endl;
+ cout << "Using mongoURI " << config["mongoURI"] << endl;
+
+ UmosapiService umosapi(addr);
+
+ umosapi.init(thr);
+ umosapi.start(config["swaggerui"]);
+}
diff --git a/shared.h b/shared.h
index 2f796c7..0814b6c 100644
--- a/shared.h
+++ b/shared.h
@@ -1,6 +1,8 @@
#ifndef SHARED_H_
#define SHARED_H_
+#include <map>
+
extern std::map<std::string, std::string> config;
#endif