1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-09-22 19:45:54 -04:00

Add plugins on_unload hook

This commit is contained in:
James Booth 2016-07-05 22:03:14 +01:00
parent 71178b3696
commit 99598e7d57
6 changed files with 43 additions and 0 deletions

View File

@ -81,6 +81,7 @@ c_plugin_create(const char *const filename)
plugin->init_func = c_init_hook;
plugin->on_start_func = c_on_start_hook;
plugin->on_shutdown_func = c_on_shutdown_hook;
plugin->on_unload_func = c_on_unload_hook;
plugin->on_connect_func = c_on_connect_hook;
plugin->on_disconnect_func = c_on_disconnect_hook;
plugin->pre_chat_message_display = c_pre_chat_message_display_hook;
@ -161,6 +162,20 @@ c_on_shutdown_hook(ProfPlugin *plugin)
func();
}
void
c_on_unload_hook(ProfPlugin *plugin)
{
void *f = NULL;
void (*func)(void);
assert(plugin && plugin->module);
if (NULL == (f = dlsym(plugin->module, "prof_on_unload")))
return;
func = (void (*)(void))f;
func();
}
void
c_on_connect_hook(ProfPlugin *plugin, const char *const account_name, const char *const fulljid)
{

View File

@ -47,6 +47,7 @@ void c_init_hook(ProfPlugin *plugin, const char *const version, const char *cons
const char *const fulljid);
void c_on_start_hook(ProfPlugin *plugin);
void c_on_shutdown_hook(ProfPlugin *plugin);
void c_on_unload_hook(ProfPlugin *plugin);
void c_on_connect_hook(ProfPlugin *plugin, const char *const account_name, const char *const fulljid);
void c_on_disconnect_hook(ProfPlugin *plugin, const char *const account_name, const char *const fulljid);

View File

@ -168,6 +168,11 @@ plugins_load(const char *const name)
gboolean
plugins_unload(const char *const name)
{
ProfPlugin *plugin = g_hash_table_lookup(plugins, name);
if (plugin) {
plugin->on_unload_func(plugin);
}
prefs_remove_plugin(name);
return TRUE;

View File

@ -51,6 +51,7 @@ typedef struct prof_plugin_t {
void (*on_start_func)(struct prof_plugin_t* plugin);
void (*on_shutdown_func)(struct prof_plugin_t* plugin);
void (*on_unload_func)(struct prof_plugin_t* plugin);
void (*on_connect_func)(struct prof_plugin_t* plugin, const char *const account_name, const char *const fulljid);
void (*on_disconnect_func)(struct prof_plugin_t* plugin, const char *const account_name,

View File

@ -91,6 +91,7 @@ python_plugin_create(const char *const filename)
plugin->init_func = python_init_hook;
plugin->on_start_func = python_on_start_hook;
plugin->on_shutdown_func = python_on_shutdown_hook;
plugin->on_unload_func = python_on_unload_hook;
plugin->on_connect_func = python_on_connect_hook;
plugin->on_disconnect_func = python_on_disconnect_hook;
plugin->pre_chat_message_display = python_pre_chat_message_display_hook;
@ -186,6 +187,25 @@ python_on_shutdown_hook(ProfPlugin *plugin)
allow_python_threads();
}
void
python_on_unload_hook(ProfPlugin *plugin)
{
disable_python_threads();
PyObject *p_function;
PyObject *p_module = plugin->module;
if (PyObject_HasAttrString(p_module, "prof_on_unload")) {
p_function = PyObject_GetAttrString(p_module, "prof_on_unload");
python_check_error();
if (p_function && PyCallable_Check(p_function)) {
PyObject_CallObject(p_function, NULL);
python_check_error();
Py_XDECREF(p_function);
}
}
allow_python_threads();
}
void
python_on_connect_hook(ProfPlugin *plugin, const char *const account_name, const char *const fulljid)
{

View File

@ -47,6 +47,7 @@ void python_init_hook(ProfPlugin *plugin, const char *const version, const char
const char *const account_name, const char *const fulljid);
void python_on_start_hook(ProfPlugin *plugin);
void python_on_shutdown_hook(ProfPlugin *plugin);
void python_on_unload_hook(ProfPlugin *plugin);
void python_on_connect_hook(ProfPlugin *plugin, const char *const account_name, const char *const fulljid);
void python_on_disconnect_hook(ProfPlugin *plugin, const char *const account_name, const char *const fulljid);