summaryrefslogtreecommitdiff
path: root/datastore-leveldb/src
diff options
context:
space:
mode:
Diffstat (limited to 'datastore-leveldb/src')
-rw-r--r--datastore-leveldb/src/server.cpp37
1 files changed, 33 insertions, 4 deletions
diff --git a/datastore-leveldb/src/server.cpp b/datastore-leveldb/src/server.cpp
index 8dd0ee2..c2c702d 100644
--- a/datastore-leveldb/src/server.cpp
+++ b/datastore-leveldb/src/server.cpp
@@ -5,6 +5,7 @@
#include <thread>
#include <boost/regex.hpp>
+#include <boost/program_options.hpp>
#include "mongoose.h"
#include "db.h"
@@ -41,14 +42,43 @@ void sigint_handler(int s) {
exit(0);
}
+namespace po = boost::program_options;
+
int main(int argc, char **argv) {
- struct mg_callbacks callbacks;
+ // Program options
+ po::options_description desc("Program options");
+ desc.add_options()
+ ("wwwroot", po::value<std::string>()->required(), "Path to www root directory")
+ ("port", po::value<int>()->default_value(8080), "HTTP Port")
+ ("help", "Print help message")
+ ;
+
+ po::variables_map vm;
+ po::store(po::parse_command_line(argc, argv, desc), vm);
+ try {
+ po::notify(vm);
+ } catch(boost::program_options::required_option& e) {
+ std::cerr << "ERROR: " << e.what() << std::endl << std::endl;
+ return 1;
+ }
+
+ if (vm.count("help")) {
+ std::cout << "Usage: " << argv[0] << std::endl << std::endl;
+ std::cout << desc << std::endl;
+ return 0;
+ }
+ const char *port = strdup(std::to_string(vm["wwwroot"].as<int>()).c_str());
+ const char *wwwroot = strdup(vm["wwwroot"].as<std::string>().c_str());
+
+ // Mongoose options
const char *options[] = {
"num_threads", "8",
- "listening_ports", "8080",
- "document_root", "wwwroot",
+ "listening_ports", port,
+ "document_root", wwwroot,
NULL};
+ // Mongoose callbacks
+ struct mg_callbacks callbacks;
memset(&callbacks, 0, sizeof(callbacks));
callbacks.begin_request = begin_request_handler;
@@ -66,7 +96,6 @@ int main(int argc, char **argv) {
web_handle_api_range_size_R,
web_handle_api_range_size));
-
// Signals: handle C-c
struct sigaction action;
memset(&action, 0, sizeof(action));