Sirikata
|
Plugin provides loading of plugins to allow for extension of the system. More...
#include <Plugin.hpp>
Public Member Functions | |
Plugin (const String &path) | |
~Plugin () | |
bool | load () |
Loads the plugin, returning true if it satisfies all the plugin requirements, i.e. | |
bool | unload () |
Forcefully unloads the plugin. | |
void | initialize () |
Run this plugin's initialization code. | |
int | incref () |
Increment the ref count on this plugin by one. | |
int | decref () |
Decrease the ref count on this plugin by one. | |
void | destroy () |
Destroy this plugin. | |
String | name () |
Get the name of this plugin. | |
int | refcount () |
Get the current refcount of this plugin. | |
Private Types | |
typedef void(* | InitFunc )() |
typedef void(* | DestroyFunc )() |
typedef const char *(* | NameFunc )() |
typedef int(* | RefCountFunc )() |
typedef int(* | IncRefCountFunc )() |
typedef int(* | DecRefCountFunc )() |
Private Attributes | |
DynamicLibrary | mDL |
InitFunc | mInit |
DestroyFunc | mDestroy |
NameFunc | mName |
RefCountFunc | mRefCount |
IncRefCountFunc | mIncRefCount |
DecRefCountFunc | mDecRefCount |
int | mInitialized |
Plugin provides loading of plugins to allow for extension of the system.
Plugins are dynamic libraries which register services with the core system. Generally these will take the form of implementations of services which are registered with the appropriate factory. Plugins must provide a simple interface implemented as a small set of C functions: void init(); // initialize this plugin, generally just register services void destroy(); // destroy this plugin, generally just unregister services const char* name(); // get the name of this plugin int refcount(); // get the reference count of this plugin These should be mostly self explanatory. The reference count is maintained by the plugin but used by the main system itself. While a plugin's code is potentially in use it should ensure that its refcount is greater than 0.
typedef int(* Sirikata::Plugin::DecRefCountFunc)() [private] |
typedef void(* Sirikata::Plugin::DestroyFunc)() [private] |
typedef int(* Sirikata::Plugin::IncRefCountFunc)() [private] |
typedef void(* Sirikata::Plugin::InitFunc)() [private] |
typedef const char*(* Sirikata::Plugin::NameFunc)() [private] |
typedef int(* Sirikata::Plugin::RefCountFunc)() [private] |
Sirikata::Plugin::Plugin | ( | const String & | path | ) |
Sirikata::Plugin::~Plugin | ( | ) |
References destroy(), mDestroy, mInitialized, mRefCount, refcount(), and unload().
int Sirikata::Plugin::decref | ( | ) |
Decrease the ref count on this plugin by one.
References mDecRefCount.
void Sirikata::Plugin::destroy | ( | ) |
int Sirikata::Plugin::incref | ( | ) |
Increment the ref count on this plugin by one.
References mIncRefCount.
void Sirikata::Plugin::initialize | ( | ) |
Run this plugin's initialization code.
References mInit, and mInitialized.
Referenced by Sirikata::PluginManager::load().
bool Sirikata::Plugin::load | ( | ) |
Loads the plugin, returning true if it satisfies all the plugin requirements, i.e.
if it is successfully loaded from disk and has the appropriate interface.
References Sirikata::DynamicLibrary::load(), mDecRefCount, mDestroy, mDL, mIncRefCount, mInit, mName, mRefCount, and Sirikata::DynamicLibrary::symbol().
Referenced by Sirikata::PluginManager::load().
String Sirikata::Plugin::name | ( | ) |
int Sirikata::Plugin::refcount | ( | ) |
bool Sirikata::Plugin::unload | ( | ) |
Forcefully unloads the plugin.
Note that this *does not* call the destroy method.
References mDecRefCount, mDestroy, mDL, mIncRefCount, mInit, mName, mRefCount, and Sirikata::DynamicLibrary::unload().
Referenced by ~Plugin().
DestroyFunc Sirikata::Plugin::mDestroy [private] |
DynamicLibrary Sirikata::Plugin::mDL [private] |
InitFunc Sirikata::Plugin::mInit [private] |
Referenced by initialize(), load(), and unload().
int Sirikata::Plugin::mInitialized [private] |
Referenced by destroy(), initialize(), and ~Plugin().
NameFunc Sirikata::Plugin::mName [private] |
RefCountFunc Sirikata::Plugin::mRefCount [private] |
Referenced by load(), refcount(), unload(), and ~Plugin().