diff options
author | Yves Fischer <yvesf-git@xapek.org> | 2013-04-30 17:48:16 +0200 |
---|---|---|
committer | Yves Fischer <yvesf-git@xapek.org> | 2013-04-30 17:48:16 +0200 |
commit | 8810ba02335d60b2afda0a2d1efb101461dac891 (patch) | |
tree | 25e43ff7c00f68357e5369a58ff273d90f4e71ed /datastore-leveldb/src | |
parent | ce0727c4f43d4e043d8f0d338c8a4c8db53000f2 (diff) | |
download | ebus-alt-8810ba02335d60b2afda0a2d1efb101461dac891.tar.gz ebus-alt-8810ba02335d60b2afda0a2d1efb101461dac891.zip |
leveldb: programm_options
Diffstat (limited to 'datastore-leveldb/src')
-rw-r--r-- | datastore-leveldb/src/server.cpp | 37 |
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)); |