From 9a7b39ed82e02f1e87eaf75de7211bac90810c8a Mon Sep 17 00:00:00 2001 From: elvez Date: Mon, 3 Jul 2006 22:01:19 +0000 Subject: [PATCH] - Completed plugin management system. Now we should start using it... git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@703 3ecf2c5c-341e-0410-92b4-d18e462d057c --- src/backend/invalid_plugin_exception.hh | 2 +- src/backend/module.cc | 39 ++++++++++++++++++------- src/backend/module.hh | 11 +++++++ src/backend/plugin_manager.cc | 8 ++++- 4 files changed, 47 insertions(+), 13 deletions(-) diff --git a/src/backend/invalid_plugin_exception.hh b/src/backend/invalid_plugin_exception.hh index b80d512..64f29d0 100644 --- a/src/backend/invalid_plugin_exception.hh +++ b/src/backend/invalid_plugin_exception.hh @@ -27,7 +27,7 @@ namespace sgpem { - class InvalidPluginException : std::runtime_error + class InvalidPluginException : public std::runtime_error { public: InvalidPluginException(const std::string& what); diff --git a/src/backend/module.cc b/src/backend/module.cc index 0dce959..49ab1b8 100644 --- a/src/backend/module.cc +++ b/src/backend/module.cc @@ -27,44 +27,60 @@ using namespace sgpem; Module::Module(const Glib::ustring& identifier) throw(InvalidPluginException) : Glib::Module(identifier), _enabled(false), _id(identifier) { - //FIXME Don't know what to doh!!! - throw InvalidPluginException(Glib::Module::get_last_error()); + // too stuff to put it on an inizialization list, don't you think? + on_init_ptr = NULL; + on_exit_ptr = NULL; + describe_ptr = NULL; + get_name_ptr = NULL; + get_author_ptr = NULL; + get_version_ptr = NULL; + + if(!(get_symbol("on_init", on_init_ptr) && + get_symbol("on_exit", on_exit_ptr) && + get_symbol("describe", describe_ptr) && + get_symbol("get_name", get_name_ptr) && + get_symbol("get_author", get_author_ptr) && + get_symbol("get_version", get_version_ptr))) + throw InvalidPluginException("incomplete/wrong exported interface"); } void Module::set_enabled(bool enabled) { - //FIXME Don't know what to doh!!! + if(_enabled == enabled) + return; + + if(enabled) + reinterpret_cast(on_init_ptr)(); + else + reinterpret_cast(on_exit_ptr)(); + _enabled = enabled; } Glib::ustring Module::get_name() const { - //FIXME Don't know what to doh!!! - return "doh!"; + return reinterpret_cast(get_name_ptr)(); } Glib::ustring Module::get_author() const { - //FIXME Don't know what to doh!!! - return "doh! doh!"; + return reinterpret_cast(get_author_ptr)(); } Glib::ustring Module::describe() const { - //FIXME Don't know what to doh!!! - return "homer insists in saying doh!"; + return reinterpret_cast(describe_ptr)(); } float Module::get_version() const { - //FIXME Don't know what to doh!!! - return -1.0f; + return reinterpret_cast(get_version_ptr)(); } bool @@ -72,3 +88,4 @@ Module::get_enabled() const { return _enabled; } + diff --git a/src/backend/module.hh b/src/backend/module.hh index 75f66db..04f6706 100644 --- a/src/backend/module.hh +++ b/src/backend/module.hh @@ -50,8 +50,19 @@ namespace sgpem bool get_enabled() const; private: + typedef void (*f_void)(void); + typedef Glib::ustring (*f_ustring)(void); + typedef float (*f_float)(void); + bool _enabled; Glib::ustring _id; + + void* on_init_ptr; + void* on_exit_ptr; + void* describe_ptr; + void* get_name_ptr; + void* get_author_ptr; + void* get_version_ptr; }; //~ class Module diff --git a/src/backend/plugin_manager.cc b/src/backend/plugin_manager.cc index e921a09..b7245f4 100644 --- a/src/backend/plugin_manager.cc +++ b/src/backend/plugin_manager.cc @@ -59,22 +59,28 @@ PluginManager::rescan_dirs() for(Glib::DirIterator dir_it = dir.begin(); dir_it != dir.end(); ++dir_it) { std::string module_path = Module::build_path(*it, *dir_it); + + std::cout << "Attempting to load module at path " << module_path << std::endl; try { module = new Module(module_path); if(*module) + { _modules.push_back(module); + std::cerr << "\tSuccess" << std::endl; + } else { - std::cerr << Glib::Module::get_last_error() << std::endl; + std::cerr << "\tFailed: " << Glib::Module::get_last_error() << std::endl; delete module; } } catch(InvalidPluginException e) { + std::cerr << "\tFailed, invalid plugin: " << e.what() << std::endl; } }