- 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 "plugin.hh"
|
||||||
#include "python_policy_manager.hh"
|
#include "python_policy_manager.hh"
|
||||||
|
|
||||||
#include <glibmm/ustring.h>
|
|
||||||
|
|
||||||
using namespace sgpem;
|
using namespace sgpem;
|
||||||
|
|
||||||
// Is this OK? If not, we must use a function with a local static variable...
|
// Is this OK? If not, we must use a function with a local static variable...
|
||||||
PythonPolicyManager* _policy_manager = NULL;
|
PythonPolicyManager* _policy_manager = NULL;
|
||||||
|
|
||||||
void
|
void
|
||||||
Plugin::on_init()
|
sgpem__Plugin__on_init()
|
||||||
{
|
{
|
||||||
if(_policy_manager == NULL)
|
if(_policy_manager == NULL)
|
||||||
_policy_manager = new sgpem::PythonPolicyManager();
|
_policy_manager = new sgpem::PythonPolicyManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Plugin::on_exit()
|
sgpem__Plugin__on_exit()
|
||||||
{
|
{
|
||||||
delete _policy_manager;
|
delete _policy_manager;
|
||||||
_policy_manager = NULL;
|
_policy_manager = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Glib::ustring
|
const char*
|
||||||
Plugin::describe()
|
sgpem__Plugin__describe()
|
||||||
{
|
{
|
||||||
return "This plugin manages policies written in the Python scripting language";
|
return "This plugin manages policies written in the Python scripting language";
|
||||||
}
|
}
|
||||||
|
|
||||||
Glib::ustring
|
const char*
|
||||||
Plugin::get_name()
|
sgpem__Plugin__get_name()
|
||||||
{
|
{
|
||||||
return "Pyloader";
|
return "Pyloader";
|
||||||
}
|
}
|
||||||
|
|
||||||
Glib::ustring
|
const char*
|
||||||
Plugin::get_author()
|
sgpem__Plugin__get_author()
|
||||||
{
|
{
|
||||||
return "Copyright 2005, 2006, University of Padova, dept. of Pure and Applied Mathematics";
|
return "Copyright 2005, 2006, University of Padova, dept. of Pure and Applied Mathematics";
|
||||||
}
|
}
|
||||||
|
|
||||||
float
|
float
|
||||||
Plugin::get_version()
|
sgpem__Plugin__get_version()
|
||||||
{
|
{
|
||||||
return 1.0f;
|
return 1.0f;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,46 +22,43 @@
|
||||||
|
|
||||||
#include "plugin.hh"
|
#include "plugin.hh"
|
||||||
|
|
||||||
#include <glibmm/ustring.h>
|
|
||||||
|
|
||||||
using namespace sgpem;
|
|
||||||
|
|
||||||
//static XMLSerializer* _serializer = NULL;
|
//static XMLSerializer* _serializer = NULL;
|
||||||
|
|
||||||
void
|
void
|
||||||
Plugin::on_init()
|
sgpem__Plugin__on_init()
|
||||||
{
|
{
|
||||||
// if(_serializer == NULL)
|
// if(_serializer == NULL)
|
||||||
// _serializer = new sgpem::XMLSerializer();
|
// _serializer = new sgpem::XMLSerializer();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Plugin::on_exit()
|
sgpem__Plugin__on_exit()
|
||||||
{
|
{
|
||||||
// delete _serializer;
|
// delete _serializer;
|
||||||
// _serializer = NULL;
|
// _serializer = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Glib::ustring
|
const char*
|
||||||
Plugin::describe()
|
sgpem__Plugin__describe()
|
||||||
{
|
{
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
Glib::ustring
|
const char*
|
||||||
Plugin::get_name()
|
sgpem__Plugin__get_name()
|
||||||
{
|
{
|
||||||
return "XmlSave";
|
return "XmlSave";
|
||||||
}
|
}
|
||||||
|
|
||||||
Glib::ustring
|
const char*
|
||||||
Plugin::get_author()
|
sgpem__Plugin__get_author()
|
||||||
{
|
{
|
||||||
return "Copyright 2005, 2006, University of Padova, dept. of Pure and Applied Mathematics";
|
return "Copyright 2005, 2006, University of Padova, dept. of Pure and Applied Mathematics";
|
||||||
}
|
}
|
||||||
|
|
||||||
float
|
float
|
||||||
Plugin::get_version()
|
sgpem__Plugin__get_version()
|
||||||
{
|
{
|
||||||
return 1.0f;
|
return 1.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ Module::Module(const Glib::ustring& identifier) throw(InvalidPluginException) :
|
||||||
get_version_ptr(NULL)
|
get_version_ptr(NULL)
|
||||||
{
|
{
|
||||||
// Type-safeness here is an optional, as always. :-)
|
// 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) &&
|
if(!(get_symbol(prefix + "on_init", (void*&) on_init_ptr) &&
|
||||||
get_symbol(prefix + "on_exit", (void*&) on_exit_ptr) &&
|
get_symbol(prefix + "on_exit", (void*&) on_exit_ptr) &&
|
||||||
get_symbol(prefix + "describe", (void*&) describe_ptr) &&
|
get_symbol(prefix + "describe", (void*&) describe_ptr) &&
|
||||||
|
|
|
@ -23,42 +23,36 @@
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include <glibmm/ustring.h>
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
|
||||||
/** \file plugin.hh
|
/** \file plugin.hh
|
||||||
* All loadable modules that want to act as plugins
|
* All loadable modules that want to act as plugins
|
||||||
* for SGPEMv2 should implement this interface. */
|
* for SGPEMv2 should implement this interface.
|
||||||
|
|
||||||
namespace sgpem
|
|
||||||
{
|
|
||||||
/** \brief The interface a specific plugin should implement
|
|
||||||
*
|
|
||||||
* Only the header file containing this interface
|
* Only the header file containing this interface
|
||||||
* should be provided by the backend library. Every plugin
|
* should be provided by the backend library. Every plugin
|
||||||
* will then implement its set of static functions.
|
* will then implement its set of static functions.
|
||||||
* Thus every plugin will export these very symbols
|
* Thus every plugin will export these very symbols
|
||||||
* outside its DSO.
|
* outside its DSO.
|
||||||
*/
|
*/
|
||||||
class SG_DLLEXPORT Plugin
|
|
||||||
{
|
|
||||||
/** \brief Called when a plugin is loaded and enabled
|
/** \brief Called when a plugin is loaded and enabled
|
||||||
*
|
*
|
||||||
* Sets up the plugin's initial state and
|
* Sets up the plugin's initial state and
|
||||||
* performs needed actions before its usage can start.
|
* performs needed actions before its usage can start.
|
||||||
*/
|
*/
|
||||||
static void SG_DLLEXPORT on_init();
|
void sgpem__Plugin__on_init();
|
||||||
|
|
||||||
static void SG_DLLEXPORT on_exit();
|
void sgpem__Plugin__on_exit();
|
||||||
static Glib::ustring SG_DLLEXPORT describe();
|
const char* sgpem__Plugin__describe();
|
||||||
static Glib::ustring SG_DLLEXPORT get_name();
|
const char* sgpem__Plugin__get_name();
|
||||||
static Glib::ustring SG_DLLEXPORT get_author();
|
const char* sgpem__Plugin__get_author();
|
||||||
static float SG_DLLEXPORT get_version();
|
float sgpem__Plugin__get_version();
|
||||||
|
|
||||||
private:
|
#ifdef __cplusplus
|
||||||
SG_DLLLOCAL Plugin();
|
|
||||||
}
|
}
|
||||||
; //~ class Plugin
|
#endif
|
||||||
|
|
||||||
} //~ namespace sgpem
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -27,6 +27,8 @@
|
||||||
#include "singleton.tcc"
|
#include "singleton.tcc"
|
||||||
|
|
||||||
#include <glibmm/fileutils.h>
|
#include <glibmm/fileutils.h>
|
||||||
|
#include <glibmm/pattern.h>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
using namespace sgpem;
|
using namespace sgpem;
|
||||||
|
@ -52,11 +54,16 @@ PluginManager::rescan_dirs()
|
||||||
GlobalPreferences& prefs = GlobalPreferences::get_instance();
|
GlobalPreferences& prefs = GlobalPreferences::get_instance();
|
||||||
GlobalPreferences::dir_iterator it = prefs.modules_dir_begin();
|
GlobalPreferences::dir_iterator it = prefs.modules_dir_begin();
|
||||||
|
|
||||||
|
Glib::PatternSpec shared_obj("*.so");
|
||||||
|
|
||||||
while(it != prefs.modules_dir_end())
|
while(it != prefs.modules_dir_end())
|
||||||
{
|
{
|
||||||
Glib::Dir dir(*it);
|
Glib::Dir dir(*it);
|
||||||
|
|
||||||
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)
|
||||||
|
{
|
||||||
|
// only attempt to load .so files
|
||||||
|
if(shared_obj.match(*dir_it))
|
||||||
{
|
{
|
||||||
std::string module_path = Module::build_path(*it, *dir_it);
|
std::string module_path = Module::build_path(*it, *dir_it);
|
||||||
|
|
||||||
|
@ -83,6 +90,7 @@ PluginManager::rescan_dirs()
|
||||||
std::cerr << "\tFailed, invalid plugin: " << e.what() << std::endl;
|
std::cerr << "\tFailed, invalid plugin: " << e.what() << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
it++;
|
it++;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue