summaryrefslogtreecommitdiff
path: root/server/src
diff options
context:
space:
mode:
Diffstat (limited to 'server/src')
-rw-r--r--server/src/api_core.cpp26
-rw-r--r--server/src/main.cpp4
-rw-r--r--server/src/modules_handler.cpp64
3 files changed, 69 insertions, 25 deletions
diff --git a/server/src/api_core.cpp b/server/src/api_core.cpp
index 5412624..6cee810 100644
--- a/server/src/api_core.cpp
+++ b/server/src/api_core.cpp
@@ -19,23 +19,41 @@
*/
-#include <api_core.h>
+#include "api_core.h"
+#include "main.h"
+#include "api_module_base.h"
+#include <boost/foreach.hpp>
+extern runtime_config_s runtime_config;
-bool core_api::metadata_set(const module_base *m, const std::string &setting_name, const std::vector<char> &data)
+
+bool core_api::metadata_set(module_base *m, const std::string &setting_name, const std::vector<char> &data)
{
//TODO
return true;
}
-bool core_api::metadata_get(const module_base *m, const std::string &setting_name, std::vector<char> &data)
+bool core_api::metadata_get(module_base *m, const std::string &setting_name, std::vector<char> &data)
{
//TODO
return true;
}
-bool core_api::metadata_remove(const module_base *m, const std::string &setting_name)
+bool core_api::metadata_remove(module_base *m, const std::string &setting_name)
{
//TODO
return true;
}
+
+std::map<std::string, std::string> core_api::get_module_settings(module_base *m)
+{
+ //TODO:
+ std::map<std::string, std::string> settings;
+ std::string module = "modules.";
+ module += m->get_module_info().name;
+ for(auto i = runtime_config.config_file.get_child(module).begin(), end = runtime_config.config_file.get_child(module).end(); i != end; ++i)
+ {
+ settings[i->first] = i->second.get_value<std::string>("");
+ }
+ return settings;
+}
diff --git a/server/src/main.cpp b/server/src/main.cpp
index e8b4e2c..8cf9efc 100644
--- a/server/src/main.cpp
+++ b/server/src/main.cpp
@@ -37,6 +37,7 @@ namespace bpo = boost::program_options;
runtime_config_s runtime_config;
+//TODO: "core" config section architecture, define base settings
int main(int argc, char *argv[])
@@ -89,7 +90,10 @@ int main(int argc, char *argv[])
if(!module_api)
module_api = new core_api;
if(!modules)
+ {
modules = new modules_handler;
+ modules->load_modules();
+ }
std::cout<<modules->list_modules();
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 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()