Skip to content

Commit

Permalink
feat: running server
Browse files Browse the repository at this point in the history
  • Loading branch information
noahrav committed Dec 21, 2023
1 parent 20ce7f2 commit 68d6407
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ The executable is build/cu_submitter
## CLI

./cu_submitter --help | --usage : prints the usage\
./cu_submitter [-p <port>] : opens backend server on specific port; 8080 by default\
./cu_submitter --chgen <base_path> <modified_path> : generates a changelog text file\
./cu_submitter --transfer <unmodified_copy_path> <modified_copy_path> <destination_path> : transfers the modified files to the destination path\
./cu_submitter --submit <unmodified_copy_path> <modified_copy_path> [<archive_path>] : copy the modified files to a submission archive
./cu_submitter --submit <unmodified_copy_path> <modified_copy_path> [<archive_path>] : copy the modified files to a submission folder
17 changes: 17 additions & 0 deletions src/api/api.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef CU_SUBMITTER_API_H
#define CU_SUBMITTER_API_H

#include <pistache/endpoint.h>

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
22 changes: 17 additions & 5 deletions src/cu_submitter.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <iostream>
#include <pistache/endpoint.h>

#include "api/api.h"
#include "chgen/chgen.h"
#include "transfer/transfer.h"
#include "submit/submit.h"
Expand All @@ -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 <port>] : opens backend server on specific port; 8080 by default\n";
usage_message += "--help | --usage : prints this message\n";
usage_message += "--chgen <base_path> <modified_path> : generates a changelog text file\n";
usage_message += "--transfer <unmodified_copy_path> <modified_copy_path> <destination_path> : transfers the modified files to the destination path\n";
usage_message += "--submit <unmodified_copy_path> <modified_copy_path> [<archive_path>] : compress the modified files to a submission archive\n";
usage_message += "--submit <unmodified_copy_path> <modified_copy_path> [<archive_path>] : copy the modified files to a submission folder\n";

print(usage_message);
} else if (option == "--chgen") {
Expand Down Expand Up @@ -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<CUSubmitterHandler>());
server.serve();
}

0 comments on commit 68d6407

Please sign in to comment.