[glib/wip/gdesktopappinfo: 1/20] GMainContext: add qdata



commit 2af6f8bfae0647588c56c21e74577a137c575967
Author: Ryan Lortie <desrt desrt ca>
Date:   Tue Sep 24 15:11:24 2013 -0400

    GMainContext: add qdata
    
    https://bugzilla.gnome.org/show_bug.cgi?id=690525

 docs/reference/glib/glib-sections.txt |    3 +
 glib/gmain.c                          |   87 +++++++++++++++++++++++++++++++++
 glib/gmain.h                          |   15 ++++++
 3 files changed, 105 insertions(+), 0 deletions(-)
---
diff --git a/docs/reference/glib/glib-sections.txt b/docs/reference/glib/glib-sections.txt
index 9c2a7f8..04ab5d3 100644
--- a/docs/reference/glib/glib-sections.txt
+++ b/docs/reference/glib/glib-sections.txt
@@ -457,6 +457,9 @@ g_main_context_acquire
 g_main_context_release
 g_main_context_is_owner
 g_main_context_wait
+g_main_context_set_qdata
+g_main_context_set_qdata_full
+g_main_context_get_qdata
 g_main_context_prepare
 g_main_context_query
 g_main_context_check
diff --git a/glib/gmain.c b/glib/gmain.c
index 738e69c..84bef64 100644
--- a/glib/gmain.c
+++ b/glib/gmain.c
@@ -261,6 +261,8 @@ struct _GMainContext
 
   gint64   time;
   gboolean time_is_fresh;
+
+  GData *qdata;
 };
 
 struct _GSourceCallback
@@ -517,6 +519,8 @@ g_main_context_unref (GMainContext *context)
   if (!g_atomic_int_dec_and_test (&context->ref_count))
     return;
 
+  g_datalist_clear (&context->qdata);
+
   G_LOCK (main_context_list);
   main_context_list = g_slist_remove (main_context_list, context);
   G_UNLOCK (main_context_list);
@@ -4382,6 +4386,89 @@ g_main_context_is_owner (GMainContext *context)
   return is_owner;
 }
 
+/**
+ * g_main_context_set_qdata_full:
+ * @context: a #GMainContext
+ * @quark: a #GQuark
+ * @data: (allow none): the data to set
+ * @notify: the #GDestroyNotify for @data
+ *
+ * Sets @data as the qdata for @quark on @context, such that a future
+ * call to g_main_context_get_qdata() on the same @context and @quark
+ * will return @data.
+ *
+ * @notify will be called on @data on a future call to
+ * g_main_context_set_qdata_full() or g_main_context_set_qdata() on the
+ * same @context and @quark, or when @context is freed.
+ *
+ * If @data is %NULL then the qdata is unset.  It is not permitted to
+ * have %NULL @data and non-%NULL @notify.
+ *
+ * Since: 2.40
+ */
+void
+g_main_context_set_qdata_full (GMainContext   *context,
+                               GQuark          quark,
+                               gpointer        data,
+                               GDestroyNotify  notify)
+{
+  g_return_if_fail (context != NULL);
+  g_return_if_fail (data != NULL || notify == NULL);
+  g_return_if_fail (quark > 0);
+
+  g_datalist_id_set_data_full (&context->qdata, quark, data, notify);
+}
+
+/**
+ * g_main_context_set_qdata:
+ * @context: a #GMainContext
+ * @quark: a #GQuark
+ * @data: (allow none): the data to set
+ *
+ * Sets @data as the qdata for @quark on @context, such that a future
+ * call to g_main_context_get_qdata() on the same @context and @quark
+ * will return @data.
+ *
+ * If @data is %NULL then the qdata is unset.
+ *
+ * Since: 2.40
+ */
+void
+g_main_context_set_qdata (GMainContext *context,
+                          GQuark        quark,
+                          gpointer      data)
+{
+  g_return_if_fail (context != NULL);
+  g_return_if_fail (quark > 0);
+
+  g_datalist_id_set_data (&context->qdata, quark, data);
+}
+
+/**
+ * g_main_context_get_qdata:
+ * @context: a #GMainContext
+ * @quark: a #GQuark
+ *
+ * Gets the qdata set by a previous call to g_main_context_set_qdata()
+ * or g_main_context_set_qdata_full().
+ *
+ * If no such call was made on this @context with this @quark then %NULL
+ * is returned.
+ *
+ * Returns: the stored qdata
+ *
+ * Since: 2.40
+ */
+gpointer
+g_main_context_get_qdata (GMainContext *context,
+                          GQuark        quark)
+{
+  g_return_val_if_fail (context != NULL, NULL);
+  g_return_val_if_fail (quark > 0, NULL);
+
+  return g_datalist_id_get_data (&context->qdata, quark);
+}
+
 /* Timeouts */
 
 static void
diff --git a/glib/gmain.h b/glib/gmain.h
index c455353..a7aaf40 100644
--- a/glib/gmain.h
+++ b/glib/gmain.h
@@ -602,6 +602,21 @@ void     g_main_context_invoke      (GMainContext   *context,
                                      GSourceFunc     function,
                                      gpointer        data);
 
+GLIB_AVAILABLE_IN_2_40
+void                    g_main_context_set_qdata_full                   (GMainContext   *context,
+                                                                         GQuark          quark,
+                                                                         gpointer        data,
+                                                                         GDestroyNotify  notify);
+
+GLIB_AVAILABLE_IN_2_40
+void                    g_main_context_set_qdata                        (GMainContext   *context,
+                                                                         GQuark          quark,
+                                                                         gpointer        data);
+
+GLIB_AVAILABLE_IN_2_40
+gpointer                g_main_context_get_qdata                        (GMainContext   *context,
+                                                                         GQuark          quark);
+
 /* Hook for GClosure / GSource integration. Don't touch */
 GLIB_VAR GSourceFuncs g_timeout_funcs;
 GLIB_VAR GSourceFuncs g_child_watch_funcs;


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