From 68d640763f2d563cc71e140d971fa88eaca37b0c Mon Sep 17 00:00:00 2001 From: Noahrav Date: Thu, 21 Dec 2023 16:12:58 +0100 Subject: [PATCH] feat: running server --- CMakeLists.txt | 1 + README.md | 3 ++- src/api/api.h | 17 +++++++++++++++++ src/cu_submitter.cpp | 22 +++++++++++++++++----- 4 files changed, 37 insertions(+), 6 deletions(-) create mode 100644 src/api/api.h diff --git a/CMakeLists.txt b/CMakeLists.txt index bc917c0..21ece75 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,7 @@ add_subdirectory(deps) set(CMAKE_CXX_STANDARD 20) set(PROJECT_SOURCES + src/api/api.h src/cu_submitter.cpp src/chgen/chgen.cpp src/chgen/chgen.h src/data/changelog.cpp src/data/changelog.h diff --git a/README.md b/README.md index 55c0cc7..8005658 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ The executable is build/cu_submitter ## CLI ./cu_submitter --help | --usage : prints the usage\ +./cu_submitter [-p ] : opens backend server on specific port; 8080 by default\ ./cu_submitter --chgen : generates a changelog text file\ ./cu_submitter --transfer : transfers the modified files to the destination path\ -./cu_submitter --submit [] : copy the modified files to a submission archive +./cu_submitter --submit [] : copy the modified files to a submission folder diff --git a/src/api/api.h b/src/api/api.h new file mode 100644 index 0000000..f4d434e --- /dev/null +++ b/src/api/api.h @@ -0,0 +1,17 @@ +#ifndef CU_SUBMITTER_API_H +#define CU_SUBMITTER_API_H + +#include + +using namespace Pistache; + +class CUSubmitterHandler : public Http::Handler { +public: + HTTP_PROTOTYPE(CUSubmitterHandler) + + void onRequest(const Http::Request& request, Http::ResponseWriter response) { + response.send(Http::Code::Ok, "CU Submitter backend is reponding\n"); + } +}; + +#endif //CU_SUBMITTER_API_H \ No newline at end of file diff --git a/src/cu_submitter.cpp b/src/cu_submitter.cpp index abfef12..5f1aa1e 100644 --- a/src/cu_submitter.cpp +++ b/src/cu_submitter.cpp @@ -1,6 +1,6 @@ #include -#include +#include "api/api.h" #include "chgen/chgen.h" #include "transfer/transfer.h" #include "submit/submit.h" @@ -12,20 +12,20 @@ * @program cu_submitter * @brief The main entry point for the program. */ - int main(int argc, char* argv[]) { - if (argc >= 2) { + if (argc >= 2 && std::string(argv[1]) != "-p") { //CLI mode const std::string option = argv[1]; if (option == "--help" || option == "--usage") { std::string usage_message = "USAGE\n"; usage_message += "-----\n"; + usage_message += "[-p ] : opens backend server on specific port; 8080 by default\n"; usage_message += "--help | --usage : prints this message\n"; usage_message += "--chgen : generates a changelog text file\n"; usage_message += "--transfer : transfers the modified files to the destination path\n"; - usage_message += "--submit [] : compress the modified files to a submission archive\n"; + usage_message += "--submit [] : copy the modified files to a submission folder\n"; print(usage_message); } else if (option == "--chgen") { @@ -119,9 +119,21 @@ int main(int argc, char* argv[]) return 0; } + std::string port = "8080"; + if (std::string(argv[1]) == "-p" && argc < 3) { + error("Invalid arguments"); + return 1; + } else if (std::string(argv[1]) == "-p") { + port = argv[2]; + } + Address addr(Ipv4::any(), Port(stoi(port))); + auto opts = Http::Endpoint::options().threads(1); + Http::Endpoint server(addr); - return 0; + server.init(opts); + server.setHandler(Http::make_handler()); + server.serve(); }