[glib/tls: 4/9] Add g_source_set_dummy_callback()



commit 2365348f30605ec7bb2917a12d8e9ff91cabe313
Author: Dan Winship <danw gnome org>
Date:   Sun Nov 7 11:49:40 2010 -0500

    Add g_source_set_dummy_callback()
    
    Use g_source_set_closure() and g_close_set_meta_marshal() to allow
    setting a do-nothing callback on any source.

 docs/reference/gobject/gobject-sections.txt |    1 +
 gobject/gobject.symbols                     |    1 +
 gobject/gsourceclosure.c                    |   39 ++++++++++++++++++++++++++-
 gobject/gsourceclosure.h                    |    6 +++-
 4 files changed, 44 insertions(+), 3 deletions(-)
---
diff --git a/docs/reference/gobject/gobject-sections.txt b/docs/reference/gobject/gobject-sections.txt
index 6df42c8..fe4a2c8 100644
--- a/docs/reference/gobject/gobject-sections.txt
+++ b/docs/reference/gobject/gobject-sections.txt
@@ -827,6 +827,7 @@ g_closure_set_marshal
 g_closure_add_marshal_guards
 g_closure_set_meta_marshal
 g_source_set_closure
+g_source_set_dummy_callback
 G_TYPE_IO_CHANNEL
 G_TYPE_IO_CONDITION
 
diff --git a/gobject/gobject.symbols b/gobject/gobject.symbols
index c80293f..df79dd5 100644
--- a/gobject/gobject.symbols
+++ b/gobject/gobject.symbols
@@ -128,6 +128,7 @@ g_value_get_flags
 g_io_channel_get_type
 g_io_condition_get_type
 g_source_set_closure
+g_source_set_dummy_callback
 #endif
 #endif
 
diff --git a/gobject/gsourceclosure.c b/gobject/gsourceclosure.c
index 0da5027..e3e6b8d 100644
--- a/gobject/gsourceclosure.c
+++ b/gobject/gsourceclosure.c
@@ -168,7 +168,7 @@ g_source_set_closure (GSource  *source,
       source->source_funcs != &g_timeout_funcs &&
       source->source_funcs != &g_idle_funcs)
     {
-      g_critical (G_STRLOC "closure can not be set on closure without GSourceFuncs::closure_callback\n");
+      g_critical (G_STRLOC ": closure can not be set on closure without GSourceFuncs::closure_callback\n");
       return;
     }
 
@@ -191,3 +191,40 @@ g_source_set_closure (GSource  *source,
 	g_closure_set_marshal (closure, marshal);
     }
 }
+
+static void
+dummy_closure_marshal (GClosure     *closure,
+		       GValue       *return_value,
+		       guint         n_param_values,
+		       const GValue *param_values,
+		       gpointer      invocation_hint,
+		       gpointer      marshal_data)
+{
+  if (G_VALUE_HOLDS_BOOLEAN (return_value))
+    g_value_set_boolean (return_value, TRUE);
+}
+
+/**
+ * g_source_set_dummy_callback:
+ * @source: the source
+ *
+ * Sets a dummy callback for @source. The callback will do nothing, and
+ * if the source expects a #gboolean return value, it will return %TRUE.
+ * (If the source expects any other type of return value, it will return
+ * a 0/%NULL value; whatever g_value_init() initializes a #GValue to for
+ * that type.)
+ *
+ * If the source is not one of the standard GLib types, the
+ * @closure_callback and @closure_marshal fields of the #GSourceFuncs
+ * structure must have been filled in with pointers to appropriate
+ * functions.
+ */
+void
+g_source_set_dummy_callback (GSource *source)
+{
+  GClosure *closure;
+
+  closure = g_closure_new_simple (sizeof (GClosure), NULL);
+  g_closure_set_meta_marshal (closure, NULL, dummy_closure_marshal);
+  g_source_set_closure (source, closure);
+}
diff --git a/gobject/gsourceclosure.h b/gobject/gsourceclosure.h
index e7f5594..edae2c8 100644
--- a/gobject/gsourceclosure.h
+++ b/gobject/gsourceclosure.h
@@ -27,8 +27,10 @@
 
 G_BEGIN_DECLS
 
-void g_source_set_closure (GSource  *source,
-			   GClosure *closure);
+void g_source_set_closure        (GSource  *source,
+				  GClosure *closure);
+
+void g_source_set_dummy_callback (GSource  *source);
 
 GType g_io_channel_get_type   (void);
 GType g_io_condition_get_type (void);



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