mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-19 00:46:21 +00:00
Introduce our own shutdown callback mechanism.
Instead of adding stuff to `_shutdown()`, we can now register a shutdown routine from the respective `init()` function of our modules. This also has the advantage, that we're sure they're called in reverse order from how the initialization happened. I didn't simply use `atexit()` because POSIX says that the number of possible callbacks is limited (min 32) and I was not sure whether we will maybe extend this number at one point. Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
This commit is contained in:
@@ -65,9 +65,49 @@
|
||||
|
||||
static GHashTable* plugins;
|
||||
|
||||
static void
|
||||
_plugins_shutdown(void)
|
||||
{
|
||||
GList* values = g_hash_table_get_values(plugins);
|
||||
GList *curr = values, *next;
|
||||
|
||||
while (curr) {
|
||||
next = g_list_next(curr);
|
||||
#ifdef HAVE_PYTHON
|
||||
if (curr && ((ProfPlugin*)curr->data)->lang == LANG_PYTHON) {
|
||||
python_plugin_destroy(curr->data);
|
||||
curr = NULL;
|
||||
}
|
||||
#endif
|
||||
#ifdef HAVE_C
|
||||
if (curr && ((ProfPlugin*)curr->data)->lang == LANG_C) {
|
||||
c_plugin_destroy(curr->data);
|
||||
curr = NULL;
|
||||
}
|
||||
#endif
|
||||
curr = next;
|
||||
}
|
||||
g_list_free(values);
|
||||
#ifdef HAVE_PYTHON
|
||||
python_shutdown();
|
||||
#endif
|
||||
#ifdef HAVE_C
|
||||
c_shutdown();
|
||||
#endif
|
||||
|
||||
autocompleters_destroy();
|
||||
plugin_themes_close();
|
||||
plugin_settings_close();
|
||||
callbacks_close();
|
||||
disco_close();
|
||||
g_hash_table_destroy(plugins);
|
||||
plugins = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
plugins_init(void)
|
||||
{
|
||||
prof_add_shutdown_routine(_plugins_shutdown);
|
||||
plugins = g_hash_table_new_full(g_str_hash, g_str_equal, free, NULL);
|
||||
callbacks_init();
|
||||
autocompleters_init();
|
||||
@@ -421,21 +461,8 @@ plugins_close_win(const char* const plugin_name, const char* const tag)
|
||||
callbacks_remove_win(plugin_name, tag);
|
||||
}
|
||||
|
||||
void
|
||||
plugins_on_start(void)
|
||||
{
|
||||
GList* values = g_hash_table_get_values(plugins);
|
||||
GList* curr = values;
|
||||
while (curr) {
|
||||
ProfPlugin* plugin = curr->data;
|
||||
plugin->on_start_func(plugin);
|
||||
curr = g_list_next(curr);
|
||||
}
|
||||
g_list_free(values);
|
||||
}
|
||||
|
||||
void
|
||||
plugins_on_shutdown(void)
|
||||
static void
|
||||
_plugins_on_shutdown(void)
|
||||
{
|
||||
GList* values = g_hash_table_get_values(plugins);
|
||||
GList* curr = values;
|
||||
@@ -447,6 +474,20 @@ plugins_on_shutdown(void)
|
||||
g_list_free(values);
|
||||
}
|
||||
|
||||
void
|
||||
plugins_on_start(void)
|
||||
{
|
||||
prof_add_shutdown_routine(_plugins_on_shutdown);
|
||||
GList* values = g_hash_table_get_values(plugins);
|
||||
GList* curr = values;
|
||||
while (curr) {
|
||||
ProfPlugin* plugin = curr->data;
|
||||
plugin->on_start_func(plugin);
|
||||
curr = g_list_next(curr);
|
||||
}
|
||||
g_list_free(values);
|
||||
}
|
||||
|
||||
void
|
||||
plugins_on_connect(const char* const account_name, const char* const fulljid)
|
||||
{
|
||||
@@ -924,42 +965,3 @@ plugins_get_disco_features(void)
|
||||
{
|
||||
return disco_get_features();
|
||||
}
|
||||
|
||||
void
|
||||
plugins_shutdown(void)
|
||||
{
|
||||
GList* values = g_hash_table_get_values(plugins);
|
||||
GList *curr = values, *next;
|
||||
|
||||
while (curr) {
|
||||
next = g_list_next(curr);
|
||||
#ifdef HAVE_PYTHON
|
||||
if (curr && ((ProfPlugin*)curr->data)->lang == LANG_PYTHON) {
|
||||
python_plugin_destroy(curr->data);
|
||||
curr = NULL;
|
||||
}
|
||||
#endif
|
||||
#ifdef HAVE_C
|
||||
if (curr && ((ProfPlugin*)curr->data)->lang == LANG_C) {
|
||||
c_plugin_destroy(curr->data);
|
||||
curr = NULL;
|
||||
}
|
||||
#endif
|
||||
curr = next;
|
||||
}
|
||||
g_list_free(values);
|
||||
#ifdef HAVE_PYTHON
|
||||
python_shutdown();
|
||||
#endif
|
||||
#ifdef HAVE_C
|
||||
c_shutdown();
|
||||
#endif
|
||||
|
||||
autocompleters_destroy();
|
||||
plugin_themes_close();
|
||||
plugin_settings_close();
|
||||
callbacks_close();
|
||||
disco_close();
|
||||
g_hash_table_destroy(plugins);
|
||||
plugins = NULL;
|
||||
}
|
||||
|
||||
@@ -113,7 +113,6 @@ GSList* plugins_unloaded_list(void);
|
||||
GList* plugins_loaded_list(void);
|
||||
char* plugins_autocomplete(const char* const input, gboolean previous);
|
||||
void plugins_reset_autocomplete(void);
|
||||
void plugins_shutdown(void);
|
||||
|
||||
void plugins_free_install_result(PluginsInstallResult* result);
|
||||
|
||||
@@ -129,7 +128,6 @@ gboolean plugins_reload(const char* const name, GString* error_message);
|
||||
void plugins_reload_all(void);
|
||||
|
||||
void plugins_on_start(void);
|
||||
void plugins_on_shutdown(void);
|
||||
|
||||
void plugins_on_connect(const char* const account_name, const char* const fulljid);
|
||||
void plugins_on_disconnect(const char* const account_name, const char* const fulljid);
|
||||
|
||||
Reference in New Issue
Block a user