{
GstLogFunction func;
gpointer user_data;
+ GDestroyNotify notify;
}
LogFuncEntry;
static GMutex __log_func_mutex;
_GST_CAT_DEBUG = _gst_debug_category_new ("GST_DEBUG",
GST_DEBUG_BOLD | GST_DEBUG_FG_YELLOW, "debugging subsystem");
- gst_debug_add_log_function (gst_debug_log_default, NULL);
+ gst_debug_add_log_function (gst_debug_log_default, NULL, NULL);
/* FIXME: add descriptions here */
GST_CAT_GST_INIT = _gst_debug_category_new ("GST_INIT",
/**
* gst_debug_add_log_function:
* @func: the function to use
- * @data: (closure): user data
+ * @user_data: user data
+ * @notify: called when @user_data is not used anymore
*
* Adds the logging function to the list of logging functions.
* Be sure to use #G_GNUC_NO_INSTRUMENT on that function, it is needed.
*/
void
-gst_debug_add_log_function (GstLogFunction func, gpointer data)
+gst_debug_add_log_function (GstLogFunction func, gpointer user_data,
+ GDestroyNotify notify)
{
LogFuncEntry *entry;
GSList *list;
entry = g_slice_new (LogFuncEntry);
entry->func = func;
- entry->user_data = data;
+ entry->user_data = user_data;
+ entry->notify = notify;
/* FIXME: we leak the old list here - other threads might access it right now
* in gst_debug_logv. Another solution is to lock the mutex in gst_debug_logv,
* but that is waaay costly.
g_mutex_unlock (&__log_func_mutex);
GST_DEBUG ("prepended log function %p (user data %p) to log functions",
- func, data);
+ func, user_data);
}
static gint
gst_debug_remove_with_compare_func (GCompareFunc func, gpointer data)
{
GSList *found;
- GSList *new;
+ GSList *new, *cleanup = NULL;
guint removals = 0;
g_mutex_lock (&__log_func_mutex);
new = __log_functions;
+ cleanup = NULL;
while ((found = g_slist_find_custom (new, data, func))) {
if (new == __log_functions) {
/* make a copy when we have the first hit, so that we modify the copy and
new = g_slist_copy (new);
continue;
}
- g_slice_free (LogFuncEntry, found->data);
+ cleanup = g_slist_prepend (cleanup, found->data);
new = g_slist_delete_link (new, found);
removals++;
}
__log_functions = new;
g_mutex_unlock (&__log_func_mutex);
+ while (cleanup) {
+ LogFuncEntry *entry = cleanup->data;
+
+ if (entry->notify)
+ entry->notify (entry->user_data);
+
+ g_slice_free (LogFuncEntry, entry);
+ cleanup = g_slist_delete_link (cleanup, cleanup);
+ }
return removals;
}
/**
* gst_debug_remove_log_function:
- * @func: the log function to remove
+ * @func: (scope call): the log function to remove
*
* Removes all registered instances of the given logging functions.
*
const gchar * gst_debug_level_get_name (GstDebugLevel level);
void gst_debug_add_log_function (GstLogFunction func,
- gpointer data);
+ gpointer user_data,
+ GDestroyNotify notify);
guint gst_debug_remove_log_function (GstLogFunction func);
guint gst_debug_remove_log_function_by_data (gpointer data);
#ifndef GST_DISABLE_GST_DEBUG
-#define gst_debug_add_log_function(func,data) \
-G_STMT_START{ \
- if (func == gst_debug_log_default) { \
- gst_debug_add_log_function(NULL,data); \
- } else { \
- gst_debug_add_log_function(func,data); \
- } \
+#define gst_debug_add_log_function(func,data,notify) \
+G_STMT_START{ \
+ if (func == gst_debug_log_default) { \
+ gst_debug_add_log_function(NULL,data,notify); \
+ } else { \
+ gst_debug_add_log_function(func,data,notify); \
+ } \
}G_STMT_END
#define gst_debug_remove_log_function(func) \
#define gst_debug_level_get_name(level) ("NONE")
#define gst_debug_message_get(message) ("")
-#define gst_debug_add_log_function(func,data) G_STMT_START{ }G_STMT_END
+#define gst_debug_add_log_function(func,data,notify) G_STMT_START{ }G_STMT_END
#define gst_debug_set_active(active) G_STMT_START{ }G_STMT_END
#define gst_debug_is_active() (FALSE)
#define gst_debug_set_colored(colored) G_STMT_START{ }G_STMT_END
/* set up our own log function to make sure the code in gstinfo is actually
* executed without GST_DEBUG being set or it being output to stdout */
gst_debug_remove_log_function (gst_debug_log_default);
- gst_debug_add_log_function (printf_extension_log_func, NULL);
+ gst_debug_add_log_function (printf_extension_log_func, NULL, NULL);
gst_debug_set_default_threshold (GST_LEVEL_LOG);
/* clean up */
gst_debug_set_default_threshold (GST_LEVEL_NONE);
- gst_debug_add_log_function (gst_debug_log_default, NULL);
+ gst_debug_add_log_function (gst_debug_log_default, NULL, NULL);
gst_debug_remove_log_function (printf_extension_log_func);
}
/* set up our own log function to make sure the code in gstinfo is actually
* executed without GST_DEBUG being set or it being output to stdout */
gst_debug_remove_log_function (gst_debug_log_default);
- gst_debug_add_log_function (printf_extension_log_func, NULL);
+ gst_debug_add_log_function (printf_extension_log_func, NULL, NULL);
gst_debug_set_default_threshold (GST_LEVEL_LOG);
/* clean up */
gst_debug_set_default_threshold (GST_LEVEL_NONE);
- gst_debug_add_log_function (gst_debug_log_default, NULL);
+ gst_debug_add_log_function (gst_debug_log_default, NULL, NULL);
gst_debug_remove_log_function (printf_extension_log_func);
}