From 8810ba02335d60b2afda0a2d1efb101461dac891 Mon Sep 17 00:00:00 2001 From: Yves Fischer Date: Tue, 30 Apr 2013 17:48:16 +0200 Subject: leveldb: programm_options --- datastore-leveldb/src/server.cpp | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) (limited to 'datastore-leveldb/src') 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 #include +#include #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()->required(), "Path to www root directory") + ("port", po::value()->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()).c_str()); + const char *wwwroot = strdup(vm["wwwroot"].as().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)); -- cgit v1.2.1