[libsecret] Pass return_type to prompt async begin functions, rather than finish



commit bdbdadf40c842c0f01f274f9bdff4b5947986dff
Author: Stef Walter <stefw gnome org>
Date:   Fri Jun 21 12:40:40 2013 +0200

    Pass return_type to prompt async begin functions, rather than finish
    
    Much like g_dbus_connection_call() we now pass our return_type value
    when starting the async operation. This unbreaks vala and various
    other bindings that make assumptions about the form of xxx_finish()
    async calls.
    
    This is an API/API break, but its to the portion of the library
    marked as unstable. Only used by seahorse (in jhbuild) and updated
    usage there.

 libsecret/secret-paths.c      |   28 +++++++++++++---------------
 libsecret/secret-paths.h      |    2 +-
 libsecret/secret-prompt.c     |   16 ++++++++++------
 libsecret/secret-prompt.h     |    2 +-
 libsecret/secret-service.c    |   23 +++++++----------------
 libsecret/secret-service.h    |    4 ++--
 libsecret/tests/test-prompt.c |   20 ++++++++++----------
 7 files changed, 44 insertions(+), 51 deletions(-)
---
diff --git a/libsecret/secret-paths.c b/libsecret/secret-paths.c
index 49ebe26..8114b79 100644
--- a/libsecret/secret-paths.c
+++ b/libsecret/secret-paths.c
@@ -1014,7 +1014,7 @@ on_xlock_prompted (GObject *source,
        GVariant *retval;
        gchar *path;
 
-       retval = secret_service_prompt_finish (self, result, G_VARIANT_TYPE ("ao"), &error);
+       retval = secret_service_prompt_finish (self, result, &error);
        if (error != NULL)
                g_simple_async_result_take_error (res, error);
 
@@ -1058,8 +1058,8 @@ on_xlock_called (GObject *source,
 
                } else {
                        closure->prompt = _secret_prompt_instance (self, prompt);
-                       secret_service_prompt (self, closure->prompt, closure->cancellable,
-                                               on_xlock_prompted, g_object_ref (res));
+                       secret_service_prompt (self, closure->prompt, G_VARIANT_TYPE ("ao"),
+                                              closure->cancellable, on_xlock_prompted, g_object_ref (res));
                }
 
                g_strfreev (xlocked);
@@ -1395,7 +1395,7 @@ on_delete_prompted (GObject *source,
        GVariant *retval;
 
        retval = secret_service_prompt_finish (SECRET_SERVICE (source), result,
-                                              NULL, &error);
+                                              &error);
 
        if (error == NULL)
                closure->deleted = TRUE;
@@ -1430,7 +1430,7 @@ on_delete_complete (GObject *source,
                } else {
                        closure->prompt = _secret_prompt_instance (self, prompt_path);
 
-                       secret_service_prompt (self, closure->prompt,
+                       secret_service_prompt (self, closure->prompt, NULL,
                                               closure->cancellable,
                                               on_delete_prompted,
                                               g_object_ref (res));
@@ -1624,8 +1624,7 @@ on_create_collection_prompt (GObject *source,
        GError *error = NULL;
        GVariant *value;
 
-       value = secret_service_prompt_finish (SECRET_SERVICE (source), result,
-                                             G_VARIANT_TYPE ("o"), &error);
+       value = secret_service_prompt_finish (SECRET_SERVICE (source), result, &error);
        if (error != NULL)
                g_simple_async_result_take_error (res, error);
        if (value != NULL) {
@@ -1655,7 +1654,7 @@ on_create_collection_called (GObject *source,
                g_variant_get (retval, "(&o&o)", &collection_path, &prompt_path);
                if (!_secret_util_empty_path (prompt_path)) {
                        closure->prompt = _secret_prompt_instance (self, prompt_path);
-                       secret_service_prompt (self, closure->prompt,
+                       secret_service_prompt (self, closure->prompt, G_VARIANT_TYPE ("o"),
                                               closure->cancellable, on_create_collection_prompt,
                                               g_object_ref (res));
 
@@ -1893,8 +1892,7 @@ on_create_item_prompt (GObject *source,
        GError *error = NULL;
        GVariant *value;
 
-       value = secret_service_prompt_finish (SECRET_SERVICE (source), result,
-                                             G_VARIANT_TYPE ("o"), &error);
+       value = secret_service_prompt_finish (SECRET_SERVICE (source), result, &error);
        if (error != NULL)
                g_simple_async_result_take_error (res, error);
        if (value != NULL) {
@@ -1924,7 +1922,7 @@ on_create_item_called (GObject *source,
                g_variant_get (retval, "(&o&o)", &item_path, &prompt_path);
                if (!_secret_util_empty_path (prompt_path)) {
                        closure->prompt = _secret_prompt_instance (self, prompt_path);
-                       secret_service_prompt (self, closure->prompt,
+                       secret_service_prompt (self, closure->prompt, G_VARIANT_TYPE ("o"),
                                               closure->cancellable, on_create_item_prompt,
                                               g_object_ref (res));
 
@@ -2422,6 +2420,7 @@ secret_service_prompt_at_dbus_path_sync (SecretService *self,
  * secret_service_prompt_at_dbus_path:
  * @self: the secret service
  * @prompt_path: the D-Bus object path of the prompt
+ * @return_type: (allow-none): the variant type of the prompt result
  * @cancellable: optional cancellation object
  * @callback: called when the operation completes
  * @user_data: data to be passed to the callback
@@ -2438,6 +2437,7 @@ secret_service_prompt_at_dbus_path_sync (SecretService *self,
 void
 secret_service_prompt_at_dbus_path (SecretService *self,
                                     const gchar *prompt_path,
+                                    const GVariantType *return_type,
                                     GCancellable *cancellable,
                                     GAsyncReadyCallback callback,
                                     gpointer user_data)
@@ -2449,7 +2449,7 @@ secret_service_prompt_at_dbus_path (SecretService *self,
        g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
 
        prompt = _secret_prompt_instance (self, prompt_path);
-       secret_service_prompt (self, prompt, cancellable, callback, user_data);
+       secret_service_prompt (self, prompt, return_type, cancellable, callback, user_data);
        g_object_unref (prompt);
 }
 
@@ -2457,7 +2457,6 @@ secret_service_prompt_at_dbus_path (SecretService *self,
  * secret_service_prompt_at_dbus_path_finish:
  * @self: the secret service
  * @result: the asynchronous result passed to the callback
- * @return_type: the variant type of the prompt result
  * @error: location to place an error on failure
  *
  * Complete asynchronous operation to perform prompting for a #SecretPrompt.
@@ -2472,12 +2471,11 @@ secret_service_prompt_at_dbus_path (SecretService *self,
 GVariant *
 secret_service_prompt_at_dbus_path_finish (SecretService *self,
                                            GAsyncResult *result,
-                                           const GVariantType *return_type,
                                            GError **error)
 {
        g_return_val_if_fail (SECRET_IS_SERVICE (self), NULL);
        g_return_val_if_fail (G_IS_ASYNC_RESULT (result), NULL);
        g_return_val_if_fail (error == NULL || *error == NULL, NULL);
 
-       return secret_service_prompt_finish (self, result, return_type, error);
+       return secret_service_prompt_finish (self, result, error);
 }
diff --git a/libsecret/secret-paths.h b/libsecret/secret-paths.h
index b744f34..8bda883 100644
--- a/libsecret/secret-paths.h
+++ b/libsecret/secret-paths.h
@@ -176,13 +176,13 @@ GVariant *          secret_service_prompt_at_dbus_path_sync            (SecretSe
 
 void                secret_service_prompt_at_dbus_path                 (SecretService *self,
                                                                         const gchar *prompt_path,
+                                                                        const GVariantType *return_type,
                                                                         GCancellable *cancellable,
                                                                         GAsyncReadyCallback callback,
                                                                         gpointer user_data);
 
 GVariant *          secret_service_prompt_at_dbus_path_finish          (SecretService *self,
                                                                         GAsyncResult *result,
-                                                                        const GVariantType *return_type,
                                                                         GError **error);
 
 void                secret_service_delete_item_dbus_path               (SecretService *self,
diff --git a/libsecret/secret-prompt.c b/libsecret/secret-prompt.c
index 8671c5f..61c1e14 100644
--- a/libsecret/secret-prompt.c
+++ b/libsecret/secret-prompt.c
@@ -167,12 +167,12 @@ secret_prompt_run (SecretPrompt *self,
        closure = g_new0 (RunClosure, 1);
        closure->loop = g_main_loop_new (context, FALSE);
 
-       secret_prompt_perform (self, window_id, cancellable,
+       secret_prompt_perform (self, window_id, return_type, cancellable,
                               on_prompt_run_complete, closure);
 
        g_main_loop_run (closure->loop);
 
-       retval = secret_prompt_perform_finish (self, closure->result, return_type, error);
+       retval = secret_prompt_perform_finish (self, closure->result, error);
 
        g_main_loop_unref (closure->loop);
        g_object_unref (closure->result);
@@ -244,6 +244,7 @@ typedef struct {
        GVariant *result;
        guint signal;
        guint watch;
+       GVariantType *return_type;
 } PerformClosure;
 
 static void
@@ -255,6 +256,8 @@ perform_closure_free (gpointer data)
        g_object_unref (closure->connection);
        if (closure->result)
                g_variant_unref (closure->result);
+       if (closure->return_type)
+               g_variant_type_free (closure->return_type);
        g_assert (closure->signal == 0);
        g_assert (closure->watch == 0);
        g_slice_free (PerformClosure, closure);
@@ -409,6 +412,7 @@ on_prompt_cancelled (GCancellable *cancellable,
  * secret_prompt_perform:
  * @self: a prompt
  * @window_id: XWindow id for parent window to be transient for
+ * @return_type: the variant type of the prompt result
  * @cancellable: optional cancellation object
  * @callback: called when the operation completes
  * @user_data: data to be passed to the callback
@@ -426,6 +430,7 @@ on_prompt_cancelled (GCancellable *cancellable,
 void
 secret_prompt_perform (SecretPrompt *self,
                        gulong window_id,
+                       const GVariantType *return_type,
                        GCancellable *cancellable,
                        GAsyncReadyCallback callback,
                        gpointer user_data)
@@ -455,6 +460,7 @@ secret_prompt_perform (SecretPrompt *self,
        closure->connection = g_object_ref (g_dbus_proxy_get_connection (proxy));
        closure->call_cancellable = g_cancellable_new ();
        closure->async_cancellable = cancellable ? g_object_ref (cancellable) : NULL;
+       closure->return_type = return_type ? g_variant_type_copy (return_type) : NULL;
        g_simple_async_result_set_op_res_gpointer (res, closure, perform_closure_free);
 
        if (window_id == 0)
@@ -498,7 +504,6 @@ secret_prompt_perform (SecretPrompt *self,
  * secret_prompt_perform_finish:
  * @self: a prompt
  * @result: the asynchronous result passed to the callback
- * @return_type: the variant type of the prompt result
  * @error: location to place an error on failure
  *
  * Complete asynchronous operation to run a prompt and perform the prompting.
@@ -513,7 +518,6 @@ secret_prompt_perform (SecretPrompt *self,
 GVariant *
 secret_prompt_perform_finish (SecretPrompt *self,
                               GAsyncResult *result,
-                              const GVariantType *return_type,
                               GError **error)
 {
        PerformClosure *closure;
@@ -533,8 +537,8 @@ secret_prompt_perform_finish (SecretPrompt *self,
        closure = g_simple_async_result_get_op_res_gpointer (res);
        if (closure->result == NULL)
                return NULL;
-       if (return_type != NULL && !g_variant_is_of_type (closure->result, return_type)) {
-               string = g_variant_type_dup_string (return_type);
+       if (closure->return_type != NULL && !g_variant_is_of_type (closure->result, closure->return_type)) {
+               string = g_variant_type_dup_string (closure->return_type);
                g_warning ("received unexpected result type %s from Completed signal instead of expected %s",
                           g_variant_get_type_string (closure->result), string);
                g_free (string);
diff --git a/libsecret/secret-prompt.h b/libsecret/secret-prompt.h
index a6abac2..7660c1c 100644
--- a/libsecret/secret-prompt.h
+++ b/libsecret/secret-prompt.h
@@ -66,13 +66,13 @@ GVariant *          secret_prompt_perform_sync              (SecretPrompt *self,
 
 void                secret_prompt_perform                   (SecretPrompt *self,
                                                              gulong window_id,
+                                                             const GVariantType *return_type,
                                                              GCancellable *cancellable,
                                                              GAsyncReadyCallback callback,
                                                              gpointer user_data);
 
 GVariant *          secret_prompt_perform_finish            (SecretPrompt *self,
                                                              GAsyncResult *result,
-                                                             const GVariantType *return_type,
                                                              GError **error);
 
 G_END_DECLS
diff --git a/libsecret/secret-service.c b/libsecret/secret-service.c
index 55a4e21..3c9539c 100644
--- a/libsecret/secret-service.c
+++ b/libsecret/secret-service.c
@@ -312,7 +312,7 @@ on_real_prompt_completed (GObject *source,
        GError *error = NULL;
        GVariant *retval;
 
-       retval = secret_prompt_perform_finish (SECRET_PROMPT (source), result, NULL, &error);
+       retval = secret_prompt_perform_finish (SECRET_PROMPT (source), result, &error);
        if (retval != NULL)
                g_simple_async_result_set_op_res_gpointer (res, retval, (GDestroyNotify)g_variant_unref);
        if (error != NULL)
@@ -324,6 +324,7 @@ on_real_prompt_completed (GObject *source,
 static void
 secret_service_real_prompt_async (SecretService *self,
                                   SecretPrompt *prompt,
+                                  const GVariantType *return_type,
                                   GCancellable *cancellable,
                                   GAsyncReadyCallback callback,
                                   gpointer user_data)
@@ -333,7 +334,7 @@ secret_service_real_prompt_async (SecretService *self,
        res =  g_simple_async_result_new (G_OBJECT (self), callback, user_data,
                                          secret_service_real_prompt_async);
 
-       secret_prompt_perform (prompt, 0, cancellable,
+       secret_prompt_perform (prompt, 0, return_type, cancellable,
                               on_real_prompt_completed,
                               g_object_ref (res));
 
@@ -343,12 +344,10 @@ secret_service_real_prompt_async (SecretService *self,
 static GVariant *
 secret_service_real_prompt_finish (SecretService *self,
                                    GAsyncResult *result,
-                                   const GVariantType *return_type,
                                    GError **error)
 {
        GSimpleAsyncResult *res;
        GVariant *retval;
-       gchar *string;
 
        g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (self),
                              secret_service_real_prompt_async), NULL);
@@ -361,14 +360,6 @@ secret_service_real_prompt_finish (SecretService *self,
        if (retval == NULL)
                return NULL;
 
-       if (return_type != NULL && !g_variant_is_of_type (retval, return_type)) {
-               string = g_variant_type_dup_string (return_type);
-               g_warning ("received unexpected result type %s from prompt's Completed signal instead of 
expected %s",
-                          g_variant_get_type_string (retval), string);
-               g_free (string);
-               return NULL;
-       }
-
        return g_variant_ref (retval);
 }
 
@@ -1684,6 +1675,7 @@ secret_service_prompt_sync (SecretService *self,
  * secret_service_prompt:
  * @self: the secret service
  * @prompt: the prompt
+ * @return_type: (allow-none): the variant type of the prompt result
  * @cancellable: optional cancellation object
  * @callback: called when the operation completes
  * @user_data: data to be passed to the callback
@@ -1700,6 +1692,7 @@ secret_service_prompt_sync (SecretService *self,
 void
 secret_service_prompt (SecretService *self,
                        SecretPrompt *prompt,
+                       const GVariantType *return_type,
                        GCancellable *cancellable,
                        GAsyncReadyCallback callback,
                        gpointer user_data)
@@ -1713,14 +1706,13 @@ secret_service_prompt (SecretService *self,
        klass = SECRET_SERVICE_GET_CLASS (self);
        g_return_if_fail (klass->prompt_async != NULL);
 
-       (klass->prompt_async) (self, prompt, cancellable, callback, user_data);
+       (klass->prompt_async) (self, prompt, return_type, cancellable, callback, user_data);
 }
 
 /**
  * secret_service_prompt_finish:
  * @self: the secret service
  * @result: the asynchronous result passed to the callback
- * @return_type: the variant type of the prompt result
  * @error: location to place an error on failure
  *
  * Complete asynchronous operation to perform prompting for a #SecretPrompt.
@@ -1735,7 +1727,6 @@ secret_service_prompt (SecretService *self,
 GVariant *
 secret_service_prompt_finish (SecretService *self,
                               GAsyncResult *result,
-                              const GVariantType *return_type,
                               GError **error)
 {
        SecretServiceClass *klass;
@@ -1747,7 +1738,7 @@ secret_service_prompt_finish (SecretService *self,
        klass = SECRET_SERVICE_GET_CLASS (self);
        g_return_val_if_fail (klass->prompt_finish != NULL, NULL);
 
-       return (klass->prompt_finish) (self, result, return_type, error);
+       return (klass->prompt_finish) (self, result, error);
 }
 
 /**
diff --git a/libsecret/secret-service.h b/libsecret/secret-service.h
index bceaf92..e35f415 100644
--- a/libsecret/secret-service.h
+++ b/libsecret/secret-service.h
@@ -75,13 +75,13 @@ struct _SecretServiceClass {
 
        void        (* prompt_async)     (SecretService *self,
                                          SecretPrompt *prompt,
+                                         const GVariantType *return_type,
                                          GCancellable *cancellable,
                                          GAsyncReadyCallback callback,
                                          gpointer user_data);
 
        GVariant *  (* prompt_finish)    (SecretService *self,
                                          GAsyncResult *result,
-                                         const GVariantType *return_type,
                                          GError **error);
 
        GType       (* get_collection_gtype)  (SecretService *self);
@@ -168,13 +168,13 @@ GVariant *           secret_service_prompt_sync                   (SecretService
 
 void                 secret_service_prompt                        (SecretService *self,
                                                                    SecretPrompt *prompt,
+                                                                   const GVariantType *return_type,
                                                                    GCancellable *cancellable,
                                                                    GAsyncReadyCallback callback,
                                                                    gpointer user_data);
 
 GVariant *           secret_service_prompt_finish                 (SecretService *self,
                                                                    GAsyncResult *result,
-                                                                   const GVariantType *return_type,
                                                                    GError **error);
 
 void                 secret_service_search                        (SecretService *service,
diff --git a/libsecret/tests/test-prompt.c b/libsecret/tests/test-prompt.c
index b4b72c7..3fd1a1a 100644
--- a/libsecret/tests/test-prompt.c
+++ b/libsecret/tests/test-prompt.c
@@ -146,12 +146,12 @@ test_perform_async (Test *test,
 
        prompt = _secret_prompt_instance (test->service, "/org/freedesktop/secrets/prompts/simple");
 
-       secret_prompt_perform (prompt, 0, NULL, on_async_result, &result);
+       secret_prompt_perform (prompt, 0, NULL, NULL, on_async_result, &result);
        g_assert (result == NULL);
 
        egg_test_wait ();
 
-       retval = secret_prompt_perform_finish (prompt, result, NULL, &error);
+       retval = secret_prompt_perform_finish (prompt, result, &error);
        g_assert_no_error (error);
        g_assert (retval != NULL);
        g_variant_unref (retval);
@@ -177,7 +177,7 @@ test_perform_cancel (Test *test,
        prompt = _secret_prompt_instance (test->service, "/org/freedesktop/secrets/prompts/delay");
 
        cancellable = g_cancellable_new ();
-       secret_prompt_perform (prompt, 0, cancellable, on_async_result, &result);
+       secret_prompt_perform (prompt, 0, NULL, cancellable, on_async_result, &result);
        g_assert (result == NULL);
 
        g_cancellable_cancel (cancellable);
@@ -185,7 +185,7 @@ test_perform_cancel (Test *test,
 
        egg_test_wait ();
 
-       retval = secret_prompt_perform_finish (prompt, result, NULL, &error);
+       retval = secret_prompt_perform_finish (prompt, result, &error);
        g_assert_no_error (error);
        g_assert (retval != NULL);
        g_variant_unref (retval);
@@ -305,12 +305,12 @@ test_service_async (Test *test,
 
        prompt = _secret_prompt_instance (test->service, "/org/freedesktop/secrets/prompts/simple");
 
-       secret_service_prompt (test->service, prompt, NULL, on_async_result, &result);
+       secret_service_prompt (test->service, prompt, NULL, NULL, on_async_result, &result);
        g_assert (result == NULL);
 
        egg_test_wait ();
 
-       retval = secret_service_prompt_finish (test->service, result, NULL, &error);
+       retval = secret_service_prompt_finish (test->service, result, &error);
        g_assert_no_error (error);
        g_assert (retval != NULL);
        g_variant_unref (retval);
@@ -334,12 +334,12 @@ test_service_fail (Test *test,
 
        prompt = _secret_prompt_instance (test->service, "/org/freedesktop/secrets/prompts/error");
 
-       secret_service_prompt (test->service, prompt, NULL, on_async_result, &result);
+       secret_service_prompt (test->service, prompt, NULL, NULL, on_async_result, &result);
        g_assert (result == NULL);
 
        egg_test_wait ();
 
-       retval = secret_service_prompt_finish (test->service, result, NULL, &error);
+       retval = secret_service_prompt_finish (test->service, result, &error);
        g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_NOT_SUPPORTED);
        g_assert (retval == NULL);
        g_object_unref (result);
@@ -362,13 +362,13 @@ test_service_path (Test *test,
 
        prompt = _secret_prompt_instance (test->service, "/org/freedesktop/secrets/prompts/simple");
 
-       secret_service_prompt (test->service, prompt, NULL, on_async_result, &result);
+       secret_service_prompt (test->service, prompt, NULL, NULL, on_async_result, &result);
        g_assert (result == NULL);
 
        g_object_unref (prompt);
        egg_test_wait ();
 
-       retval = secret_service_prompt_finish (test->service, result, NULL, &error);
+       retval = secret_service_prompt_finish (test->service, result, &error);
        g_assert_no_error (error);
        g_assert (retval != NULL);
        g_variant_unref (retval);


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