summaryrefslogtreecommitdiff
path: root/datastore-leveldb
diff options
context:
space:
mode:
authorYves Fischer <yvesf-git@xapek.org>2013-04-30 17:48:16 +0200
committerYves Fischer <yvesf-git@xapek.org>2013-04-30 17:48:16 +0200
commit8810ba02335d60b2afda0a2d1efb101461dac891 (patch)
tree25e43ff7c00f68357e5369a58ff273d90f4e71ed /datastore-leveldb
parentce0727c4f43d4e043d8f0d338c8a4c8db53000f2 (diff)
downloadebus-alt-8810ba02335d60b2afda0a2d1efb101461dac891.tar.gz
ebus-alt-8810ba02335d60b2afda0a2d1efb101461dac891.zip
leveldb: programm_options
Diffstat (limited to 'datastore-leveldb')
-rw-r--r--datastore-leveldb/Makefile2
-rw-r--r--datastore-leveldb/src/server.cpp37
2 files changed, 34 insertions, 5 deletions
diff --git a/datastore-leveldb/Makefile b/datastore-leveldb/Makefile
index 6a6c9a3..6a55822 100644
--- a/datastore-leveldb/Makefile
+++ b/datastore-leveldb/Makefile
@@ -3,7 +3,7 @@ OUT = bin/server
CFLAGS += -Wall -DNO_CGI -DNO_POPEN -DUSE_IPV6 -DNO_SSL
CXXFLAGS += -Wall -std=c++11 -Imongoose
-LDFLAGS += -lleveldb -lboost_regex
+LDFLAGS += -lleveldb -lboost_regex -lboost_program_options
ifdef DEBUG
CFLAGS += -g -O0
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));