[evolution-data-server] EBackend: Add authenticate() sync+async methods.
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server] EBackend: Add authenticate() sync+async methods.
- Date: Tue, 31 Jul 2012 23:18:01 +0000 (UTC)
commit 13db1835e679d6dd3e267e0b0fde2c6eede1796b
Author: Matthew Barnes <mbarnes redhat com>
Date: Tue Jul 31 17:32:10 2012 -0400
EBackend: Add authenticate() sync+async methods.
These are convenience functions providing a consistent interface for
backends running in either the registry service itself or a client
process communicating with the registry service over D-Bus.
Dynamically loaded backend classes need not implement these methods.
They will inherit a suitable method implementation from ECalBackend,
EBookBackend or ECollectionBackend.
.../reference/libebackend/libebackend-sections.txt | 3 +
libebackend/e-backend.c | 210 ++++++++++++++++++++
libebackend/e-backend.h | 28 +++-
3 files changed, 240 insertions(+), 1 deletions(-)
---
diff --git a/docs/reference/libebackend/libebackend-sections.txt b/docs/reference/libebackend/libebackend-sections.txt
index b9a34b7..c4c03cb 100644
--- a/docs/reference/libebackend/libebackend-sections.txt
+++ b/docs/reference/libebackend/libebackend-sections.txt
@@ -76,6 +76,9 @@ EBackend
e_backend_get_online
e_backend_set_online
e_backend_get_source
+e_backend_authenticate_sync
+e_backend_authenticate
+e_backend_authenticate_finish
<SUBSECTION Standard>
E_BACKEND
E_IS_BACKEND
diff --git a/libebackend/e-backend.c b/libebackend/e-backend.c
index 00ab0f6..d24ba37 100644
--- a/libebackend/e-backend.c
+++ b/libebackend/e-backend.c
@@ -34,17 +34,25 @@
#include "e-backend.h"
#include <config.h>
+#include <glib/gi18n-lib.h>
+
#include <gio/gio.h>
#define E_BACKEND_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE \
((obj), E_TYPE_BACKEND, EBackendPrivate))
+typedef struct _AsyncContext AsyncContext;
+
struct _EBackendPrivate {
ESource *source;
gboolean online;
};
+struct _AsyncContext {
+ ESourceAuthenticator *auth;
+};
+
enum {
PROP_0,
PROP_ONLINE,
@@ -54,6 +62,15 @@ enum {
G_DEFINE_ABSTRACT_TYPE (EBackend, e_backend, G_TYPE_OBJECT)
static void
+async_context_free (AsyncContext *async_context)
+{
+ if (async_context->auth != NULL)
+ g_object_unref (async_context->auth);
+
+ g_slice_free (AsyncContext, async_context);
+}
+
+static void
backend_set_source (EBackend *backend,
ESource *source)
{
@@ -144,6 +161,86 @@ backend_constructed (GObject *object)
}
static void
+backend_authenticate_thread (GSimpleAsyncResult *simple,
+ GObject *object,
+ GCancellable *cancellable)
+{
+ AsyncContext *async_context;
+ GError *error = NULL;
+
+ async_context = g_simple_async_result_get_op_res_gpointer (simple);
+
+ e_backend_authenticate_sync (
+ E_BACKEND (object),
+ async_context->auth,
+ cancellable, &error);
+
+ if (error != NULL)
+ g_simple_async_result_take_error (simple, error);
+}
+
+static gboolean
+backend_authenticate_sync (EBackend *backend,
+ ESourceAuthenticator *auth,
+ GCancellable *cancellable,
+ GError **error)
+{
+ g_set_error (
+ error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
+ _("%s does not support authentication"),
+ G_OBJECT_TYPE_NAME (backend));
+
+ return FALSE;
+}
+
+static void
+backend_authenticate (EBackend *backend,
+ ESourceAuthenticator *auth,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GSimpleAsyncResult *simple;
+ AsyncContext *async_context;
+
+ async_context = g_slice_new0 (AsyncContext);
+ async_context->auth = g_object_ref (auth);
+
+ simple = g_simple_async_result_new (
+ G_OBJECT (backend), callback,
+ user_data, backend_authenticate);
+
+ g_simple_async_result_set_check_cancellable (simple, cancellable);
+
+ g_simple_async_result_set_op_res_gpointer (
+ simple, async_context, (GDestroyNotify) async_context_free);
+
+ g_simple_async_result_run_in_thread (
+ simple, backend_authenticate_thread,
+ G_PRIORITY_DEFAULT, cancellable);
+
+ g_object_unref (simple);
+}
+
+static gboolean
+backend_authenticate_finish (EBackend *backend,
+ GAsyncResult *result,
+ GError **error)
+{
+ GSimpleAsyncResult *simple;
+
+ g_return_val_if_fail (
+ g_simple_async_result_is_valid (
+ result, G_OBJECT (backend),
+ backend_authenticate), FALSE);
+
+ simple = G_SIMPLE_ASYNC_RESULT (result);
+
+ /* Assume success unless a GError is set. */
+ return !g_simple_async_result_propagate_error (simple, error);
+}
+
+static void
e_backend_class_init (EBackendClass *class)
{
GObjectClass *object_class;
@@ -156,6 +253,10 @@ e_backend_class_init (EBackendClass *class)
object_class->dispose = backend_dispose;
object_class->constructed = backend_constructed;
+ class->authenticate_sync = backend_authenticate_sync;
+ class->authenticate = backend_authenticate;
+ class->authenticate_finish = backend_authenticate_finish;
+
g_object_class_install_property (
object_class,
PROP_ONLINE,
@@ -251,3 +352,112 @@ e_backend_get_source (EBackend *backend)
return backend->priv->source;
}
+/**
+ * e_backend_authenticate_sync:
+ * @backend: an #EBackend
+ * @auth: an #ESourceAuthenticator
+ * @cancellable: optional #GCancellable object, or %NULL
+ * @error: return location for a #GError, or %NULL
+ *
+ * Convenience function providing a consistent authentication interface
+ * for backends running in either the registry service itself or a client
+ * process communicating with the registry service over D-Bus.
+ *
+ * Authenticates @backend's #EBackend:source, using @auth to handle
+ * authentication attempts. The @backend and @auth arguments may be one
+ * and the same if @backend implements the #ESourceAuthenticator interface.
+ * The operation loops until authentication is successful or the user aborts
+ * further authentication attempts. If an error occurs, the function will
+ * set @error and return %FALSE.
+ *
+ * Returns: %TRUE on success, %FALSE on failure
+ *
+ * Since: 3.6
+ **/
+gboolean
+e_backend_authenticate_sync (EBackend *backend,
+ ESourceAuthenticator *auth,
+ GCancellable *cancellable,
+ GError **error)
+{
+ EBackendClass *class;
+
+ g_return_val_if_fail (E_IS_BACKEND (backend), FALSE);
+ g_return_val_if_fail (E_IS_SOURCE_AUTHENTICATOR (auth), FALSE);
+
+ class = E_BACKEND_GET_CLASS (backend);
+ g_return_val_if_fail (class->authenticate_sync != NULL, FALSE);
+
+ return class->authenticate_sync (backend, auth, cancellable, error);
+}
+
+/**
+ * e_backend_authenticate:
+ * @backend: an #EBackend
+ * @auth: an #ESourceAuthenticator
+ * @cancellable: optional #GCancellable object, or %NULL
+ * @callback: a #GAsyncReadyCallback to call when the request is satisfied
+ * @user_data: data to pass to the callback function
+ *
+ * Convenience function providing a consistent authentication interface
+ * for backends running in either the registry service itself or a client
+ * process communicating with the registry service over D-Bus.
+ *
+ * Asynchronously authenticates @backend's #EBackend:source, using @auth
+ * to handle authentication attempts. The @backend and @auth arguments may
+ * be one and the same if @backend implements the #ESourceAuthenticator
+ * interface. The operation loops until authentication is succesful or the
+ * user aborts further authentication attempts.
+ *
+ * When the operation is finished, @callback will be called. You can then
+ * call e_backend_authenticate_finish() to get the result of the operation.
+ *
+ * Since: 3.6
+ **/
+void
+e_backend_authenticate (EBackend *backend,
+ ESourceAuthenticator *auth,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ EBackendClass *class;
+
+ g_return_if_fail (E_IS_BACKEND (backend));
+ g_return_if_fail (E_IS_SOURCE_AUTHENTICATOR (auth));
+
+ class = E_BACKEND_GET_CLASS (backend);
+ g_return_if_fail (class->authenticate != NULL);
+
+ class->authenticate (backend, auth, cancellable, callback, user_data);
+}
+
+/**
+ * e_backend_authenticate_finish:
+ * @backend: an #EBackend
+ * @result: a #GAsyncResult
+ * @error: return location for a #GError, or %NULL
+ *
+ * Finishes the operation started with e_backend_authenticate(). If
+ * an error occurred, the function will set @error and return %FALSE.
+ *
+ * Returns: %TRUE on success, %FALSE on failure
+ *
+ * Since: 3.6
+ **/
+gboolean
+e_backend_authenticate_finish (EBackend *backend,
+ GAsyncResult *result,
+ GError **error)
+{
+ EBackendClass *class;
+
+ g_return_val_if_fail (E_IS_BACKEND (backend), FALSE);
+ g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
+
+ class = E_BACKEND_GET_CLASS (backend);
+ g_return_val_if_fail (class->authenticate_finish != NULL, FALSE);
+
+ return class->authenticate_finish (backend, result, error);
+}
+
diff --git a/libebackend/e-backend.h b/libebackend/e-backend.h
index 7b1ed9c..30b697e 100644
--- a/libebackend/e-backend.h
+++ b/libebackend/e-backend.h
@@ -66,7 +66,21 @@ struct _EBackend {
struct _EBackendClass {
GObjectClass parent_class;
- gpointer reserved[16];
+ /* Methods */
+ gboolean (*authenticate_sync) (EBackend *backend,
+ ESourceAuthenticator *auth,
+ GCancellable *cancellable,
+ GError **error);
+ void (*authenticate) (EBackend *backend,
+ ESourceAuthenticator *auth,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+ gboolean (*authenticate_finish) (EBackend *backend,
+ GAsyncResult *result,
+ GError **error);
+
+ gpointer reserved[13];
};
GType e_backend_get_type (void) G_GNUC_CONST;
@@ -74,6 +88,18 @@ gboolean e_backend_get_online (EBackend *backend);
void e_backend_set_online (EBackend *backend,
gboolean online);
ESource * e_backend_get_source (EBackend *backend);
+gboolean e_backend_authenticate_sync (EBackend *backend,
+ ESourceAuthenticator *auth,
+ GCancellable *cancellable,
+ GError **error);
+void e_backend_authenticate (EBackend *backend,
+ ESourceAuthenticator *auth,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+gboolean e_backend_authenticate_finish (EBackend *backend,
+ GAsyncResult *result,
+ GError **error);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]