From 5cabcf9b79880d550782da2967b9d67a531a8f7d Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 7 Mar 2016 20:36:25 +0000 Subject: Plugins: Added callbacks init and close functions Included destroy function in PluginWindowCallback --- src/plugins/callbacks.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'src/plugins/callbacks.c') diff --git a/src/plugins/callbacks.c b/src/plugins/callbacks.c index a3cbfc1d..6f796259 100644 --- a/src/plugins/callbacks.c +++ b/src/plugins/callbacks.c @@ -46,6 +46,27 @@ static GSList *p_commands = NULL; static GSList *p_timed_functions = NULL; static GHashTable *p_window_callbacks = NULL; +static void +_free_window_callback(PluginWindowCallback *window_callback) +{ + if (window_callback->destroy) { + window_callback->destroy(window_callback->callback); + } + free(window_callback); +} + +void +callbacks_init(void) +{ + p_window_callbacks = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)_free_window_callback); +} + +void +callbacks_close(void) +{ + g_hash_table_destroy(p_window_callbacks); +} + void callbacks_add_command(PluginCommand *command) { @@ -64,10 +85,6 @@ callbacks_add_timed(PluginTimedFunction *timed_function) void callbacks_add_window_handler(const char *tag, PluginWindowCallback *window_callback) { - if (p_window_callbacks == NULL) { - p_window_callbacks = g_hash_table_new(g_str_hash, g_str_equal); - } - g_hash_table_insert(p_window_callbacks, strdup(tag), window_callback); } -- cgit 1.4.1-2-gfad0