From ff44c9cd55bff146c6c47277656a967045184c7b Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Fri, 27 Mar 2015 16:07:27 +0300 Subject: working module loader basic program options support abitilty to print installed modules info started config support implementation --- server/src/main.cpp | 106 +++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 85 insertions(+), 21 deletions(-) (limited to 'server/src/main.cpp') diff --git a/server/src/main.cpp b/server/src/main.cpp index 54bb498..67e5fa6 100644 --- a/server/src/main.cpp +++ b/server/src/main.cpp @@ -17,36 +17,100 @@ along with UDM. If not, see . */ +#include +#include +#include +#include +#include -#include #include +#include -core_api module_api; -void module_load_test() +core_api *module_api = nullptr; + +modules_handler *modules = nullptr; + +namespace bpo = boost::program_options; +namespace bpt = boost::property_tree; + +bpt::ptree config; + + + +int main(int argc, char *argv[]) { - void *lib = dlopen("./modules/metadata/libflat_files.so", RTLD_LAZY); - if(!lib) + bpo::options_description desc("Available commands and options"); + desc.add_options() + ("help", "this message") + ("daemon", "fork to background") + ("config", bpo::value(), "use specified config file instead of \"~/.config/udm/udm.conf\"") + ("list-modules", "list all installed modules") + ("run", "start UDM server") + ; + + bool daemon = false, run = false; + std::string config_path = "~/.config/udm/udm.conf"; + try{ + + bpo::variables_map vm; + bpo::store(bpo::parse_command_line(argc, argv, desc), vm); + bpo::notify(vm); + + //load config first, as it may be needed for other commands + if(vm.count("config")) + config_path = vm["config"].as(); + + if(boost::filesystem::exists(config_path) && boost::filesystem::is_regular(config_path)) + bpt::read_info(config_path, config); //TODO: finish this + else + std::cerr<<"failed to load config: \"" + config_path + "\", file does not exists or is not regular file\n"; + + + if(vm.count("help")) + { + std::cout<list_modules(); + return 0; + } + if(vm.count("run")) + { + run = true; + } + } + catch(std::exception &e) { - printf("%s\n", dlerror()); - return; + std::cerr<<"error: "<(f()); - m->load(&module_api); -} - + if(run) + { + if(daemon) + { + //TODO: fork here + } + } + //module_api must be created first + std::cerr<<"error: no command specified"<