sgpemv2/src/backend/module.cc
elvez 45cc6733e4 - 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
2006-07-05 17:03:04 +00:00

94 lines
2.3 KiB
C++

// src/backend/module.hh - Copyright 2005, 2006, University
// of Padova, dept. of Pure and Applied
// Mathematics
//
// This file is part of SGPEMv2.
//
// This is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// SGPEMv2 is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with SGPEMv2; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "config.h"
#include "module.hh"
using namespace sgpem;
Module::Module(const Glib::ustring& identifier) throw(InvalidPluginException) :
Glib::Module(identifier),
_enabled(false),
_id(identifier),
on_init_ptr(NULL),
on_exit_ptr(NULL),
describe_ptr(NULL),
get_name_ptr(NULL),
get_author_ptr(NULL),
get_version_ptr(NULL)
{
// Type-safeness here is an optional, as always. :-)
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) &&
get_symbol(prefix + "get_name", (void*&) get_name_ptr) &&
get_symbol(prefix + "get_author", (void*&) get_author_ptr) &&
get_symbol(prefix + "get_version", (void*&) get_version_ptr)))
throw InvalidPluginException("incomplete/wrong exported interface");
}
void
Module::set_enabled(bool enabled)
{
if(_enabled == enabled)
return;
if(enabled)
on_init_ptr();
else
on_exit_ptr();
_enabled = enabled;
}
Glib::ustring
Module::get_name() const
{
return get_name_ptr();
}
Glib::ustring
Module::get_author() const
{
return get_author_ptr();
}
Glib::ustring
Module::describe() const
{
return describe_ptr();
}
float
Module::get_version() const
{
return get_version_ptr();
}
bool
Module::get_enabled() const
{
return _enabled;
}