mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-27 20:21:24 +00:00
info: add destroy notify to gst_debug_add_log_function()
This commit is contained in:
parent
d2c632fcda
commit
7da1d23a9b
3 changed files with 36 additions and 21 deletions
|
@ -256,6 +256,7 @@ typedef struct
|
|||
{
|
||||
GstLogFunction func;
|
||||
gpointer user_data;
|
||||
GDestroyNotify notify;
|
||||
}
|
||||
LogFuncEntry;
|
||||
static GMutex __log_func_mutex;
|
||||
|
@ -347,7 +348,7 @@ _priv_gst_debug_init (void)
|
|||
_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",
|
||||
|
@ -1063,13 +1064,15 @@ gst_debug_level_get_name (GstDebugLevel level)
|
|||
/**
|
||||
* 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;
|
||||
|
@ -1079,7 +1082,8 @@ gst_debug_add_log_function (GstLogFunction func, gpointer data)
|
|||
|
||||
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.
|
||||
|
@ -1092,7 +1096,7 @@ gst_debug_add_log_function (GstLogFunction func, gpointer data)
|
|||
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
|
||||
|
@ -1115,11 +1119,12 @@ static guint
|
|||
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
|
||||
|
@ -1127,7 +1132,7 @@ gst_debug_remove_with_compare_func (GCompareFunc func, gpointer data)
|
|||
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++;
|
||||
}
|
||||
|
@ -1135,12 +1140,21 @@ gst_debug_remove_with_compare_func (GCompareFunc func, gpointer data)
|
|||
__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.
|
||||
*
|
||||
|
|
|
@ -330,7 +330,8 @@ void gst_debug_log_default (GstDebugCategory * category,
|
|||
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);
|
||||
|
@ -365,12 +366,12 @@ gint gst_debug_construct_win_color (guint colorinfo);
|
|||
|
||||
#ifndef GST_DISABLE_GST_DEBUG
|
||||
|
||||
#define 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); \
|
||||
gst_debug_add_log_function(NULL,data,notify); \
|
||||
} else { \
|
||||
gst_debug_add_log_function(func,data); \
|
||||
gst_debug_add_log_function(func,data,notify); \
|
||||
} \
|
||||
}G_STMT_END
|
||||
|
||||
|
@ -1262,7 +1263,7 @@ GST_TRACE (const char *format, ...)
|
|||
|
||||
#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
|
||||
|
|
|
@ -49,7 +49,7 @@ GST_START_TEST (info_ptr_format_printf_extension)
|
|||
/* 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);
|
||||
|
||||
|
@ -105,7 +105,7 @@ GST_START_TEST (info_ptr_format_printf_extension)
|
|||
|
||||
/* 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);
|
||||
}
|
||||
|
||||
|
@ -117,7 +117,7 @@ GST_START_TEST (info_segment_format_printf_extension)
|
|||
/* 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);
|
||||
|
||||
|
@ -183,7 +183,7 @@ GST_START_TEST (info_segment_format_printf_extension)
|
|||
|
||||
/* 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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue