- Fixed plugin interface. Now both plugins are loaded. Not tried calling the exported functions, though...

- To make sure libraries are not loaded multiple times, only .so files are considered. Beware that this is not portable

git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@731 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
elvez 2006-07-05 17:03:04 +00:00
parent f181c93527
commit 45cc6733e4
5 changed files with 70 additions and 73 deletions

View file

@ -36,7 +36,7 @@ Module::Module(const Glib::ustring& identifier) throw(InvalidPluginException) :
get_version_ptr(NULL)
{
// Type-safeness here is an optional, as always. :-)
std::string prefix = "sgpem::Plugin::";
std::string prefix = "sgpem__Plugin__";
if(!(get_symbol(prefix + "on_init", (void*&) on_init_ptr) &&
get_symbol(prefix + "on_exit", (void*&) on_exit_ptr) &&
get_symbol(prefix + "describe", (void*&) describe_ptr) &&

View file

@ -23,42 +23,36 @@
#include "config.h"
#include <glibmm/ustring.h>
/** \file plugin.hh
* All loadable modules that want to act as plugins
* for SGPEMv2 should implement this interface. */
namespace sgpem
#ifdef __cplusplus
extern "C"
{
/** \brief The interface a specific plugin should implement
*
* Only the header file containing this interface
#endif
/** \file plugin.hh
* All loadable modules that want to act as plugins
* for SGPEMv2 should implement this interface.
* Only the header file containing this interface
* should be provided by the backend library. Every plugin
* will then implement its set of static functions.
* Thus every plugin will export these very symbols
* outside its DSO.
*/
class SG_DLLEXPORT Plugin
{
/** \brief Called when a plugin is loaded and enabled
*
* Sets up the plugin's initial state and
* performs needed actions before its usage can start.
*/
static void SG_DLLEXPORT on_init();
static void SG_DLLEXPORT on_exit();
static Glib::ustring SG_DLLEXPORT describe();
static Glib::ustring SG_DLLEXPORT get_name();
static Glib::ustring SG_DLLEXPORT get_author();
static float SG_DLLEXPORT get_version();
/** \brief Called when a plugin is loaded and enabled
*
* Sets up the plugin's initial state and
* performs needed actions before its usage can start.
*/
void sgpem__Plugin__on_init();
private:
SG_DLLLOCAL Plugin();
}
; //~ class Plugin
void sgpem__Plugin__on_exit();
const char* sgpem__Plugin__describe();
const char* sgpem__Plugin__get_name();
const char* sgpem__Plugin__get_author();
float sgpem__Plugin__get_version();
} //~ namespace sgpem
#ifdef __cplusplus
}
#endif
#endif

View file

@ -27,6 +27,8 @@
#include "singleton.tcc"
#include <glibmm/fileutils.h>
#include <glibmm/pattern.h>
#include <iostream>
using namespace sgpem;
@ -52,35 +54,41 @@ PluginManager::rescan_dirs()
GlobalPreferences& prefs = GlobalPreferences::get_instance();
GlobalPreferences::dir_iterator it = prefs.modules_dir_begin();
Glib::PatternSpec shared_obj("*.so");
while(it != prefs.modules_dir_end())
{
Glib::Dir 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::cout << "Attempting to load module at path " << module_path << std::endl;
try
// only attempt to load .so files
if(shared_obj.match(*dir_it))
{
module = new Module(module_path);
std::string module_path = Module::build_path(*it, *dir_it);
if(*module)
std::cout << "Attempting to load module at path " << module_path << std::endl;
try
{
_modules.push_back(module);
std::cerr << "\tSuccess" << std::endl;
}
else
{
std::cerr << "\tFailed: " << Glib::Module::get_last_error() << std::endl;
delete module;
}
module = new Module(module_path);
}
catch(InvalidPluginException e)
{
std::cerr << "\tFailed, invalid plugin: " << e.what() << std::endl;
if(*module)
{
_modules.push_back(module);
std::cerr << "\tSuccess" << std::endl;
}
else
{
std::cerr << "\tFailed: " << Glib::Module::get_last_error() << std::endl;
delete module;
}
}
catch(InvalidPluginException e)
{
std::cerr << "\tFailed, invalid plugin: " << e.what() << std::endl;
}
}
}