summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/include/modules_handler.h3
-rw-r--r--server/src/main.cpp46
-rw-r--r--server/src/modules_handler.cpp43
-rw-r--r--server/udm-server.cbp3
4 files changed, 70 insertions, 25 deletions
diff --git a/server/include/modules_handler.h b/server/include/modules_handler.h
index efcbebc..2459d9c 100644
--- a/server/include/modules_handler.h
+++ b/server/include/modules_handler.h
@@ -30,11 +30,12 @@ class modules_handler
{
public:
modules_handler();
- std::string list_modules();
+ std::string list_modules(short verbose_level = 0);
~modules_handler();
private:
void load_metadata_modules(const std::string &path);
void load_downloader_modules(const std::string &path);
+ void sync_module_settings(module_base *m);
std::string get_self_path();
std::string self_path;
std::list<module_metadata_storage*> metadata_modules;
diff --git a/server/src/main.cpp b/server/src/main.cpp
index 08fe5b7..e8b4e2c 100644
--- a/server/src/main.cpp
+++ b/server/src/main.cpp
@@ -18,13 +18,13 @@
*/
#include <boost/program_options.hpp>
-#include <boost/property_tree/ptree.hpp>
-#include <boost/property_tree/info_parser.hpp>
#include <boost/filesystem.hpp>
#include <iostream>
-#include <api_module_metadata_storage.h>
-#include <modules_handler.h>
+#include "api_module_metadata_storage.h"
+#include "modules_handler.h"
+#include "utilities.h"
+#include "main.h"
core_api *module_api = nullptr;
@@ -32,9 +32,10 @@ core_api *module_api = nullptr;
modules_handler *modules = nullptr;
namespace bpo = boost::program_options;
-namespace bpt = boost::property_tree;
-bpt::ptree config;
+
+
+runtime_config_s runtime_config;
@@ -42,19 +43,20 @@ int main(int argc, char *argv[])
{
bpo::options_description desc("Available commands and options");
desc.add_options()
- ("help", "this message")
- ("daemon", "fork to background")
- ("config", bpo::value<std::string>(), "use specified config file instead of \"~/.config/udm/udm.conf\"")
- ("list-modules", "list all installed modules")
+ ("help,h", "this message")
+ ("daemon,d", "fork to background (must be combined with \"--run\", does nothing alone)")
+ ("config,c", bpo::value<std::string>(), "use specified config file instead of \"~/.config/udm/udm.conf\"")
+ ("list-modules", "list all installed modules (you can set verbosity level, accepted values from 0 to 1, default = 0)")
+ ("verbosity,v", bpo::value<short>()->default_value(0), "set global verbosity level")
("run", "start UDM server")
;
bool daemon = false, run = false;
- std::string config_path = "~/.config/udm/udm.conf";
+ std::string config_path = "~/.config/udm/udm.conf", parsed_config_path;
try{
bpo::variables_map vm;
- bpo::store(bpo::parse_command_line(argc, argv, desc), vm);
+ bpo::store(bpo::command_line_parser(argc, argv).options(desc).style(bpo::command_line_style::unix_style | bpo::command_line_style::allow_long_disguise).run(), vm);
bpo::notify(vm);
//load config first, as it may be needed for other commands
@@ -62,15 +64,16 @@ int main(int argc, char *argv[])
config_path = vm["config"].as<std::string>();
{
- std::string tmp_path = config_path, home = getenv("HOME");
- for(std::string::size_type p1 = tmp_path.find("~"); p1 != std::string::npos; p1 = tmp_path.find("~", p1))
- tmp_path.replace(p1, 1, home);
- if(boost::filesystem::exists(tmp_path) && boost::filesystem::is_regular(tmp_path))
- bpt::read_info(tmp_path, config); //TODO: finish this
+ parsed_config_path = replace_home_var(config_path);
+ if(boost::filesystem::exists(parsed_config_path) && boost::filesystem::is_regular(parsed_config_path))
+ bpt::read_info(parsed_config_path, runtime_config.config_file); //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("verbosity"))
+ {
+ runtime_config.verbosity = vm["verbosity"].as<short>();
+ }
if(vm.count("help"))
{
@@ -88,6 +91,7 @@ int main(int argc, char *argv[])
if(!modules)
modules = new modules_handler;
std::cout<<modules->list_modules();
+ bpt::write_info(parsed_config_path, runtime_config.config_file); //save config on exit
return 0;
}
if(vm.count("run"))
@@ -112,10 +116,14 @@ int main(int argc, char *argv[])
{
//TODO: fork here
}
+ //TODO: run here
}
- //module_api must be created first
std::cerr<<"error: no command specified"<<std::endl;
std::cout<<desc<<std::endl;
+ bpt::write_info(parsed_config_path, runtime_config.config_file); //save config on exit
+
+
+
return 0;
}
diff --git a/server/src/modules_handler.cpp b/server/src/modules_handler.cpp
index a6dbcef..1626d91 100644
--- a/server/src/modules_handler.cpp
+++ b/server/src/modules_handler.cpp
@@ -19,14 +19,23 @@
*/
#include "modules_handler.h"
+#include "main.h"
#include <unistd.h>
#include <dlfcn.h>
#include <string>
#include <boost/filesystem.hpp>
+#include <iostream>
+
+
+
-#include <iostream>
+
+namespace bpt = boost::property_tree;
+
+extern runtime_config_s runtime_config;
+
extern core_api *module_api;
@@ -55,6 +64,7 @@ void modules_handler::load_metadata_modules(const std::string &path)
//TODO: aditional sanity checks
module_metadata_storage *m = static_cast<module_metadata_storage*>(f());
m->load(module_api);
+ sync_module_settings(m);
metadata_modules.push_back(m);
}
}
@@ -84,6 +94,7 @@ void modules_handler::load_downloader_modules(const std::string &path)
//TODO: aditional sanity checks
module_metadata_storage *m = static_cast<module_metadata_storage*>(f());
m->load(module_api);
+ sync_module_settings(m);
metadata_modules.push_back(m);
}
}
@@ -98,16 +109,27 @@ std::string modules_handler::get_self_path()
return s;
}
-std::string modules_handler::list_modules()
+std::string modules_handler::list_modules(short verbose_level)
{
std::string buf;
buf += "Installed metadata modules:\n";
for(auto i = metadata_modules.begin(), end = metadata_modules.end(); i != end; ++i)
{
- buf += "\t";
+ buf += "\tName: ";
buf += (*i)->get_module_info().name;
- buf += " (" + (*i)->get_module_info().description + ") ";
- buf += "v" + (*i)->get_module_info().version;
+ buf += "\n\tDescription: " +(*i)->get_module_info().description;
+ buf += "\n\tVersion: " + (*i)->get_module_info().version;
+ if(runtime_config.verbosity >= 1)
+ {
+ buf += "\n\tAvailable options:";
+ for(auto i1 = (*i)->get_module_info().default_settings.begin(), end = (*i)->get_module_info().default_settings.end(); i1 != end; ++i1)
+ {
+ buf += "\n\t\t";
+ buf += i1->first;
+ buf += " = ";
+ buf += i1->second;
+ }
+ }
buf += "\n";
}
buf += "Installed downloader modules:\n";
@@ -122,6 +144,17 @@ std::string modules_handler::list_modules()
return buf;
}
+void modules_handler::sync_module_settings(module_base *m)
+{
+ for(auto i = m->get_module_info().default_settings.begin(), end = m->get_module_info().default_settings.end(); i != end; ++i)
+ {
+ std::string setting = "modules." + m->get_module_info().name + "." + i->first;
+ std::string current_val = runtime_config.config_file.get<std::string>(setting, "not set"), default_val = i->second;
+ if(current_val == "not set" || current_val != default_val)
+ runtime_config.config_file.put(setting, i->second);
+ }
+}
+
modules_handler::modules_handler()
{
diff --git a/server/udm-server.cbp b/server/udm-server.cbp
index de8ccd5..a416bdb 100644
--- a/server/udm-server.cbp
+++ b/server/udm-server.cbp
@@ -51,12 +51,15 @@
<Unit filename="include/api_module_base.h" />
<Unit filename="include/api_module_downloader.h" />
<Unit filename="include/api_module_metadata_storage.h" />
+ <Unit filename="include/main.h" />
<Unit filename="include/modules_handler.h" />
<Unit filename="include/protocol.h" />
+ <Unit filename="include/utilities.h" />
<Unit filename="src/api_core.cpp" />
<Unit filename="src/main.cpp" />
<Unit filename="src/modules_handler.cpp" />
<Unit filename="src/protocol.cpp" />
+ <Unit filename="src/utilities.cpp" />
<Extensions>
<code_completion />
<debugger />