diff options
author | Maxim Ermilov <zaspire@rambler.ru> | 2009-12-02 11:01:17 -0200 |
---|---|---|
committer | Johan Dahlin <johan@gnome.org> | 2009-12-02 11:01:17 -0200 |
commit | 2f68deb3b0645be56b4cc59bce6f450f78b80a8d (patch) | |
tree | e846e4d5593af4651058386b5997eb13cadc46ff /gir | |
parent | 8486bc107587f3884306252c4d97cb2d55c6d8b6 (diff) | |
download | gobject-introspection-2f68deb3b0645be56b4cc59bce6f450f78b80a8d.tar.gz |
Add async callback tests to everything
Diffstat (limited to 'gir')
-rw-r--r-- | gir/Everything-1.0-expected.gir | 22 | ||||
-rw-r--r-- | gir/everything.c | 47 | ||||
-rw-r--r-- | 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 6944fc69..7e3caaee 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 9153560e..e73d8ca7 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 436c74ce..6eaa09ea 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); |