- 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:
parent
f181c93527
commit
45cc6733e4
|
@ -23,47 +23,45 @@
|
|||
#include "plugin.hh"
|
||||
#include "python_policy_manager.hh"
|
||||
|
||||
#include <glibmm/ustring.h>
|
||||
|
||||
using namespace sgpem;
|
||||
|
||||
// Is this OK? If not, we must use a function with a local static variable...
|
||||
PythonPolicyManager* _policy_manager = NULL;
|
||||
|
||||
void
|
||||
Plugin::on_init()
|
||||
sgpem__Plugin__on_init()
|
||||
{
|
||||
if(_policy_manager == NULL)
|
||||
_policy_manager = new sgpem::PythonPolicyManager();
|
||||
}
|
||||
|
||||
void
|
||||
Plugin::on_exit()
|
||||
sgpem__Plugin__on_exit()
|
||||
{
|
||||
delete _policy_manager;
|
||||
_policy_manager = NULL;
|
||||
}
|
||||
|
||||
Glib::ustring
|
||||
Plugin::describe()
|
||||
const char*
|
||||
sgpem__Plugin__describe()
|
||||
{
|
||||
return "This plugin manages policies written in the Python scripting language";
|
||||
}
|
||||
|
||||
Glib::ustring
|
||||
Plugin::get_name()
|
||||
const char*
|
||||
sgpem__Plugin__get_name()
|
||||
{
|
||||
return "Pyloader";
|
||||
}
|
||||
|
||||
Glib::ustring
|
||||
Plugin::get_author()
|
||||
const char*
|
||||
sgpem__Plugin__get_author()
|
||||
{
|
||||
return "Copyright 2005, 2006, University of Padova, dept. of Pure and Applied Mathematics";
|
||||
}
|
||||
|
||||
float
|
||||
Plugin::get_version()
|
||||
sgpem__Plugin__get_version()
|
||||
{
|
||||
return 1.0f;
|
||||
}
|
||||
|
|
|
@ -22,46 +22,43 @@
|
|||
|
||||
#include "plugin.hh"
|
||||
|
||||
#include <glibmm/ustring.h>
|
||||
|
||||
using namespace sgpem;
|
||||
|
||||
// static XMLSerializer* _serializer = NULL;
|
||||
//static XMLSerializer* _serializer = NULL;
|
||||
|
||||
void
|
||||
Plugin::on_init()
|
||||
sgpem__Plugin__on_init()
|
||||
{
|
||||
// if(_serializer == NULL)
|
||||
// _serializer = new sgpem::XMLSerializer();
|
||||
}
|
||||
|
||||
void
|
||||
Plugin::on_exit()
|
||||
sgpem__Plugin__on_exit()
|
||||
{
|
||||
// delete _serializer;
|
||||
// _serializer = NULL;
|
||||
}
|
||||
|
||||
Glib::ustring
|
||||
Plugin::describe()
|
||||
const char*
|
||||
sgpem__Plugin__describe()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
Glib::ustring
|
||||
Plugin::get_name()
|
||||
const char*
|
||||
sgpem__Plugin__get_name()
|
||||
{
|
||||
return "XmlSave";
|
||||
}
|
||||
|
||||
Glib::ustring
|
||||
Plugin::get_author()
|
||||
const char*
|
||||
sgpem__Plugin__get_author()
|
||||
{
|
||||
return "Copyright 2005, 2006, University of Padova, dept. of Pure and Applied Mathematics";
|
||||
}
|
||||
|
||||
float
|
||||
Plugin::get_version()
|
||||
sgpem__Plugin__get_version()
|
||||
{
|
||||
return 1.0f;
|
||||
}
|
||||
|
||||
|
|
|
@ -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) &&
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue