[glib] Add g_log_set_handler_full



commit 2471d9cf8697b07d4e86b6f143eda7b779be02a9
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Nov 28 23:31:00 2014 -0500

    Add g_log_set_handler_full
    
    This is a bindable version of g_log_set_handler that takes
    a destroy notify for the user_data.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=740516

 docs/reference/glib/glib-sections.txt |    1 +
 glib/gmessages.c                      |   38 ++++++++++++++++++++++++++++++--
 glib/gmessages.h                      |    6 +++++
 3 files changed, 42 insertions(+), 3 deletions(-)
---
diff --git a/docs/reference/glib/glib-sections.txt b/docs/reference/glib/glib-sections.txt
index 25b6146..4346ac2 100644
--- a/docs/reference/glib/glib-sections.txt
+++ b/docs/reference/glib/glib-sections.txt
@@ -1142,6 +1142,7 @@ g_debug
 
 <SUBSECTION>
 g_log_set_handler
+g_log_set_handler_full
 g_log_remove_handler
 g_log_set_always_fatal
 g_log_set_fatal_mask
diff --git a/glib/gmessages.c b/glib/gmessages.c
index 5342596..fea3247 100644
--- a/glib/gmessages.c
+++ b/glib/gmessages.c
@@ -279,6 +279,7 @@ struct _GLogHandler
   GLogLevelFlags log_level;
   GLogFunc      log_func;
   gpointer      data;
+  GDestroyNotify destroy;
   GLogHandler  *next;
 };
 
@@ -566,9 +567,37 @@ g_log_set_fatal_mask (const gchar   *log_domain,
  */
 guint
 g_log_set_handler (const gchar  *log_domain,
-                  GLogLevelFlags log_levels,
-                  GLogFunc       log_func,
-                  gpointer       user_data)
+                   GLogLevelFlags log_levels,
+                   GLogFunc       log_func,
+                   gpointer       user_data)
+{
+  return g_log_set_handler_full (log_domain, log_levels, log_func, user_data, NULL);
+}
+
+/**
+ * g_log_set_handler_full: (rename-to g_log_set_handler)
+ * @log_domain: (allow-none): the log domain, or %NULL for the default ""
+ *     application domain
+ * @log_levels: the log levels to apply the log handler for.
+ *     To handle fatal and recursive messages as well, combine
+ *     the log levels with the #G_LOG_FLAG_FATAL and
+ *     #G_LOG_FLAG_RECURSION bit flags.
+ * @log_func: the log handler function
+ * @user_data: data passed to the log handler
+ * @destroy: destroy notify for @user_data, or %NULL
+ *
+ * Like g_log_sets_handler(), but takes a destroy notify for the @user_data.
+ *
+ * Returns: the id of the new handler
+ *
+ * Since: 2.44
+ */
+guint
+g_log_set_handler_full (const gchar    *log_domain,
+                        GLogLevelFlags  log_levels,
+                        GLogFunc        log_func,
+                        gpointer        user_data,
+                        GDestroyNotify  destroy)
 {
   static guint handler_id = 0;
   GLogDomain *domain;
@@ -592,6 +621,7 @@ g_log_set_handler (const gchar       *log_domain,
   handler->log_level = log_levels;
   handler->log_func = log_func;
   handler->data = user_data;
+  handler->destroy = destroy;
   handler->next = domain->handlers;
   domain->handlers = handler;
 
@@ -699,6 +729,8 @@ g_log_remove_handler (const gchar *log_domain,
                domain->handlers = work->next;
              g_log_domain_check_free_L (domain); 
              g_mutex_unlock (&g_messages_lock);
+              if (work->destroy)
+                work->destroy (work->data);
              g_free (work);
              return;
            }
diff --git a/glib/gmessages.h b/glib/gmessages.h
index 497c669..d186c2b 100644
--- a/glib/gmessages.h
+++ b/glib/gmessages.h
@@ -86,6 +86,12 @@ guint           g_log_set_handler       (const gchar    *log_domain,
                                          GLogLevelFlags  log_levels,
                                          GLogFunc        log_func,
                                          gpointer        user_data);
+GLIB_AVAILABLE_IN_2_44
+guint           g_log_set_handler_full  (const gchar    *log_domain,
+                                         GLogLevelFlags  log_levels,
+                                         GLogFunc        log_func,
+                                         gpointer        user_data,
+                                         GDestroyNotify  destroy);
 GLIB_AVAILABLE_IN_ALL
 void            g_log_remove_handler    (const gchar    *log_domain,
                                          guint           handler_id);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]