summaryrefslogtreecommitdiff
path: root/server/src/modules_handler.cpp
diff options
context:
space:
mode:
authorGluzskiy Alexandr <sss@sss.chaoslab.ru>2015-03-29 04:41:17 +0300
committerGluzskiy Alexandr <sss@sss.chaoslab.ru>2015-03-29 04:41:17 +0300
commit0c9dd8ea102db49c9702d36d8a13c013d6e5df86 (patch)
tree2b0041410439799eeb9bf3a8aae43948480cb1c8 /server/src/modules_handler.cpp
parentd85b9e99218f4cab4410149415348d8a365c4828 (diff)
api fixes
implemented get_module_settings
Diffstat (limited to 'server/src/modules_handler.cpp')
-rw-r--r--server/src/modules_handler.cpp64
1 files changed, 43 insertions, 21 deletions
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 <unistd.h>
#include <dlfcn.h>
#include <string>
@@ -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<module_metadata_storage*>(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<module_metadata_storage*>(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<module_base*>)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<module_base*> &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()