From 0c9dd8ea102db49c9702d36d8a13c013d6e5df86 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Sun, 29 Mar 2015 04:41:17 +0300 Subject: api fixes implemented get_module_settings --- server/src/modules_handler.cpp | 64 ++++++++++++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 21 deletions(-) (limited to 'server/src/modules_handler.cpp') diff --git a/server/src/modules_handler.cpp b/server/src/modules_handler.cpp index 1626d91..7a17ec7 100644 --- a/server/src/modules_handler.cpp +++ b/server/src/modules_handler.cpp @@ -20,6 +20,7 @@ #include "modules_handler.h" #include "main.h" +#include "utilities.h" #include #include #include @@ -46,12 +47,13 @@ void modules_handler::load_metadata_modules(const std::string &path) { for(boost::filesystem::directory_iterator i(path), end = boost::filesystem::directory_iterator(); i != end; ++i) { - void *lib = dlopen(i->path().generic_string().c_str(), RTLD_LAZY); + void *lib = dlopen(i->path().generic_string().c_str(), RTLD_LAZY |RTLD_GLOBAL); if(!lib) { printf("failed to open library \"%s\" with error: %s\n", i->path().c_str(), dlerror()); return; } + void *fptr = dlsym(lib, "udm_metadata_module_load"); if(!fptr) { @@ -59,10 +61,10 @@ void modules_handler::load_metadata_modules(const std::string &path) dlclose(lib); return; } - void *(*f)(void); - f = (void* (*)())fptr; + module_metadata_storage *(*f)(void); + f = (module_metadata_storage *(*)(void))fptr; //TODO: aditional sanity checks - module_metadata_storage *m = static_cast(f()); + module_metadata_storage *m = f(); m->load(module_api); sync_module_settings(m); metadata_modules.push_back(m); @@ -89,10 +91,10 @@ void modules_handler::load_downloader_modules(const std::string &path) dlclose(lib); return; } - void *(*f)(void); - f = (void* (*)())fptr; + module_downloader *(*f)(void); + f = (module_downloader *(*)(void))fptr; //TODO: aditional sanity checks - module_metadata_storage *m = static_cast(f()); + module_downloader *m = f(); m->load(module_api); sync_module_settings(m); metadata_modules.push_back(m); @@ -109,11 +111,21 @@ std::string modules_handler::get_self_path() return s; } -std::string modules_handler::list_modules(short verbose_level) +std::string modules_handler::list_modules() { std::string buf; buf += "Installed metadata modules:\n"; - for(auto i = metadata_modules.begin(), end = metadata_modules.end(); i != end; ++i) + buf += list_modules_single_type_internal((std::list)metadata_modules); + buf += "\nInstalled downloader modules:\n"; + buf += list_modules_single_type_internal(downloader_modules); + + return buf; +} + +std::string modules_handler::list_modules_single_type_internal(const std::list &modules) +{ + std::string buf; + for(auto i = modules.begin(), end = modules.end(); i != end; ++i) { buf += "\tName: "; buf += (*i)->get_module_info().name; @@ -130,16 +142,7 @@ std::string modules_handler::list_modules(short verbose_level) buf += i1->second; } } - buf += "\n"; - } - buf += "Installed downloader modules:\n"; - for(auto i = downloader_modules.begin(), end = downloader_modules.end(); i != end; ++i) - { - buf += "\t"; - buf += (*i)->get_module_info().name; - buf += " (" + (*i)->get_module_info().description + ") "; - buf += "v" + (*i)->get_module_info().version; - buf += "\n"; + buf += "\n\n"; } return buf; } @@ -159,14 +162,33 @@ void modules_handler::sync_module_settings(module_base *m) modules_handler::modules_handler() { self_path = get_self_path(); +} + +void modules_handler::load_modules() +{ boost::filesystem::path p(self_path); std::string self_dir = p.parent_path().generic_string(); load_metadata_modules(self_dir + "/modules/metadata"); - load_metadata_modules("~/.share/udm/modules/metadata"); + load_metadata_modules(replace_home_var("~/.share/udm/modules/metadata")); load_metadata_modules("/usr/lib/udm/modules/metadata"); load_downloader_modules(self_dir + "/modules/downloader"); - load_downloader_modules("~/.share/udm/modules/downloader"); + load_downloader_modules(replace_home_var("~/.share/udm/modules/downloader")); load_downloader_modules("/usr/lib/udm/modules/downloader"); + on_modules_loaded(); +} + +void modules_handler::on_modules_loaded() +{ + for(auto i = metadata_modules.begin(), end = metadata_modules.end(); i != end; ++i) + { + if(!(*i)->get_module_info().on_modules_loaded.empty()) + (*i)->get_module_info().on_modules_loaded(); + } + for(auto i = downloader_modules.begin(), end = downloader_modules.end(); i != end; ++i) + { + if(!(*i)->get_module_info().on_modules_loaded.empty()) + (*i)->get_module_info().on_modules_loaded(); + } } modules_handler::~modules_handler() -- cgit v1.2.3