aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar TheXception2007-04-29 11:37:12 +0000
committerGravatar TheXception2007-04-29 11:37:12 +0000
commit516f07ced40840d388d50fa9948570d4d8e6ad65 (patch)
tree5aad4c9172f5354be3cd3298f5da11955e3178b8
parent*AUTOMATICALLY* updated KVI_SOURCES_DATE variable (diff)
downloadKVIrc-516f07ced40840d388d50fa9948570d4d8e6ad65.tar.gz
KVIrc-516f07ced40840d388d50fa9948570d4d8e6ad65.tar.bz2
KVIrc-516f07ced40840d388d50fa9948570d4d8e6ad65.zip
added _canunload + more doc + small fix
git-svn-id: https://svn.kvirc.de/svn/trunk/kvirc@542 17fca916-40b9-46aa-a4ea-0a15b648b75c
-rw-r--r--src/modules/system/libkvisystem.cpp2
-rw-r--r--src/modules/system/plugin.cpp60
-rw-r--r--src/modules/system/plugin.h6
3 files changed, 54 insertions, 14 deletions
diff --git a/src/modules/system/libkvisystem.cpp b/src/modules/system/libkvisystem.cpp
index 1fd5ac219..2f3351b58 100644
--- a/src/modules/system/libkvisystem.cpp
+++ b/src/modules/system/libkvisystem.cpp
@@ -724,7 +724,7 @@ static bool system_module_init(KviModule * m)
static bool system_module_cleanup(KviModule *m)
{
- g_pPluginManager->unloadAll(true);
+ g_pPluginManager->unloadAll();
delete g_pPluginManager;
return true;
}
diff --git a/src/modules/system/plugin.cpp b/src/modules/system/plugin.cpp
index 9d91c12b4..c3eccbcee 100644
--- a/src/modules/system/plugin.cpp
+++ b/src/modules/system/plugin.cpp
@@ -45,9 +45,16 @@
@short:
Small plugins which can be called in scripts
@body:
+ Where to put Easyplugins?
+ localdir + "easyplugins/"[br]
+ globaldir + "easyplugins/"[br][br]
+ How to call functions of easyplugins:[br]
+ See: $system.call()[br]
+ [br]
TODO
- [b]Exported functions by dll[/b][br]
+ [b]exported functions by plugin[/b][br]
[br]_free function (needed)[br]
+ This function is important! Since KVIrc can not free directly the memory of the dll, the plugins need the _free function so that the memory can be freed by the plugin to prevent memory-leaks.[br]
[example]
int _free(void * p)[br]
{[br]
@@ -58,6 +65,7 @@
[/example]
[br]_load function (optional)[br]
+ After the plugin has be loaded, KVIrc will call the _load-function. Here you can prepare your plugin stuff.
[example]
int _load()[br]
{[br]
@@ -66,14 +74,29 @@
[/example]
[br]_unload function (optional)[br]
+ This function will be called before the plugins is unloaded. In this function you can clean up memory or other things.
+ After this call there is no guarantee that the plugin will be kept in memory.[br]
[example]
int _unload()[br]
{[br]
return 0;[br]
}[br]
[/example]
+
+ [br]_canunload function (optional)[br]
+ The _canunload-function will be called by KVIrc to check if it may unload the plugin.
+ If return value is true KVIrc will unload the plugin, false means he will try unloading it at the next check.[br]
+ Important: KVIrc will ignore this if unload of plugins will be forced! So you have to be sure that the _unload function of your plugins cleans up![br]
+ [example]
+ int _canunload(void * p)[br]
+ {[br]
+ return 0; [br]
+ }[br]
+ [/example]
[br]user function[br]
+ This is the general structure of a user function call.[br]
+ The important thing here is the handling of return values. To return a value to KVIrc you have to allocate memory and write the pointer to it into pBuffer. Have a look at the example for more details.[br]
[example]
int about(int argc, char * argv[], char ** pBuffer)[br]
{[br]
@@ -129,7 +152,7 @@ bool KviPlugin::pfree(char * pBuffer)
return false;
}
-bool KviPlugin::unload(bool forced)
+bool KviPlugin::unload()
{
plugin_unload function_unload;
@@ -137,10 +160,7 @@ bool KviPlugin::unload(bool forced)
if (function_unload)
{
//TODO: THREAD
- if(!function_unload())
- {
- if(!forced) return false;
- }
+ function_unload();
}
if(m_Plugin)
@@ -151,6 +171,22 @@ bool KviPlugin::unload(bool forced)
return true;
}
+bool KviPlugin::canunload()
+{
+ plugin_canunload function_canunload;
+
+ function_canunload = (plugin_canunload)kvi_library_symbol(m_Plugin,"_canunload");
+ if (function_canunload)
+ {
+ //TODO: THREAD
+ if(!function_canunload())
+ {
+ return false;
+ }
+ }
+ return true;
+}
+
int KviPlugin::call(const QString& pszFunctionName, int argc, char * argv[], char ** pBuffer)
{
int r;
@@ -292,7 +328,7 @@ bool KviPluginManager::pluginCall(KviKvsModuleFunctionCall *c)
{
if (!plugin->pfree(returnBuffer))
{
- c->warning(__tr2qs("The plugin has no function to free memory. Can result in Memory Leaks!"));
+ c->warning(__tr2qs("The plugin has no function to free memory. This can result in Memory Leaks!"));
}
}
@@ -313,10 +349,12 @@ bool KviPluginManager::checkUnload()
while(it.current())
{
- if(it.current()->unload(false))
+ if(it.current()->canunload())
{
+ it.current()->unload();
m_pPluginDict->remove(it.currentKey());
} else {
+ m_pPluginDict++;
m_bCanUnload = false;
}
}
@@ -324,14 +362,14 @@ bool KviPluginManager::checkUnload()
return m_bCanUnload;
}
-void KviPluginManager::unloadAll(bool forced)
+void KviPluginManager::unloadAll()
{
KviDictIterator<KviPlugin> it(*m_pPluginDict);
while(it.current())
{
- it.current()->unload(true);
- m_pPluginDict->remove(it.currentKey());
+ it.current()->unload();
+ m_pPluginDict->remove(it.currentKey());
}
}
diff --git a/src/modules/system/plugin.h b/src/modules/system/plugin.h
index cd6002e5c..c94ebb013 100644
--- a/src/modules/system/plugin.h
+++ b/src/modules/system/plugin.h
@@ -31,6 +31,7 @@
typedef int (*plugin_function)(int argc, char* argv[], char ** buffer);
typedef int (*plugin_unload)();
+typedef int (*plugin_canunload)();
typedef int (*plugin_load)();
typedef int (*plugin_free)(char * pBuffer);
@@ -49,7 +50,8 @@ private:
public:
static KviPlugin* load(const QString& szFileName);
bool pfree(char * pBuffer);
- bool unload(bool forced);
+ bool unload();
+ bool canunload();
int call(const QString& szFunctionName, int argc, char * argv[], char ** pBuffer);
QString name();
void setName(const QString& szName);
@@ -69,7 +71,7 @@ class KviPluginManager
public:
bool pluginCall(KviKvsModuleFunctionCall *c);
bool checkUnload();
- void unloadAll(bool forced);
+ void unloadAll();
protected:
bool findPlugin(QString& szName);
bool isPluginLoaded(const QString& szFileNameOrPathToLoad);