Relacs
0.9.8
|
#include <plugins.h>
Public Types | |
enum | ErrorCode { AlreadyLoaded, LibraryError, InvalidFile, CantGetFiles, LibraryInUse, EraseFailed, InvalidPlugin } |
typedef void *(* | PluginCreator )(void) |
Public Member Functions | |
Plugins (void) | |
~Plugins (void) | |
Static Public Member Functions | |
static int | open (const string &file) |
static int | open (int id) |
static int | openPath (const string &path, const string &relativepath, const StrQueue &pluginhomes) |
static int | openFile (const string &file) |
static int | close (int id) |
static int | close (const string &file) |
static int | close (void) |
static int | erase (int id) |
static int | erase (const string &file) |
static int | clear (void) |
static int | reopen (int id) |
static int | reopen (const string &file) |
static int | size (void) |
static bool | empty (void) |
static int | plugins (void) |
static int | plugins (int type) |
static string | ident (int index) |
static string | first (int type=0) |
static int | index (const string &plugin, int type=-1) |
static int | type (int index) |
static int | type (const string &plugin) |
static int | fileID (int index) |
static int | fileID (const string &plugin) |
static void * | create (int index) |
static void * | create (const string &plugin, int type) |
static int | destroy (int index) |
static int | destroy (const string &plugin, int type) |
static void | add (const string &ident, int type, PluginCreator create, const string &version) |
static void | erase (const string &ident, int type) |
static const string & | libraryErrors (void) |
static void | clearLibraryErrors (void) |
static const string & | classErrors (void) |
static void | clearClassErrors (void) |
Friends | |
ostream & | operator<< (ostream &str, const Plugins &plugins) |
Dynamically load plugins (libraries) into the running program.
Plugins has a file list with all library files that are opened and a plugins list containing the plugins (a library can contain more than one plugin).
With the open(), openPath(), and OpenFile() functions you can add files to the file list and load the libraries into the program. The plugins in the library automatically add themselves to the plugins list. The close() functions remove the libraries from the program but keep the filenames in the list. The plugins of a closed library are removed from the plugins list. To close the libraries and remove them from the file list use the erase() functions. The clear() function tries to erase all libraries. With reopen() a library can be first closed and than opened again. The number of library files in the list is returned by size(), the list can alos be empty().
Each plugin has an identifier string ident(), an index(), a type(), and is contained by the library file with file id fileID(). The type() of a plugin is used to group plugins of different type together, i.e. classes with the same base class. The identifier string of the first plugin in the list with a given type is returned by first(). The number of loaded plugins is plugins().
An instance of a plugin is created by create() and destroyed by destroy().
Errors concerning the library files are retuned by libraryErrors(). Errors concerning the plugin classes are retuned by classErrors().
In order to make a class a plugin that is managed by Plugins addPlugin() must be "called", i.e. it must be added to the end of the source file. A class can be added to or removed from the plugins explicitely by calling add() and erase(const string&,const string&,int), respectively.
typedef void*(* PluginCreator)(void) |
enum ErrorCode |
Error codes for handling plugins.
Plugins | ( | void | ) |
~Plugins | ( | void | ) |
Destructor. Does nothing.
|
static |
Load the library with file name file into the program if it is not already loaded (it may, however, be already in the list of library files).
[in] | file | the file name of the library to be loaded. |
|
static |
Load the library with id id into the program if it is not already loaded.
[in] | id | the identification number of the library to be loaded. |
|
static |
Load all libraries specified by the path path into the program. Relative pathes (not starting with a slash) are interpreted relative to relativepath, provided relativepath is not empty. If path is a pure filename (no directory, but may contain wildcards) then it is assumed to be found in one of the pluginhomes directories. If pluginhomes is an empty string, then pure filenames are also interpreted relative to relativepath, provided relativepath is not empty.
[in] | path | the file pattern (can include wildcard characters) selecting the libraries to be loaded. If path ends with a slash, "*" is added first. If path has no file extension, the appropriate extension (".so") is added. If the filename of path does not start with "lib", the filename is prefixed with "lib". |
[in] | relativepath | the path to be used for relative pathes. |
[in] | pluginhomes | default pathes for the plugin files. |
References Str::dir(), StrQueue::empty(), Str::empty(), Str::extension(), Str::find(), Str::notdir(), Str::providePeriod(), StrQueue::size(), Str::size(), and Str::strip().
Referenced by RELACSWidget::RELACSWidget().
|
static |
Load all libraries listed in the file file into the program.
[in] | file | the name of a text file that contains in each line the file name of a library that is to be loaded. |
|
static |
Close library specified by its id id. The library is not removed from the list. You can open the library again with the open() functions. Use erase() to close the library and remove it from the list.
[in] | id | the identification number of the library to be closed. |
|
static |
Close library specified by its file name file. The library is not removed from the list. You can open the library again with the open() functions. Use erase() to close the library and remove it from the list.
[in] | file | the file name of the library to be closed. |
|
static |
Close all libraries. The libraries are not removed from the list. You can open the libraries again with the open() functions. Use clear() to close the libraries and remove them from the list.
Referenced by RELACSWidget::~RELACSWidget().
|
static |
Close library specified by its id id and remove it form the list.
[in] | id | the identification number of the library to be erased. |
|
static |
Close library specified by its file name file and remove it form the list.
[in] | file | the file name of the library to be erased. |
|
static |
Close all libraries and remove them from the list.
|
static |
Load the library with id id into the program after closing it.
[in] | id | the identification number of the library to be reopened. |
Referenced by ReProData::reload().
|
static |
Load the library with file name file into the program after closing it.
[in] | file | the file name of the library to be reopened. |
|
static |
|
static |
true
if no libraries are contained in the list. Referenced by RELACSWidget::RELACSWidget().
|
static |
Referenced by RePros::RePros().
|
static |
[in] | type | the type of the plugins. |
|
static |
[in] | index | the index of the plugin. |
Referenced by RePros::RePros().
|
static |
|
static |
[in] | plugin | the name of the plugin. |
[in] | type | the type of the plugins. If negative, the type is not used to identify the plugin. |
Referenced by DeviceList< T, PluginID >::create().
|
static |
[in] | index | the index of the plugin. |
Referenced by RePros::RePros().
|
static |
|
static |
[in] | index | the index of the plugin. |
Referenced by ReProData::reload().
|
static |
|
static |
Constructs a new instance of the plugin specified by its index index.
[in] | index | the index of the plugin to be created. |
Referenced by DeviceList< T, PluginID >::create(), ControlTabs::createControls(), FilterDetectors::createFilters(), RELACSWidget::RELACSWidget(), ReProData::reload(), and RePros::RePros().
|
static |
|
static |
If you delete a plugin which has been created by one of the create functions, call this function to decrement its use count.
[in] | index | the index of the plugin to be destroyed. |
Referenced by AllDevices::clear(), FilterDetectors::clear(), FilterDetectors::createFilters(), ReProData::reload(), ControlTabs::~ControlTabs(), RELACSWidget::~RELACSWidget(), and RePros::~RePros().
|
static |
If you delete a plugin which has been created by one of the create functions, call this function to decrement its use count.
[in] | plugin | the identifier string of the plugin to be destroyed. |
[in] | type | the type of the plugin |
|
static |
Add a plugin with identifier string ident and plugin type type to the plugin list. The plugin can be created by calling create(). The plugin was compiled with version number version. If the version number does not match the one of the Plugins class, an error string is appened to the class errors which can be read using classErrors().
Referenced by RELACSWidget::RELACSWidget().
|
static |
Remove the plugin specified by its identifier string ident and plugin type type from the plugin list.
|
static |
Referenced by RELACSWidget::RELACSWidget().
|
static |
Clear the string containing the library errors.
|
static |
Get a string containing the names of all plugin-classes which could not be loaded.
Referenced by RELACSWidget::RELACSWidget().
|
static |
Clear the string containing the plugin-class errors.
|
friend |
Writes the content of the library file list and the plugin list to str.