- 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>
|
//static XMLSerializer* _serializer = NULL;
|
||||||
|
|
||||||
using namespace sgpem;
|
|
||||||
|
|
||||||
// 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"
|
||||||
/** \file plugin.hh
|
|
||||||
* All loadable modules that want to act as plugins
|
|
||||||
* for SGPEMv2 should implement this interface. */
|
|
||||||
|
|
||||||
namespace sgpem
|
|
||||||
{
|
{
|
||||||
/** \brief The interface a specific plugin should implement
|
#endif
|
||||||
*
|
|
||||||
* Only the header file containing this interface
|
/** \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
|
* 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
|
|
||||||
*
|
|
||||||
* 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();
|
/** \brief Called when a plugin is loaded and enabled
|
||||||
static Glib::ustring SG_DLLEXPORT describe();
|
*
|
||||||
static Glib::ustring SG_DLLEXPORT get_name();
|
* Sets up the plugin's initial state and
|
||||||
static Glib::ustring SG_DLLEXPORT get_author();
|
* performs needed actions before its usage can start.
|
||||||
static float SG_DLLEXPORT get_version();
|
*/
|
||||||
|
void sgpem__Plugin__on_init();
|
||||||
|
|
||||||
private:
|
void sgpem__Plugin__on_exit();
|
||||||
SG_DLLLOCAL Plugin();
|
const char* sgpem__Plugin__describe();
|
||||||
}
|
const char* sgpem__Plugin__get_name();
|
||||||
; //~ class Plugin
|
const char* sgpem__Plugin__get_author();
|
||||||
|
float sgpem__Plugin__get_version();
|
||||||
|
|
||||||
} //~ namespace sgpem
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#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,35 +54,41 @@ 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)
|
||||||
{
|
{
|
||||||
std::string module_path = Module::build_path(*it, *dir_it);
|
// only attempt to load .so files
|
||||||
|
if(shared_obj.match(*dir_it))
|
||||||
std::cout << "Attempting to load module at path " << module_path << std::endl;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
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);
|
module = new Module(module_path);
|
||||||
std::cerr << "\tSuccess" << std::endl;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
std::cerr << "\tFailed: " << Glib::Module::get_last_error() << std::endl;
|
|
||||||
delete module;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
if(*module)
|
||||||
catch(InvalidPluginException e)
|
{
|
||||||
{
|
_modules.push_back(module);
|
||||||
std::cerr << "\tFailed, invalid plugin: " << e.what() << std::endl;
|
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