diff options
author | James Booth <boothj5@gmail.com> | 2016-07-05 22:03:14 +0100 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2016-07-05 22:03:14 +0100 |
commit | 99598e7d57be923ce18fa5cded11431e5b462720 (patch) | |
tree | d25f0ef0376a8c446bbed9eb61351219e04eedee /src | |
parent | 71178b3696cceae72c93d2e904ae41a811dec87d (diff) | |
download | profani-tty-99598e7d57be923ce18fa5cded11431e5b462720.tar.gz |
Add plugins on_unload hook
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/c_plugins.c | 15 | ||||
-rw-r--r-- | src/plugins/c_plugins.h | 1 | ||||
-rw-r--r-- | src/plugins/plugins.c | 5 | ||||
-rw-r--r-- | src/plugins/plugins.h | 1 | ||||
-rw-r--r-- | src/plugins/python_plugins.c | 20 | ||||
-rw-r--r-- | src/plugins/python_plugins.h | 1 |
6 files changed, 43 insertions, 0 deletions
diff --git a/src/plugins/c_plugins.c b/src/plugins/c_plugins.c index 5c0047c8..1a4b8754 100644 --- a/src/plugins/c_plugins.c +++ b/src/plugins/c_plugins.c @@ -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; @@ -162,6 +163,20 @@ c_on_shutdown_hook(ProfPlugin *plugin) } 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) { void *f = NULL; diff --git a/src/plugins/c_plugins.h b/src/plugins/c_plugins.h index a62e302f..f4f88752 100644 --- a/src/plugins/c_plugins.h +++ b/src/plugins/c_plugins.h @@ -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); diff --git a/src/plugins/plugins.c b/src/plugins/plugins.c index ae0e65b0..449bbecf 100644 --- a/src/plugins/plugins.c +++ b/src/plugins/plugins.c @@ -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; diff --git a/src/plugins/plugins.h b/src/plugins/plugins.h index 13bb6e2f..feddcbfe 100644 --- a/src/plugins/plugins.h +++ b/src/plugins/plugins.h @@ -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, diff --git a/src/plugins/python_plugins.c b/src/plugins/python_plugins.c index 0dac55ec..efd225b0 100644 --- a/src/plugins/python_plugins.c +++ b/src/plugins/python_plugins.c @@ -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; @@ -187,6 +188,25 @@ python_on_shutdown_hook(ProfPlugin *plugin) } 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) { disable_python_threads(); diff --git a/src/plugins/python_plugins.h b/src/plugins/python_plugins.h index 71a62f1c..facf3ff2 100644 --- a/src/plugins/python_plugins.h +++ b/src/plugins/python_plugins.h @@ -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); |