Pass service GType to secret_service_new() and friends.
authorStef Walter <stefw@gnome.org>
Wed, 27 Jun 2012 09:45:09 +0000 (11:45 +0200)
committerStef Walter <stefw@gnome.org>
Wed, 27 Jun 2012 09:45:09 +0000 (11:45 +0200)
 * This allows callers to use a custom SecretService derived
   type with the rest of libsecret
 * The default way to get a SecretService is via secret_service_get()
   which remains simple without the GType parameter

library/secret-service.c
library/secret-service.h
library/tests/test-service.c

index d449f50..9afaad3 100644 (file)
@@ -834,6 +834,7 @@ secret_service_get_sync (SecretServiceFlags flags,
 
 /**
  * secret_service_new:
+ * @service_gtype: the GType of the new secret service
  * @service_bus_name: (allow-none): the D-Bus service name of the secret service
  * @flags: flags for which service functionality to ensure is initialized
  * @cancellable: optional cancellation object
@@ -844,6 +845,9 @@ secret_service_get_sync (SecretServiceFlags flags,
  *
  * This function is rarely used, see secret_service_get() instead.
  *
+ * The @service_gtype argument should be set to %SECRET_TYPE_SERVICE or a the type
+ * of a derived class.
+ *
  * If @flags contains any flags of which parts of the secret service to
  * ensure are initialized, then those will be initialized before returning.
  *
@@ -852,18 +856,20 @@ secret_service_get_sync (SecretServiceFlags flags,
  * This method will return immediately and complete asynchronously.
  */
 void
-secret_service_new (const gchar *service_bus_name,
+secret_service_new (GType service_gtype,
+                    const gchar *service_bus_name,
                     SecretServiceFlags flags,
                     GCancellable *cancellable,
                     GAsyncReadyCallback callback,
                     gpointer user_data)
 {
        g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
+       g_return_if_fail (g_type_is_a (service_gtype, SECRET_TYPE_SERVICE));
 
        if (service_bus_name == NULL)
                service_bus_name = default_bus_name;
 
-       g_async_initable_new_async (SECRET_TYPE_SERVICE, G_PRIORITY_DEFAULT,
+       g_async_initable_new_async (service_gtype, G_PRIORITY_DEFAULT,
                                    cancellable, callback, user_data,
                                    "g-flags", G_DBUS_PROXY_FLAGS_NONE,
                                    "g-interface-info", _secret_gen_service_interface_info (),
@@ -909,6 +915,7 @@ secret_service_new_finish (GAsyncResult *result,
 
 /**
  * secret_service_new_sync:
+ * @service_gtype: the GType of the new secret service
  * @service_bus_name: (allow-none): the D-Bus service name of the secret service
  * @flags: flags for which service functionality to ensure is initialized
  * @cancellable: optional cancellation object
@@ -918,6 +925,9 @@ secret_service_new_finish (GAsyncResult *result,
  *
  * This function is rarely used, see secret_service_get_sync() instead.
  *
+ * The @service_gtype argument should be set to %SECRET_TYPE_SERVICE or a the
+ * type of a derived class.
+ *
  * If @flags contains any flags of which parts of the secret service to
  * ensure are initialized, then those will be initialized before returning.
  *
@@ -930,17 +940,19 @@ secret_service_new_finish (GAsyncResult *result,
  *          should be released with g_object_unref().
  */
 SecretService *
-secret_service_new_sync (const gchar *service_bus_name,
+secret_service_new_sync (GType service_gtype,
+                         const gchar *service_bus_name,
                          SecretServiceFlags flags,
                          GCancellable *cancellable,
                          GError **error)
 {
        g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
+       g_return_val_if_fail (g_type_is_a (service_gtype, SECRET_TYPE_SERVICE), NULL);
 
        if (service_bus_name == NULL)
                service_bus_name = default_bus_name;
 
-       return g_initable_new (SECRET_TYPE_SERVICE, cancellable, error,
+       return g_initable_new (service_gtype, cancellable, error,
                               "g-flags", G_DBUS_PROXY_FLAGS_NONE,
                               "g-interface-info", _secret_gen_service_interface_info (),
                               "g-name", service_bus_name,
index 25fc944..751a5d3 100644 (file)
@@ -93,7 +93,8 @@ SecretService *      secret_service_get_sync                      (SecretService
                                                                    GCancellable *cancellable,
                                                                    GError **error);
 
-void                 secret_service_new                           (const gchar *service_bus_name,
+void                 secret_service_new                           (GType service_gtype,
+                                                                   const gchar *service_bus_name,
                                                                    SecretServiceFlags flags,
                                                                    GCancellable *cancellable,
                                                                    GAsyncReadyCallback callback,
@@ -102,7 +103,8 @@ void                 secret_service_new                           (const gchar *
 SecretService *      secret_service_new_finish                    (GAsyncResult *result,
                                                                    GError **error);
 
-SecretService *      secret_service_new_sync                      (const gchar *service_bus_name,
+SecretService *      secret_service_new_sync                      (GType service_gtype,
+                                                                   const gchar *service_bus_name,
                                                                    SecretServiceFlags flags,
                                                                    GCancellable *cancellable,
                                                                    GError **error);
index 081cacd..ec6d797 100644 (file)
@@ -245,10 +245,12 @@ test_new_sync (void)
 
        /* Both these sohuld point to different things */
 
-       service1 = secret_service_new_sync (NULL, SECRET_SERVICE_NONE, NULL, &error);
+       service1 = secret_service_new_sync (SECRET_TYPE_SERVICE, NULL,
+                                           SECRET_SERVICE_NONE, NULL, &error);
        g_assert_no_error (error);
 
-       service2 = secret_service_new_sync (NULL, SECRET_SERVICE_NONE, NULL, &error);
+       service2 = secret_service_new_sync (SECRET_TYPE_SERVICE, NULL,
+                                           SECRET_SERVICE_NONE, NULL, &error);
        g_assert_no_error (error);
 
        g_assert (SECRET_IS_SERVICE (service1));
@@ -272,14 +274,16 @@ test_new_async (void)
 
        /* Both these sohuld point to different things */
 
-       secret_service_new (NULL, SECRET_SERVICE_NONE, NULL, on_complete_get_result, &result);
+       secret_service_new (SECRET_TYPE_SERVICE, NULL, SECRET_SERVICE_NONE,
+                           NULL, on_complete_get_result, &result);
        g_assert (result == NULL);
        egg_test_wait ();
        service1 = secret_service_new_finish (result, &error);
        g_assert_no_error (error);
        g_clear_object (&result);
 
-       secret_service_new (NULL, SECRET_SERVICE_NONE, NULL, on_complete_get_result, &result);
+       secret_service_new (SECRET_TYPE_SERVICE, NULL, SECRET_SERVICE_NONE, NULL,
+                           on_complete_get_result, &result);
        g_assert (result == NULL);
        egg_test_wait ();
        service2 = secret_service_new_finish (result, &error);
@@ -306,7 +310,8 @@ test_new_more_sync (Test *test,
        const gchar *path;
        GList *collections;
 
-       service = secret_service_new_sync (NULL, SECRET_SERVICE_NONE, NULL, &error);
+       service = secret_service_new_sync (SECRET_TYPE_SERVICE, NULL, SECRET_SERVICE_NONE,
+                                          NULL, &error);
        g_assert_no_error (error);
        g_assert (SECRET_IS_SERVICE (service));
 
@@ -317,7 +322,8 @@ test_new_more_sync (Test *test,
        g_object_unref (service);
        egg_assert_not_object (service);
 
-       service = secret_service_new_sync (NULL, SECRET_SERVICE_LOAD_COLLECTIONS, NULL, &error);
+       service = secret_service_new_sync (SECRET_TYPE_SERVICE, NULL,
+                                          SECRET_SERVICE_LOAD_COLLECTIONS, NULL, &error);
        g_assert_no_error (error);
        g_assert (SECRET_IS_SERVICE (service));
 
@@ -330,7 +336,8 @@ test_new_more_sync (Test *test,
        g_object_unref (service);
        egg_assert_not_object (service);
 
-       service = secret_service_new_sync (NULL, SECRET_SERVICE_OPEN_SESSION, NULL, &error);
+       service = secret_service_new_sync (SECRET_TYPE_SERVICE, NULL,
+                                          SECRET_SERVICE_OPEN_SESSION, NULL, &error);
        g_assert_no_error (error);
        g_assert (SECRET_IS_SERVICE (service));
 
@@ -353,7 +360,8 @@ test_new_more_async (Test *test,
        const gchar *path;
        GList *collections;
 
-       secret_service_new (NULL, SECRET_SERVICE_LOAD_COLLECTIONS | SECRET_SERVICE_OPEN_SESSION, NULL, on_complete_get_result, &result);
+       secret_service_new (SECRET_TYPE_SERVICE, NULL,
+                           SECRET_SERVICE_LOAD_COLLECTIONS | SECRET_SERVICE_OPEN_SESSION, NULL, on_complete_get_result, &result);
        g_assert (result == NULL);
 
        egg_test_wait ();
@@ -376,7 +384,8 @@ test_new_more_async (Test *test,
 
        /* Now get a session with just collections */
 
-       secret_service_new (NULL, SECRET_SERVICE_LOAD_COLLECTIONS, NULL, on_complete_get_result, &result);
+       secret_service_new (SECRET_TYPE_SERVICE, NULL, SECRET_SERVICE_LOAD_COLLECTIONS,
+                           NULL, on_complete_get_result, &result);
        g_assert (result == NULL);
 
        egg_test_wait ();
@@ -462,7 +471,8 @@ test_ensure_sync (Test *test,
        gboolean ret;
 
        /* Passing true, ensures session is established */
-       service = secret_service_new_sync (NULL, SECRET_SERVICE_NONE, NULL, &error);
+       service = secret_service_new_sync (SECRET_TYPE_SERVICE, NULL,
+                                          SECRET_SERVICE_NONE, NULL, &error);
        g_assert_no_error (error);
        g_assert (service != NULL);
 
@@ -499,7 +509,8 @@ test_ensure_async (Test *test,
        gboolean ret;
 
        /* Passing true, ensures session is established */
-       service = secret_service_new_sync (NULL, SECRET_SERVICE_NONE, NULL, &error);
+       service = secret_service_new_sync (SECRET_TYPE_SERVICE, NULL,
+                                          SECRET_SERVICE_NONE, NULL, &error);
        g_assert_no_error (error);
        g_assert (service != NULL);