[gobject-introspection] Add async callback tests to everything



commit 2f68deb3b0645be56b4cc59bce6f450f78b80a8d
Author: Maxim Ermilov <zaspire rambler ru>
Date:   Wed Dec 2 11:01:17 2009 -0200

    Add async callback tests to everything

 gir/Everything-1.0-expected.gir |   22 ++++++++++++++++++
 gir/everything.c                |   47 ++++++++++++++++++++++++++++++++++++--
 gir/everything.h                |    4 +++
 3 files changed, 70 insertions(+), 3 deletions(-)
---
diff --git a/gir/Everything-1.0-expected.gir b/gir/Everything-1.0-expected.gir
index 6944fc6..7e3caae 100644
--- a/gir/Everything-1.0-expected.gir
+++ b/gir/Everything-1.0-expected.gir
@@ -661,6 +661,22 @@ case.">
         </parameter>
       </parameters>
     </function>
+    <function name="test_callback_async" c:identifier="test_callback_async">
+      <return-value transfer-ownership="none">
+        <type name="none" c:type="void"/>
+      </return-value>
+      <parameters>
+        <parameter name="callback"
+                   transfer-ownership="none"
+                   scope="async"
+                   closure="1">
+          <type name="TestCallbackUserData" c:type="TestCallbackUserData"/>
+        </parameter>
+        <parameter name="user_data" transfer-ownership="none">
+          <type name="any" c:type="gpointer"/>
+        </parameter>
+      </parameters>
+    </function>
     <function name="test_callback_destroy_notify"
               c:identifier="test_callback_destroy_notify"
               doc="Notified - callback persists until a DestroyNotify delegate
@@ -702,6 +718,12 @@ is invoked.">
         </parameter>
       </parameters>
     </function>
+    <function name="test_callback_thaw_async"
+              c:identifier="test_callback_thaw_async">
+      <return-value transfer-ownership="none">
+        <type name="int" c:type="int"/>
+      </return-value>
+    </function>
     <function name="test_callback_thaw_notifications"
               c:identifier="test_callback_thaw_notifications"
               doc="Invokes all callbacks installed by #test_callback_destroy_notify(),
diff --git a/gir/everything.c b/gir/everything.c
index 9153560..e73d8ca 100644
--- a/gir/everything.c
+++ b/gir/everything.c
@@ -1557,7 +1557,7 @@ test_callback_destroy_notify (TestCallbackUserData callback,
 
   retval = callback(user_data);
 
-  info = g_new(CallbackInfo, 1);
+  info = g_slice_new(CallbackInfo);
   info->callback = callback;
   info->notify = notify;
   info->user_data = user_data;
@@ -1584,11 +1584,11 @@ test_callback_thaw_notifications (void)
 
   for (node = notified_callbacks; node != NULL; node = node->next)
     {
-      CallbackInfo *info = (CallbackInfo *)node->data;
+      CallbackInfo *info = node->data;
       retval += info->callback (info->user_data);
       if (info->notify)
         info->notify (info->user_data);
-      g_free (info);
+      g_slice_free (CallbackInfo, info);
     }
 
   g_slist_free (notified_callbacks);
@@ -1597,6 +1597,47 @@ test_callback_thaw_notifications (void)
   return retval;
 }
 
+static GSList *async_callbacks = NULL;
+
+/**
+ * test_callback_async:
+ * @callback: (scope async):
+ *
+ **/
+void
+test_callback_async (TestCallbackUserData callback,
+                     gpointer user_data)
+{
+  CallbackInfo *info;
+
+  info = g_slice_new(CallbackInfo);
+  info->callback = callback;
+  info->user_data = user_data;
+
+  async_callbacks = g_slist_prepend(async_callbacks, info);
+}
+
+/**
+ * test_callback_thaw_async:
+ */
+int
+test_callback_thaw_async (void)
+{
+  int retval = 0;
+  GSList *node;
+
+  for (node = async_callbacks; node != NULL; node = node->next)
+    {
+      CallbackInfo *info = node->data;
+      retval = info->callback (info->user_data);
+      g_slice_free (CallbackInfo, info);
+    }
+
+  g_slist_free (async_callbacks);
+  async_callbacks = NULL;
+  return retval;
+}
+
 /**
  * test_callback_infinite:
  * @callback: (scope infinite):
diff --git a/gir/everything.h b/gir/everything.h
index 436c74c..6eaa09e 100644
--- a/gir/everything.h
+++ b/gir/everything.h
@@ -291,6 +291,10 @@ int test_callback_destroy_notify (TestCallbackUserData callback,
                                   gpointer user_data,
                                   GDestroyNotify notify);
 int test_callback_thaw_notifications (void);
+
+void test_callback_async (TestCallbackUserData callback, gpointer user_data);
+int test_callback_thaw_async (void);
+
 int test_callback_infinite (TestCallbackUserData callback,
                            gpointer user_data);
 



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