[gcr: 2/4] gck-call: Move cb_object parameter to the async_ready functions




commit ac34777cc610b8c612a5ded54bff1c540e1463f5
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date:   Mon Nov 16 17:21:36 2020 +0100

    gck-call: Move cb_object parameter to the async_ready functions
    
    This is to mimic GTask more and so we can avoid using a temporary task
    only for temporary storing an object pointer.

 gck/gck-call.c       | 24 +++++++++++-----------
 gck/gck-enumerator.c |  4 ++--
 gck/gck-module.c     |  4 ++--
 gck/gck-modules.c    |  4 ++--
 gck/gck-object.c     | 24 +++++++++++-----------
 gck/gck-private.h    |  3 ++-
 gck/gck-session.c    | 56 ++++++++++++++++++++++++++--------------------------
 7 files changed, 59 insertions(+), 60 deletions(-)
---
diff --git a/gck/gck-call.c b/gck/gck-call.c
index 9efce0e..61ec603 100644
--- a/gck/gck-call.c
+++ b/gck/gck-call.c
@@ -216,14 +216,13 @@ _gck_call_sync (gpointer object, gpointer perform, gpointer complete,
 }
 
 gpointer
-_gck_call_async_prep (gpointer object, gpointer cb_object, gpointer perform,
-                       gpointer complete, gsize args_size, gpointer destroy)
+_gck_call_async_prep (gpointer object, gpointer perform, gpointer complete,
+                       gsize args_size, gpointer destroy)
 {
        GckArguments *args;
        GckCall *call;
 
        g_assert (!object || G_IS_OBJECT (object));
-       g_assert (!cb_object || G_IS_OBJECT (cb_object));
        g_assert (perform);
 
        if (!destroy)
@@ -235,7 +234,6 @@ _gck_call_async_prep (gpointer object, gpointer cb_object, gpointer perform,
 
        args = g_malloc0 (args_size);
        call = g_object_new (GCK_TYPE_CALL, NULL);
-       call->task = g_task_new (cb_object, NULL, NULL, NULL);
        call->destroy = (GDestroyNotify)destroy;
        call->perform = (GckPerformFunc)perform;
        call->complete = (GckCompleteFunc)complete;
@@ -269,20 +267,19 @@ _gck_call_async_object (GckCall *call, gpointer object)
 }
 
 GckCall*
-_gck_call_async_ready (gpointer data, GCancellable *cancellable,
-                        GAsyncReadyCallback callback, gpointer user_data)
+_gck_call_async_ready (gpointer data, gpointer cb_object,
+                       GCancellable *cancellable, GAsyncReadyCallback callback,
+                       gpointer user_data)
 {
        GckArguments *args = (GckArguments*)data;
        GckCall* call;
        GTask* task;
 
        g_assert (GCK_IS_CALL (args->call));
-       g_assert (G_IS_TASK (args->call->task));
+       g_assert (!cb_object || G_IS_OBJECT (cb_object));
 
-       /* XXX: Maybe move the callback object parameter to this function */
        call = g_steal_pointer (&args->call);
-       task = g_task_new (g_task_get_source_object (call->task),
-                          cancellable, callback, user_data);
+       task = g_task_new (cb_object, cancellable, callback, user_data);
        g_task_set_task_data (task, call, g_object_unref);
        g_set_object (&call->task, task);
 
@@ -302,10 +299,11 @@ _gck_call_async_go (GckCall *call)
 }
 
 void
-_gck_call_async_ready_go (gpointer data, GCancellable *cancellable,
-                           GAsyncReadyCallback callback, gpointer user_data)
+_gck_call_async_ready_go (gpointer data, gpointer cb_object,
+                           GCancellable *cancellable,
+                          GAsyncReadyCallback callback, gpointer user_data)
 {
-       GckCall *call = _gck_call_async_ready (data, cancellable, callback, user_data);
+       GckCall *call = _gck_call_async_ready (data, cb_object, cancellable, callback, user_data);
        _gck_call_async_go (call);
 }
 
diff --git a/gck/gck-enumerator.c b/gck/gck-enumerator.c
index 87a8176..7db066b 100644
--- a/gck/gck-enumerator.c
+++ b/gck/gck-enumerator.c
@@ -1306,12 +1306,12 @@ gck_enumerator_next_async (GckEnumerator *self, gint max_objects, GCancellable *
        state = check_out_enumerator_state (self);
        g_return_if_fail (state != NULL);
 
-       args =  _gck_call_async_prep (NULL, self, perform_enumerate_next, NULL,
+       args =  _gck_call_async_prep (NULL, perform_enumerate_next, NULL,
                                       sizeof (*args), free_enumerate_next);
        args->want_objects = max_objects <= 0 ? G_MAXINT : max_objects;
 
        args->state = state;
-       _gck_call_async_ready_go (args, cancellable, callback, user_data);
+       _gck_call_async_ready_go (args, self, cancellable, callback, user_data);
        g_object_unref (self);
 }
 
diff --git a/gck/gck-module.c b/gck/gck-module.c
index 509c4c2..d9e872a 100644
--- a/gck/gck-module.c
+++ b/gck/gck-module.c
@@ -420,11 +420,11 @@ gck_module_initialize_async (const gchar *path,
 
        g_return_if_fail (path != NULL);
 
-       args =  _gck_call_async_prep (NULL, NULL, perform_initialize, NULL,
+       args =  _gck_call_async_prep (NULL, perform_initialize, NULL,
                                      sizeof (*args), free_initialize);
        args->path = g_strdup (path);
 
-       _gck_call_async_ready_go (args, cancellable, callback, user_data);
+       _gck_call_async_ready_go (args, NULL, cancellable, callback, user_data);
 }
 
 /**
diff --git a/gck/gck-modules.c b/gck/gck-modules.c
index 2331423..13fab9b 100644
--- a/gck/gck-modules.c
+++ b/gck/gck-modules.c
@@ -123,10 +123,10 @@ gck_modules_initialize_registered_async (GCancellable *cancellable,
 {
        InitializeRegistered *args;
 
-       args =  _gck_call_async_prep (NULL, NULL, perform_initialize_registered, NULL,
+       args =  _gck_call_async_prep (NULL, perform_initialize_registered, NULL,
                                      sizeof (*args), free_initialize_registered);
 
-       _gck_call_async_ready_go (args, cancellable, callback, user_data);
+       _gck_call_async_ready_go (args, NULL, cancellable, callback, user_data);
 }
 
 /**
diff --git a/gck/gck-object.c b/gck/gck-object.c
index 084a74f..f9516ba 100644
--- a/gck/gck-object.c
+++ b/gck/gck-object.c
@@ -443,10 +443,10 @@ gck_object_destroy_async (GckObject *self, GCancellable *cancellable,
        g_return_if_fail (GCK_IS_OBJECT (self));
        g_return_if_fail (GCK_IS_SESSION (self->pv->session));
 
-       args = _gck_call_async_prep (self->pv->session, self, perform_destroy, NULL, sizeof (*args), NULL);
+       args = _gck_call_async_prep (self->pv->session, perform_destroy, NULL, sizeof (*args), NULL);
        args->object = self->pv->handle;
 
-       _gck_call_async_ready_go (args, cancellable, callback, user_data);
+       _gck_call_async_ready_go (args, self, cancellable, callback, user_data);
 }
 
 /**
@@ -558,13 +558,13 @@ gck_object_set_async (GckObject *self, GckAttributes *attrs, GCancellable *cance
        g_return_if_fail (GCK_IS_OBJECT (self));
        g_return_if_fail (attrs != NULL);
 
-       args = _gck_call_async_prep (self->pv->session, self, perform_set_attributes,
+       args = _gck_call_async_prep (self->pv->session, perform_set_attributes,
                                     NULL, sizeof (*args), free_set_attributes);
 
        args->attrs = gck_attributes_ref_sink (attrs);
        args->object = self->pv->handle;
 
-       _gck_call_async_ready_go (args, cancellable, callback, user_data);
+       _gck_call_async_ready_go (args, self, cancellable, callback, user_data);
 }
 
 /**
@@ -763,7 +763,7 @@ gck_object_get_async (GckObject *self,
 
        g_return_if_fail (GCK_IS_OBJECT (self));
 
-       args = _gck_call_async_prep (self->pv->session, self, perform_get_attributes,
+       args = _gck_call_async_prep (self->pv->session, perform_get_attributes,
                                     NULL, sizeof (*args), free_get_attributes);
 
        gck_builder_init (&args->builder);
@@ -772,7 +772,7 @@ gck_object_get_async (GckObject *self,
 
        args->object = self->pv->handle;
 
-       _gck_call_async_ready_go (args, cancellable, callback, user_data);
+       _gck_call_async_ready_go (args, self, cancellable, callback, user_data);
 }
 
 /**
@@ -967,14 +967,14 @@ gck_object_get_data_async (GckObject *self, gulong attr_type, GckAllocator alloc
        if (!allocator)
                allocator = g_realloc;
 
-       args = _gck_call_async_prep (self->pv->session, self, perform_get_attribute_data,
+       args = _gck_call_async_prep (self->pv->session, perform_get_attribute_data,
                                     NULL, sizeof (*args), free_get_attribute_data);
 
        args->allocator = allocator;
        args->object = self->pv->handle;
        args->type = attr_type;
 
-       _gck_call_async_ready_go (args, cancellable, callback, user_data);
+       _gck_call_async_ready_go (args, self, cancellable, callback, user_data);
 }
 
 /**
@@ -1119,14 +1119,14 @@ gck_object_set_template_async (GckObject *self, gulong attr_type, GckAttributes
        g_return_if_fail (GCK_IS_OBJECT (self));
        g_return_if_fail (attrs);
 
-       args = _gck_call_async_prep (self->pv->session, self, perform_set_template,
+       args = _gck_call_async_prep (self->pv->session, perform_set_template,
                                     NULL, sizeof (*args), free_set_template);
 
        args->attrs = gck_attributes_ref_sink (attrs);
        args->type = attr_type;
        args->object = self->pv->handle;
 
-       _gck_call_async_ready_go (args, cancellable, callback, user_data);
+       _gck_call_async_ready_go (args, self, cancellable, callback, user_data);
 }
 
 /**
@@ -1276,13 +1276,13 @@ gck_object_get_template_async (GckObject *self, gulong attr_type,
 
        g_return_if_fail (GCK_IS_OBJECT (self));
 
-       args = _gck_call_async_prep (self->pv->session, self, perform_get_template,
+       args = _gck_call_async_prep (self->pv->session, perform_get_template,
                                     NULL, sizeof (*args), free_get_template);
 
        args->object = self->pv->handle;
        args->type = attr_type;
 
-       _gck_call_async_ready_go (args, cancellable, callback, user_data);
+       _gck_call_async_ready_go (args, self, cancellable, callback, user_data);
 }
 
 /**
diff --git a/gck/gck-private.h b/gck/gck-private.h
index 46a9d11..c841e6a 100644
--- a/gck/gck-private.h
+++ b/gck/gck-private.h
@@ -179,13 +179,13 @@ gboolean           _gck_call_sync                        (gpointer object,
                                                            GError **err);
 
 gpointer           _gck_call_async_prep                  (gpointer object,
-                                                           gpointer cb_object,
                                                            gpointer perform,
                                                            gpointer complete,
                                                            gsize args_size,
                                                            gpointer destroy_func);
 
 GckCall*          _gck_call_async_ready                 (gpointer args,
+                                                           gpointer cb_object,
                                                            GCancellable *cancellable,
                                                            GAsyncReadyCallback callback,
                                                            gpointer user_data);
@@ -193,6 +193,7 @@ GckCall*          _gck_call_async_ready                 (gpointer args,
 void               _gck_call_async_go                    (GckCall *call);
 
 void               _gck_call_async_ready_go              (gpointer args,
+                                                           gpointer cb_object,
                                                            GCancellable *cancellable,
                                                            GAsyncReadyCallback callback,
                                                            gpointer user_data);
diff --git a/gck/gck-session.c b/gck/gck-session.c
index c9aecdf..65e30d3 100644
--- a/gck/gck-session.c
+++ b/gck/gck-session.c
@@ -478,13 +478,13 @@ gck_session_initable_init_async (GAsyncInitable *initable,
 
        g_object_ref (self);
 
-       args =  _gck_call_async_prep (self->pv->slot, self, perform_open_session, NULL,
+       args =  _gck_call_async_prep (self->pv->slot, perform_open_session, NULL,
                                      sizeof (*args), free_open_session);
 
        want_login = (self->pv->options & GCK_SESSION_LOGIN_USER) == GCK_SESSION_LOGIN_USER;
        args->session = self->pv->handle;
 
-       call =  _gck_call_async_ready (args, cancellable, callback, user_data);
+       call =  _gck_call_async_ready (args, self, cancellable, callback, user_data);
 
        /* Already have a session setup? */
        if (self->pv->handle && !want_login) {
@@ -954,12 +954,12 @@ gck_session_init_pin_async (GckSession *self, const guchar *pin, gsize n_pin,
                              GCancellable *cancellable, GAsyncReadyCallback callback,
                              gpointer user_data)
 {
-       InitPin* args = _gck_call_async_prep (self, self, perform_init_pin, NULL, sizeof (*args), 
free_init_pin);
+       InitPin* args = _gck_call_async_prep (self, perform_init_pin, NULL, sizeof (*args), free_init_pin);
 
        args->pin = pin && n_pin ? g_memdup (pin, n_pin) : NULL;
        args->n_pin = n_pin;
 
-       _gck_call_async_ready_go (args, cancellable, callback, user_data);
+       _gck_call_async_ready_go (args, self, cancellable, callback, user_data);
 }
 
 /**
@@ -1055,14 +1055,14 @@ gck_session_set_pin_async (GckSession *self, const guchar *old_pin, gsize n_old_
                             const guchar *new_pin, gsize n_new_pin, GCancellable *cancellable,
                             GAsyncReadyCallback callback, gpointer user_data)
 {
-       SetPin* args = _gck_call_async_prep (self, self, perform_set_pin, NULL, sizeof (*args), free_set_pin);
+       SetPin* args = _gck_call_async_prep (self, perform_set_pin, NULL, sizeof (*args), free_set_pin);
 
        args->old_pin = old_pin && n_old_pin ? g_memdup (old_pin, n_old_pin) : NULL;
        args->n_old_pin = n_old_pin;
        args->new_pin = new_pin && n_new_pin ? g_memdup (new_pin, n_new_pin) : NULL;
        args->n_new_pin = n_new_pin;
 
-       _gck_call_async_ready_go (args, cancellable, callback, user_data);
+       _gck_call_async_ready_go (args, self, cancellable, callback, user_data);
 }
 
 /**
@@ -1150,13 +1150,13 @@ gck_session_login_async (GckSession *self, gulong user_type, const guchar *pin,
                           gsize n_pin, GCancellable *cancellable, GAsyncReadyCallback callback,
                           gpointer user_data)
 {
-       Login* args = _gck_call_async_prep (self, self, perform_login, NULL, sizeof (*args), free_login);
+       Login* args = _gck_call_async_prep (self, perform_login, NULL, sizeof (*args), free_login);
 
        args->user_type = user_type;
        args->pin = pin && n_pin ? g_memdup (pin, n_pin) : NULL;
        args->n_pin = n_pin;
 
-       _gck_call_async_ready_go (args, cancellable, callback, user_data);
+       _gck_call_async_ready_go (args, self, cancellable, callback, user_data);
 }
 
 /**
@@ -1253,7 +1253,7 @@ gck_session_login_interactive_async (GckSession *self,
                                      GAsyncReadyCallback callback,
                                      gpointer user_data)
 {
-       Interactive* args = _gck_call_async_prep (self, self, perform_interactive, NULL, sizeof (*args), 
free_interactive);
+       Interactive* args = _gck_call_async_prep (self, perform_interactive, NULL, sizeof (*args), 
free_interactive);
 
        g_return_if_fail (GCK_IS_SESSION (self));
        g_return_if_fail (interaction == NULL || G_IS_TLS_INTERACTION (interaction));
@@ -1266,7 +1266,7 @@ gck_session_login_interactive_async (GckSession *self,
        args->interaction = interaction ? g_object_ref (interaction) : NULL;
        args->token = g_object_ref (self->pv->slot);
 
-       _gck_call_async_ready_go (args, cancellable, callback, user_data);
+       _gck_call_async_ready_go (args, self, cancellable, callback, user_data);
 }
 
 /**
@@ -1328,8 +1328,8 @@ void
 gck_session_logout_async (GckSession *self, GCancellable *cancellable,
                            GAsyncReadyCallback callback, gpointer user_data)
 {
-       GckArguments *args = _gck_call_async_prep (self, self, perform_logout, NULL, 0, NULL);
-       _gck_call_async_ready_go (args, cancellable, callback, user_data);
+       GckArguments *args = _gck_call_async_prep (self, perform_logout, NULL, 0, NULL);
+       _gck_call_async_ready_go (args, self, cancellable, callback, user_data);
 }
 
 /**
@@ -1442,14 +1442,14 @@ gck_session_create_object_async (GckSession *self, GckAttributes *attrs,
                                   GCancellable *cancellable, GAsyncReadyCallback callback,
                                   gpointer user_data)
 {
-       CreateObject *args = _gck_call_async_prep (self, self, perform_create_object,
+       CreateObject *args = _gck_call_async_prep (self, perform_create_object,
                                                    NULL, sizeof (*args), free_create_object);
 
        g_return_if_fail (attrs);
 
        args->attrs = gck_attributes_ref_sink (attrs);
 
-       _gck_call_async_ready_go (args, cancellable, callback, user_data);
+       _gck_call_async_ready_go (args, self, cancellable, callback, user_data);
 }
 
 /**
@@ -1624,10 +1624,10 @@ gck_session_find_handles_async (GckSession *self,
        g_return_if_fail (match != NULL);
        g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
 
-       args = _gck_call_async_prep (self, self, perform_find_objects,
+       args = _gck_call_async_prep (self, perform_find_objects,
                                     NULL, sizeof (*args), free_find_objects);
        args->attrs = gck_attributes_ref_sink (match);
-       _gck_call_async_ready_go (args, cancellable, callback, user_data);
+       _gck_call_async_ready_go (args, self, cancellable, callback, user_data);
 }
 
 /**
@@ -1940,7 +1940,7 @@ gck_session_generate_key_pair_async (GckSession *self, GckMechanism *mechanism,
                                       GCancellable *cancellable, GAsyncReadyCallback callback,
                                       gpointer user_data)
 {
-       GenerateKeyPair *args = _gck_call_async_prep (self, self, perform_generate_key_pair,
+       GenerateKeyPair *args = _gck_call_async_prep (self, perform_generate_key_pair,
                                                       NULL, sizeof (*args), free_generate_key_pair);
 
        g_return_if_fail (GCK_IS_SESSION (self));
@@ -1954,7 +1954,7 @@ gck_session_generate_key_pair_async (GckSession *self, GckMechanism *mechanism,
        args->public_attrs = gck_attributes_ref_sink (public_attrs);
        args->private_attrs = gck_attributes_ref_sink (private_attrs);
 
-       _gck_call_async_ready_go (args, cancellable, callback, user_data);
+       _gck_call_async_ready_go (args, self, cancellable, callback, user_data);
 }
 
 /**
@@ -2126,7 +2126,7 @@ gck_session_wrap_key_async (GckSession *self, GckObject *key, GckMechanism *mech
                              GckObject *wrapped, GCancellable *cancellable,
                              GAsyncReadyCallback callback, gpointer user_data)
 {
-       WrapKey *args = _gck_call_async_prep (self, self, perform_wrap_key,
+       WrapKey *args = _gck_call_async_prep (self, perform_wrap_key,
                                               NULL, sizeof (*args), free_wrap_key);
 
        g_return_if_fail (GCK_IS_SESSION (self));
@@ -2142,7 +2142,7 @@ gck_session_wrap_key_async (GckSession *self, GckObject *key, GckMechanism *mech
        g_object_get (wrapped, "handle", &args->wrapped, NULL);
        g_return_if_fail (args->wrapped != 0);
 
-       _gck_call_async_ready_go (args, cancellable, callback, user_data);
+       _gck_call_async_ready_go (args, self, cancellable, callback, user_data);
 }
 
 /**
@@ -2334,7 +2334,7 @@ gck_session_unwrap_key_async (GckSession *self,
                               GAsyncReadyCallback callback,
                               gpointer user_data)
 {
-       UnwrapKey *args = _gck_call_async_prep (self, self, perform_unwrap_key,
+       UnwrapKey *args = _gck_call_async_prep (self, perform_unwrap_key,
                                                 NULL, sizeof (*args), free_unwrap_key);
 
        g_return_if_fail (GCK_IS_SESSION (self));
@@ -2351,7 +2351,7 @@ gck_session_unwrap_key_async (GckSession *self,
        args->input = input;
        args->n_input = n_input;
 
-       _gck_call_async_ready_go (args, cancellable, callback, user_data);
+       _gck_call_async_ready_go (args, self, cancellable, callback, user_data);
 }
 
 /**
@@ -2506,7 +2506,7 @@ gck_session_derive_key_async (GckSession *self, GckObject *base, GckMechanism *m
                                GckAttributes *attrs, GCancellable *cancellable,
                                GAsyncReadyCallback callback, gpointer user_data)
 {
-       DeriveKey *args = _gck_call_async_prep (self, self, perform_derive_key,
+       DeriveKey *args = _gck_call_async_prep (self, perform_derive_key,
                                                 NULL, sizeof (*args), free_derive_key);
 
        g_return_if_fail (GCK_IS_SESSION (self));
@@ -2521,7 +2521,7 @@ gck_session_derive_key_async (GckSession *self, GckObject *base, GckMechanism *m
 
        args->attrs = gck_attributes_ref_sink (attrs);
 
-       _gck_call_async_ready_go (args, cancellable, callback, user_data);
+       _gck_call_async_ready_go (args, self, cancellable, callback, user_data);
 }
 
 /**
@@ -2674,7 +2674,7 @@ crypt_async (GckSession *self, GckObject *key, GckMechanism *mechanism, const gu
              gsize n_input, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data,
              CK_C_EncryptInit init_func, CK_C_Encrypt complete_func)
 {
-       Crypt *args = _gck_call_async_prep (self, self, perform_crypt, NULL, sizeof (*args), free_crypt);
+       Crypt *args = _gck_call_async_prep (self, perform_crypt, NULL, sizeof (*args), free_crypt);
 
        g_return_if_fail (GCK_IS_OBJECT (key));
        g_return_if_fail (mechanism);
@@ -2696,7 +2696,7 @@ crypt_async (GckSession *self, GckObject *key, GckMechanism *mechanism, const gu
        args->key_object = g_object_ref (key);
        args->interaction = gck_session_get_interaction (self);
 
-       _gck_call_async_ready_go (args, cancellable, callback, user_data);
+       _gck_call_async_ready_go (args, self, cancellable, callback, user_data);
 }
 
 static guchar*
@@ -3238,7 +3238,7 @@ gck_session_verify_async (GckSession *self, GckObject *key, GckMechanism *mechan
                            gsize n_signature, GCancellable *cancellable,
                            GAsyncReadyCallback callback, gpointer user_data)
 {
-       Verify *args = _gck_call_async_prep (self, self, perform_verify, NULL, sizeof (*args), free_verify);
+       Verify *args = _gck_call_async_prep (self, perform_verify, NULL, sizeof (*args), free_verify);
 
        g_return_if_fail (GCK_IS_OBJECT (key));
        g_return_if_fail (mechanism);
@@ -3257,7 +3257,7 @@ gck_session_verify_async (GckSession *self, GckObject *key, GckMechanism *mechan
        args->key_object = g_object_ref (key);
        args->interaction = gck_session_get_interaction (self);
 
-       _gck_call_async_ready_go (args, cancellable, callback, user_data);
+       _gck_call_async_ready_go (args, self, cancellable, callback, user_data);
 }
 
 /**


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