Add async callback tests to everything
authorMaxim Ermilov <zaspire@rambler.ru>
Wed, 2 Dec 2009 13:01:17 +0000 (11:01 -0200)
committerJohan Dahlin <johan@gnome.org>
Wed, 2 Dec 2009 13:01:17 +0000 (11:01 -0200)
gir/Everything-1.0-expected.gir
gir/everything.c
gir/everything.h

index 6944fc6..7e3caae 100644 (file)
@@ -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(),
index 9153560..e73d8ca 100644 (file)
@@ -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):
index 436c74c..6eaa09e 100644 (file)
@@ -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);