#include <pluginloader.h>
Inheritance diagram for kore::PluginLoader::
Public Methods | |
PluginLoader () | |
Default constructor. More... | |
~PluginLoader () | |
Destructor. More... | |
virtual Plugin * | openPlugin (const char *libName, const char *libPath=0, int libFlags=0) |
Loads a dll and gets the Plugin object for it. More... | |
virtual Plugin * | runPlugin (const char *libName, const char *libPath=0, int libFlags=0) |
Loads a dll, gets the dll's Plugin object and initialises it. More... | |
virtual void | closePlugin (Plugin *plugin) |
Unloads a previously loaded dll. More... | |
virtual const char * | lastError () |
Gets the error message for the last failed openPlugin() or runPlugin(). More... | |
virtual char * | libName2fileName (const char *libName) |
Helper method. More... | |
virtual char * | fileName2libName (const char *fileName) |
Helper method. More... | |
Private Attributes | |
const Version * | _loaderVersion |
const Version * | _loaderAPIVersion |
const Info * | _loaderInfo |
const Service * | _loaderService |
char | _lastError [100] |
It provides methods for loading (openPlugin()) and initialising (runPlugin()) plugins.
Definition at line 32 of file pluginloader.h.
|
Default constructor. Creates a new PluginLoader instance. Definition at line 31 of file pluginloader.cpp. References _loaderAPIVersion, _loaderInfo, _loaderService, _loaderVersion, kore::ServiceProvider::addService(), PLDR_API_MAJOR, PLDR_API_MINOR, PLDR_API_REVISION, PLDR_API_VERSION, PLDR_DESCRIPTION, PLDR_MAJOR, PLDR_MINOR, PLDR_NAME, PLDR_REVISION, PLDR_SERVICE, PLDR_SERVICE_DESCRIPTION, PLDR_TYPE, PLDR_VERSION, and kore::Module::setInfo().
00032 { 00033 _loaderVersion = new Version(PLDR_MAJOR,PLDR_MINOR,PLDR_REVISION,PLDR_VERSION); 00034 _loaderAPIVersion = new Version(PLDR_API_MAJOR,PLDR_API_MINOR,PLDR_API_REVISION,PLDR_API_VERSION); 00035 _loaderInfo = new Info(this, PLDR_NAME, PLDR_TYPE, PLDR_DESCRIPTION, _loaderVersion, _loaderAPIVersion); 00036 setInfo(_loaderInfo); 00037 _loaderService = new Service(this, PLDR_SERVICE, PLDR_SERVICE_DESCRIPTION); 00038 addService(_loaderService); 00039 } |
|
Destructor.
Definition at line 40 of file pluginloader.cpp. References _loaderAPIVersion, _loaderInfo, _loaderService, and _loaderVersion.
00041 { 00042 delete _loaderInfo; 00043 delete _loaderVersion; 00044 delete _loaderAPIVersion; 00045 delete _loaderService; 00046 } |
|
Unloads a previously loaded dll.
Definition at line 150 of file pluginloader.cpp.
00151 { 00152 plugin->unloadingPlugin(); 00153 #if defined( KORE_WIN32 ) 00154 FreeLibrary( plugin->libHandle() ); 00155 #elif defined( KORE_BEOS ) 00156 unload_add_on( plugin->libHandle() ); 00157 #elif defined( KORE_ATHEOS ) 00158 unload_library( plugin->libHandle() ); 00159 #else 00160 dlclose(const_cast<void*> (plugin->libHandle())); 00161 #endif 00162 } |
|
Helper method. It converts a platform-dependant dll filename (ie. "libmy_plugin.so", or "my_plugin.dll") to the corresponding platform-independant dll filename (ie. "my_plugin")
Definition at line 61 of file pluginloader.cpp.
00062 { 00063 #ifdef KORE_WIN32 00064 int n = strlen(libName) - 4; 00065 char* ln = new char[n+1]; 00066 #else 00067 char* pos = strstr(fileName, ".so"); 00068 int n = pos - fileName - 3; 00069 char* ln = new char[n+1]; 00070 fileName += 3; 00071 #endif 00072 return strncpy(ln, fileName, n); 00073 } |
|
Gets the error message for the last failed openPlugin() or runPlugin().
Definition at line 164 of file pluginloader.cpp. References _lastError.
00165 { 00166 _lastError[0]=0; 00167 #if defined( KORE_WIN32 ) 00168 FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 0, 00169 GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), _lastError, 100, NULL ); 00170 #elif defined( KORE_BEOS ) 00171 strncpy(_lastError, strerror(errno), 100); 00172 #elif defined( KORE_ATHEOS ) 00173 strncpy(_lastError, strerror(errno), 100); 00174 #else 00175 strncpy(_lastError, dlerror(), 100); 00176 #endif 00177 return _lastError; 00178 } |
|
Helper method. It converts a platform-independant dll name (ie. "my_plugin") to the corresponding platform-dependant dll filename (ie. "libmy_plugin.so", or "my_plugin.dll").
Definition at line 49 of file pluginloader.cpp. Referenced by openPlugin().
00050 { 00051 int n = strlen(libName); 00052 #ifdef KORE_WIN32 00053 char* fn = new char[n+1+4]; 00054 return strcat(strcpy(fn,libName),".dll"); 00055 #else 00056 char* fn = new char[n+1+6]; 00057 return strcat(strcat(strcpy(fn,"lib"),libName),".so"); 00058 #endif 00059 } |
|
Loads a dll and gets the Plugin object for it.
Definition at line 82 of file pluginloader.cpp. References HMODULE, libName2fileName(), and kore::PluginFuncType. Referenced by runPlugin().
00083 { 00084 HMODULE handle; 00085 char* fileName = libName2fileName(libName); 00086 char* filePath = 0; 00087 Plugin* res; 00088 if( libPath && libPath[0] ) 00089 { 00090 int n = strlen(libPath); 00091 int slash = libPath[n-1] == '/' ? 0 : 1; 00092 filePath = new char[n+strlen(fileName)+slash+1]; 00093 strcpy(filePath, libPath); 00094 if( slash ) 00095 { 00096 filePath[n] = '/'; 00097 filePath[n+1] = 0; 00098 } 00099 } 00100 else 00101 { 00102 filePath = new char[strlen(fileName)+1]; 00103 filePath[0] = 0; 00104 } 00105 strcat( filePath, fileName ); 00106 //cout << "Loading: " << filePath << endl; 00107 delete[] fileName; 00108 #if defined( KORE_WIN32 ) 00109 handle = LoadLibrary(filePath); 00110 #elif defined( KORE_BEOS ) 00111 handle = load_add_on(filePath); 00112 #elif defined( KORE_ATHEOS ) 00113 handle = load_library( filePath, 0 ); 00114 #else 00115 handle = dlopen(filePath, libFlags | RTLD_NOW ); 00116 #endif 00117 delete[] filePath; 00118 //cout << "Loaded: " << handle << endl; 00119 #if defined( KORE_BEOS ) 00120 if( handle < B_NO_ERROR ) 00121 #elif defined( KORE_ATHEOS ) 00122 if( handle < 0 ) 00123 #else 00124 if( !handle ) 00125 #endif 00126 return 0; 00127 //cout << "Found: " << handle << endl; 00128 PluginFuncType sym = 0; 00129 #if defined( KORE_WIN32 ) 00130 sym = (PluginFuncType) GetProcAddress( handle, "plugin" ); 00131 #elif defined( KORE_BEOS ) 00132 if( B_OK != get_image_symbol( handle, "plugin", B_SYMBOL_TYPE_TEXT, reinterpret_cast<void**>(&sym) ) ) 00133 sym = 0; 00134 #elif defined( KORE_ATHEOS ) 00135 if( 0 != get_symbol_address( handle, "plugin", -1, reinterpret_cast<void**>(&sym) ) ) 00136 sym = 0; 00137 #else 00138 sym = (PluginFuncType) dlsym( const_cast<void*>(handle), "plugin" ); 00139 #endif 00140 //cout << "Done: " << sym << endl; 00141 if( !sym ) 00142 res = new Plugin(handle,libName,libPath,libFlags); 00143 else 00144 res = sym(handle,libName,libPath,libFlags); 00145 //cout << "Called: " << sym << endl; 00146 res->pluginLoaded(); 00147 return res; 00148 } |
|
Loads a dll, gets the dll's Plugin object and initialises it.
Definition at line 75 of file pluginloader.cpp. References openPlugin().
00076 { 00077 Plugin* plugin = openPlugin(libName, libPath, libFlags); 00078 if( plugin ) 00079 plugin->initPlugin(); 00080 return plugin; 00081 } |
|
Definition at line 104 of file pluginloader.h. Referenced by lastError(). |
|
Definition at line 98 of file pluginloader.h. Referenced by PluginLoader(), and ~PluginLoader(). |
|
Definition at line 100 of file pluginloader.h. Referenced by PluginLoader(), and ~PluginLoader(). |
|
Definition at line 102 of file pluginloader.h. Referenced by PluginLoader(), and ~PluginLoader(). |
|
Definition at line 96 of file pluginloader.h. Referenced by PluginLoader(), and ~PluginLoader(). |