- 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
This commit is contained in:
elvez 2006-07-03 22:01:19 +00:00
parent 9856a86c87
commit 9a7b39ed82
4 changed files with 47 additions and 13 deletions

View File

@ -27,7 +27,7 @@
namespace sgpem namespace sgpem
{ {
class InvalidPluginException : std::runtime_error class InvalidPluginException : public std::runtime_error
{ {
public: public:
InvalidPluginException(const std::string& what); InvalidPluginException(const std::string& what);

View File

@ -27,44 +27,60 @@ using namespace sgpem;
Module::Module(const Glib::ustring& identifier) throw(InvalidPluginException) : Module::Module(const Glib::ustring& identifier) throw(InvalidPluginException) :
Glib::Module(identifier), _enabled(false), _id(identifier) Glib::Module(identifier), _enabled(false), _id(identifier)
{ {
//FIXME Don't know what to doh!!! // too stuff to put it on an inizialization list, don't you think?
throw InvalidPluginException(Glib::Module::get_last_error()); 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 void
Module::set_enabled(bool enabled) Module::set_enabled(bool enabled)
{ {
//FIXME Don't know what to doh!!! if(_enabled == enabled)
return;
if(enabled)
reinterpret_cast<f_void>(on_init_ptr)();
else
reinterpret_cast<f_void>(on_exit_ptr)();
_enabled = enabled; _enabled = enabled;
} }
Glib::ustring Glib::ustring
Module::get_name() const Module::get_name() const
{ {
//FIXME Don't know what to doh!!! return reinterpret_cast<f_ustring>(get_name_ptr)();
return "doh!";
} }
Glib::ustring Glib::ustring
Module::get_author() const Module::get_author() const
{ {
//FIXME Don't know what to doh!!! return reinterpret_cast<f_ustring>(get_author_ptr)();
return "doh! doh!";
} }
Glib::ustring Glib::ustring
Module::describe() const Module::describe() const
{ {
//FIXME Don't know what to doh!!! return reinterpret_cast<f_ustring>(describe_ptr)();
return "homer insists in saying doh!";
} }
float float
Module::get_version() const Module::get_version() const
{ {
//FIXME Don't know what to doh!!! return reinterpret_cast<f_float>(get_version_ptr)();
return -1.0f;
} }
bool bool
@ -72,3 +88,4 @@ Module::get_enabled() const
{ {
return _enabled; return _enabled;
} }

View File

@ -50,8 +50,19 @@ namespace sgpem
bool get_enabled() const; bool get_enabled() const;
private: private:
typedef void (*f_void)(void);
typedef Glib::ustring (*f_ustring)(void);
typedef float (*f_float)(void);
bool _enabled; bool _enabled;
Glib::ustring _id; 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 }; //~ class Module

View File

@ -59,22 +59,28 @@ PluginManager::rescan_dirs()
for(Glib::DirIterator dir_it = dir.begin(); dir_it != dir.end(); ++dir_it) for(Glib::DirIterator dir_it = dir.begin(); dir_it != dir.end(); ++dir_it)
{ {
std::string module_path = Module::build_path(*it, *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 try
{ {
module = new Module(module_path); module = new Module(module_path);
if(*module) if(*module)
{
_modules.push_back(module); _modules.push_back(module);
std::cerr << "\tSuccess" << std::endl;
}
else else
{ {
std::cerr << Glib::Module::get_last_error() << std::endl; std::cerr << "\tFailed: " << Glib::Module::get_last_error() << std::endl;
delete module; delete module;
} }
} }
catch(InvalidPluginException e) catch(InvalidPluginException e)
{ {
std::cerr << "\tFailed, invalid plugin: " << e.what() << std::endl;
} }
} }