[gnome-online-accounts] providerfactory: add abstract class to create providers dynamically
- From: Marco Barisione <mbari src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-online-accounts] providerfactory: add abstract class to create providers dynamically
- Date: Thu, 22 Aug 2013 14:17:44 +0000 (UTC)
commit faf55197d814d6385904dfb84adf0988efd6c926
Author: Marco Barisione <marco barisione collabora co uk>
Date: Wed Jul 24 15:32:59 2013 +0100
providerfactory: add abstract class to create providers dynamically
https://bugzilla.gnome.org/show_bug.cgi?id=696267
src/goabackend/Makefile.am | 1 +
src/goabackend/goaproviderfactory.c | 159 +++++++++++++++++++++++++++++++++++
src/goabackend/goaproviderfactory.h | 101 ++++++++++++++++++++++
3 files changed, 261 insertions(+), 0 deletions(-)
---
diff --git a/src/goabackend/Makefile.am b/src/goabackend/Makefile.am
index 37dd9e4..4049799 100644
--- a/src/goabackend/Makefile.am
+++ b/src/goabackend/Makefile.am
@@ -61,6 +61,7 @@ libgoa_backend_1_0_la_SOURCES = \
goaewsclient.h goaewsclient.c \
goahttpclient.h goahttpclient.c \
goaprovider-priv.h goaprovider.c \
+ goaproviderfactory.h goaproviderfactory.c \
goamailauth.h goamailauth.c \
goaimapauthlogin.h goaimapauthlogin.c \
goasmtpauthplain.h goasmtpauthplain.c \
diff --git a/src/goabackend/goaproviderfactory.c b/src/goabackend/goaproviderfactory.c
new file mode 100644
index 0000000..883e1ef
--- /dev/null
+++ b/src/goabackend/goaproviderfactory.c
@@ -0,0 +1,159 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/*
+ * Copyright (C) 2013 Intel Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: Marco Barisione <marco barisione collabora co uk>
+ */
+
+#include "config.h"
+
+#include "goaproviderfactory.h"
+
+/**
+ * SECTION:goaproviderfactory
+ * @title: GoaProviderFactory
+ * @short_description: Abstract base class for provider factories
+ *
+ * #GoaProviderFactory implementations are used to dynamically create #GoaProvider instances.
+ */
+
+G_DEFINE_ABSTRACT_TYPE (GoaProviderFactory, goa_provider_factory, G_TYPE_OBJECT);
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+/**
+ * goa_provider_factory_get_provider:
+ *
+ * Create a dynamic #GoaProvider for @provider_type.
+ *
+ * Returns: (transfer full): A #GoaProvider (that must be freed
+ * with g_object_unref()) or %NULL if not found.
+ */
+GoaProvider *
+goa_provider_factory_get_provider (GoaProviderFactory *factory,
+ const gchar *provider_type)
+{
+ GoaProviderFactoryClass *klass;
+
+ g_return_val_if_fail (GOA_IS_PROVIDER_FACTORY (factory), NULL);
+ g_return_val_if_fail (provider_type != NULL, NULL);
+
+ klass = GOA_PROVIDER_FACTORY_GET_CLASS (factory);
+ g_return_val_if_fail (klass->get_provider != NULL, NULL);
+
+ return klass->get_provider (factory, provider_type);
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+/**
+ * goa_provider_factory_get_providers:
+ * @factory: A #GoaProviderFactory.
+ * @callback: The function to call when the request is satisfied.
+ * @user_data: Pointer to pass to @callback.
+ *
+ * Get asynchronously a list of #GoaProvider instances handled by @factory.
+ *
+ * When the result is ready, @callback will be called in the the <link
+ * linkend="g-main-context-push-thread-default">thread-default main
+ * loop</link> this function was called from. You can then call
+ * goa_provider_factory_get_providers_finish() to get the result
+ * of the operation.
+ *
+ * This is a virtual method that must be implemented by subclasses.
+ */
+void
+goa_provider_factory_get_providers (GoaProviderFactory *factory,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GoaProviderFactoryClass *klass;
+
+ g_return_if_fail (GOA_IS_PROVIDER_FACTORY (factory));
+
+ klass = GOA_PROVIDER_FACTORY_GET_CLASS (factory);
+ g_return_if_fail (klass->get_providers != NULL);
+
+ return klass->get_providers (factory, callback, user_data);
+}
+
+/**
+ * goa_provider_factory_get_providers_finish:
+ * @factory: A #GoaProviderFactory.
+ * @out_providers: (out): Return location for a list of #GoaProvider instances handled by @factory.
+ * @res: A #GAsyncResult obtained from the #GAsyncReadyCallback passed to
goa_provider_factory_get_providers().
+ * @error: Return location for error or %NULL.
+ *
+ * Finishes an operation started with goa_provider_factory_get_providers()
+ *
+ * This is a virtual method that subclasses may implement. The default implementation is suitable for
+ * #GSimpleAsyncResult an implementation of goa_provider_factory_get_providers() using #GSimpleAsyncResult.
+ *
+ * Returns: %TRUE if the list was successfully retrieved, %FALSE if @error is set.
+ */
+gboolean
+goa_provider_factory_get_providers_finish (GoaProviderFactory *factory,
+ GList **out_providers,
+ GAsyncResult *result,
+ GError **error)
+{
+ GoaProviderFactoryClass *klass;
+
+ g_return_if_fail (GOA_IS_PROVIDER_FACTORY (factory));
+
+ klass = GOA_PROVIDER_FACTORY_GET_CLASS (factory);
+ return klass->get_providers_finish (factory, out_providers, result, error);
+}
+
+static gboolean
+get_providers_finish_default (GoaProviderFactory *factory,
+ GList **out_providers,
+ GAsyncResult *result,
+ GError **error)
+{
+
+ GSimpleAsyncResult *simple = (GSimpleAsyncResult *) result;
+ GList *providers;
+
+ g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (factory), NULL),
+ NULL);
+
+ if (g_simple_async_result_propagate_error (simple, error))
+ return FALSE;
+
+ if (out_providers != NULL)
+ {
+ providers = g_simple_async_result_get_op_res_gpointer (simple);
+ *out_providers = g_list_copy_deep (providers, (GCopyFunc) g_object_ref, NULL);
+ }
+
+ return TRUE;
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+static void
+goa_provider_factory_init (GoaProviderFactory *provider)
+{
+}
+
+static void
+goa_provider_factory_class_init (GoaProviderFactoryClass *klass)
+{
+ klass->get_providers_finish = get_providers_finish_default;
+}
diff --git a/src/goabackend/goaproviderfactory.h b/src/goabackend/goaproviderfactory.h
new file mode 100644
index 0000000..df54d44
--- /dev/null
+++ b/src/goabackend/goaproviderfactory.h
@@ -0,0 +1,101 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/*
+ * Copyright (C) 2013 Intel Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: Marco Barisione <marco barisione collabora co uk>
+ */
+
+#if !defined (__GOA_BACKEND_INSIDE_GOA_BACKEND_H__) && !defined (GOA_BACKEND_COMPILATION)
+#error "Only <goabackend/goabackend.h> can be included directly."
+#endif
+
+#ifndef __GOA_PROVIDER_FACTORY_H__
+#define __GOA_PROVIDER_FACTORY_H__
+
+#include <gio/gio.h>
+
+#include "goaprovider.h"
+
+G_BEGIN_DECLS
+
+#define GOA_TYPE_PROVIDER_FACTORY (goa_provider_factory_get_type ())
+#define GOA_PROVIDER_FACTORY(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GOA_TYPE_PROVIDER_FACTORY,
GoaProviderFactory))
+#define GOA_PROVIDER_FACTORY_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GOA_TYPE_PROVIDER_FACTORY,
GoaProviderFactoryClass))
+#define GOA_PROVIDER_FACTORY_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GOA_TYPE_PROVIDER_FACTORY,
GoaProviderFactoryClass))
+#define GOA_IS_PROVIDER_FACTORY(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GOA_TYPE_PROVIDER_FACTORY))
+#define GOA_IS_PROVIDER_FACTORY_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GOA_TYPE_PROVIDER_FACTORY))
+
+typedef struct _GoaProviderFactory GoaProviderFactory;
+typedef struct _GoaProviderFactoryClass GoaProviderFactoryClass;
+
+/**
+ * GoaProviderFactory:
+ *
+ * The #GoaProviderFactory structure contains only private data and should
+ * only be accessed using the provided API.
+ */
+struct _GoaProviderFactory
+{
+ /*< private >*/
+ GObject parent_instance;
+};
+
+/**
+ * GoaProviderFactoryClass:
+ * @parent_class: The parent class.
+ * @get_provider: Virtual function for goa_provider_factory_get_provider().
+ * @get_providers: Virtual function for goa_provider_factory_get_providers().
+ * @get_providers_finish: Virtual function for goa_provider_factory_get_providers_finish().
+ *
+ * Class structure for #GoaProviderFactory.
+ */
+struct _GoaProviderFactoryClass
+{
+ GObjectClass parent_class;
+
+ /* Mandatory to implement. */
+ GoaProvider *(*get_provider) (GoaProviderFactory *factory,
+ const gchar *provider_name);
+
+ /* The async method is mandatory to implement, but _finish has a default
+ * implementation suitable for a GSimpleAsyncResult. */
+ void (*get_providers) (GoaProviderFactory *factory,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+ gboolean (*get_providers_finish) (GoaProviderFactory *factory,
+ GList **out_providers,
+ GAsyncResult *result,
+ GError **error);
+};
+
+GType goa_provider_factory_get_type (void) G_GNUC_CONST;
+
+GoaProvider *goa_provider_factory_get_provider (GoaProviderFactory *factory,
+ const gchar *provider_name);
+
+void goa_provider_factory_get_providers (GoaProviderFactory *factory,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+gboolean goa_provider_factory_get_providers_finish (GoaProviderFactory *factory,
+ GList **out_providers,
+ GAsyncResult *result,
+ GError **error);
+
+G_END_DECLS
+
+#endif /* __GOA_PROVIDER_FACTORY_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]