- 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:
parent
9856a86c87
commit
9a7b39ed82
|
@ -27,7 +27,7 @@
|
|||
|
||||
namespace sgpem
|
||||
{
|
||||
class InvalidPluginException : std::runtime_error
|
||||
class InvalidPluginException : public std::runtime_error
|
||||
{
|
||||
public:
|
||||
InvalidPluginException(const std::string& what);
|
||||
|
|
|
@ -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<f_void>(on_init_ptr)();
|
||||
else
|
||||
reinterpret_cast<f_void>(on_exit_ptr)();
|
||||
|
||||
_enabled = enabled;
|
||||
}
|
||||
|
||||
Glib::ustring
|
||||
Module::get_name() const
|
||||
{
|
||||
//FIXME Don't know what to doh!!!
|
||||
return "doh!";
|
||||
return reinterpret_cast<f_ustring>(get_name_ptr)();
|
||||
}
|
||||
|
||||
Glib::ustring
|
||||
Module::get_author() const
|
||||
{
|
||||
//FIXME Don't know what to doh!!!
|
||||
return "doh! doh!";
|
||||
return reinterpret_cast<f_ustring>(get_author_ptr)();
|
||||
}
|
||||
|
||||
Glib::ustring
|
||||
Module::describe() const
|
||||
{
|
||||
//FIXME Don't know what to doh!!!
|
||||
return "homer insists in saying doh!";
|
||||
return reinterpret_cast<f_ustring>(describe_ptr)();
|
||||
}
|
||||
|
||||
float
|
||||
Module::get_version() const
|
||||
{
|
||||
//FIXME Don't know what to doh!!!
|
||||
return -1.0f;
|
||||
return reinterpret_cast<f_float>(get_version_ptr)();
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -72,3 +88,4 @@ Module::get_enabled() const
|
|||
{
|
||||
return _enabled;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue