[gnome-online-accounts] Ensure that the extension point is registered before implementing it



commit 3e574a83b75965e6ddbbb4acfcf9e1791643b5c3
Author: Debarshi Ray <debarshir gnome org>
Date:   Wed Feb 6 13:53:10 2013 +0100

    Ensure that the extension point is registered before implementing it
    
    This silences the following GLib-GIO-WARNING warning:
    Tried to implement non-registered extension point goa-backend-provider

 src/goabackend/Makefile.am              |    2 +-
 src/goabackend/goaexchangeprovider.c    |    2 +
 src/goabackend/goafacebookprovider.c    |    2 +
 src/goabackend/goaflickrprovider.c      |    2 +
 src/goabackend/goagoogleprovider.c      |    2 +
 src/goabackend/goakerberosprovider.c    |    2 +
 src/goabackend/goaowncloudprovider.c    |    2 +
 src/goabackend/goaprovider-priv.h       |   43 +++++++++++++++++++++++++++++++
 src/goabackend/goaprovider.c            |   26 ++++++++++++++----
 src/goabackend/goaprovider.h            |    7 -----
 src/goabackend/goatwitterprovider.c     |    2 +
 src/goabackend/goawindowsliveprovider.c |    2 +
 src/goabackend/goayahooprovider.c       |    2 +
 13 files changed, 82 insertions(+), 14 deletions(-)
---
diff --git a/src/goabackend/Makefile.am b/src/goabackend/Makefile.am
index 6595244..2693559 100644
--- a/src/goabackend/Makefile.am
+++ b/src/goabackend/Makefile.am
@@ -73,7 +73,7 @@ libgoa_backend_1_0_la_SOURCES =						\
 	goaeditablelabel.h		goaeditablelabel.c		\
 	goaewsclient.h			goaewsclient.c			\
 	goahttpclient.h			goahttpclient.c			\
-	goaprovider.h			goaprovider.c			\
+	goaprovider-priv.h		goaprovider.c			\
 	goaexchangeprovider.h		goaexchangeprovider.c		\
 	goalogging.h			goalogging.c			\
 	goaoauthprovider.h		goaoauthprovider.c		\
diff --git a/src/goabackend/goaexchangeprovider.c b/src/goabackend/goaexchangeprovider.c
index eafd8ae..8e912cd 100644
--- a/src/goabackend/goaexchangeprovider.c
+++ b/src/goabackend/goaexchangeprovider.c
@@ -26,6 +26,7 @@
 #include "goaewsclient.h"
 #include "goalogging.h"
 #include "goaprovider.h"
+#include "goaprovider-priv.h"
 #include "goaexchangeprovider.h"
 #include "goaeditablelabel.h"
 #include "goautils.h"
@@ -58,6 +59,7 @@ struct _GoaExchangeProviderClass
  */
 
 G_DEFINE_TYPE_WITH_CODE (GoaExchangeProvider, goa_exchange_provider, GOA_TYPE_PROVIDER,
+                         goa_provider_ensure_extension_points_registered ();
                          g_io_extension_point_implement (GOA_PROVIDER_EXTENSION_POINT_NAME,
 							 g_define_type_id,
 							 "exchange",
diff --git a/src/goabackend/goafacebookprovider.c b/src/goabackend/goafacebookprovider.c
index aadc218..5327df4 100644
--- a/src/goabackend/goafacebookprovider.c
+++ b/src/goabackend/goafacebookprovider.c
@@ -28,6 +28,7 @@
 #include <json-glib/json-glib.h>
 
 #include "goaprovider.h"
+#include "goaprovider-priv.h"
 #include "goaoauth2provider.h"
 #include "goafacebookprovider.h"
 
@@ -59,6 +60,7 @@ struct _GoaFacebookProviderClass
  */
 
 G_DEFINE_TYPE_WITH_CODE (GoaFacebookProvider, goa_facebook_provider, GOA_TYPE_OAUTH2_PROVIDER,
+                         goa_provider_ensure_extension_points_registered ();
                          g_io_extension_point_implement (GOA_PROVIDER_EXTENSION_POINT_NAME,
 							 g_define_type_id,
 							 "facebook",
diff --git a/src/goabackend/goaflickrprovider.c b/src/goabackend/goaflickrprovider.c
index 8d734e9..398ae4b 100644
--- a/src/goabackend/goaflickrprovider.c
+++ b/src/goabackend/goaflickrprovider.c
@@ -29,6 +29,7 @@
 #include <json-glib/json-glib.h>
 
 #include "goaprovider.h"
+#include "goaprovider-priv.h"
 #include "goaoauthprovider.h"
 #include "goaflickrprovider.h"
 
@@ -60,6 +61,7 @@ struct _GoaFlickrProviderClass
  */
 
 G_DEFINE_TYPE_WITH_CODE (GoaFlickrProvider, goa_flickr_provider, GOA_TYPE_OAUTH_PROVIDER,
+                         goa_provider_ensure_extension_points_registered ();
                          g_io_extension_point_implement (GOA_PROVIDER_EXTENSION_POINT_NAME,
 							 g_define_type_id,
 							 "flickr",
diff --git a/src/goabackend/goagoogleprovider.c b/src/goabackend/goagoogleprovider.c
index 088805d..666ba03 100644
--- a/src/goabackend/goagoogleprovider.c
+++ b/src/goabackend/goagoogleprovider.c
@@ -28,6 +28,7 @@
 #include <json-glib/json-glib.h>
 
 #include "goaprovider.h"
+#include "goaprovider-priv.h"
 #include "goaoauth2provider.h"
 #include "goagoogleprovider.h"
 #include "goahttpclient.h"
@@ -61,6 +62,7 @@ struct _GoaGoogleProviderClass
  */
 
 G_DEFINE_TYPE_WITH_CODE (GoaGoogleProvider, goa_google_provider, GOA_TYPE_OAUTH2_PROVIDER,
+                         goa_provider_ensure_extension_points_registered ();
                          g_io_extension_point_implement (GOA_PROVIDER_EXTENSION_POINT_NAME,
 							 g_define_type_id,
 							 "google",
diff --git a/src/goabackend/goakerberosprovider.c b/src/goabackend/goakerberosprovider.c
index 984872e..a212d8f 100644
--- a/src/goabackend/goakerberosprovider.c
+++ b/src/goabackend/goakerberosprovider.c
@@ -27,6 +27,7 @@
 
 #include "goalogging.h"
 #include "goaprovider.h"
+#include "goaprovider-priv.h"
 #include "goakerberosprovider.h"
 #include "goaeditablelabel.h"
 #include "goautils.h"
@@ -68,6 +69,7 @@ struct _GoaKerberosProviderClass
  */
 
 G_DEFINE_TYPE_WITH_CODE (GoaKerberosProvider, goa_kerberos_provider, GOA_TYPE_PROVIDER,
+                         goa_provider_ensure_extension_points_registered ();
                          g_io_extension_point_implement (GOA_PROVIDER_EXTENSION_POINT_NAME,
                                                          g_define_type_id,
                                                          "kerberos",
diff --git a/src/goabackend/goaowncloudprovider.c b/src/goabackend/goaowncloudprovider.c
index 63f9767..ab3897c 100644
--- a/src/goabackend/goaowncloudprovider.c
+++ b/src/goabackend/goaowncloudprovider.c
@@ -27,6 +27,7 @@
 
 #include "goahttpclient.h"
 #include "goaprovider.h"
+#include "goaprovider-priv.h"
 #include "goaowncloudprovider.h"
 #include "goaeditablelabel.h"
 #include "goautils.h"
@@ -59,6 +60,7 @@ struct _GoaOwncloudProviderClass
  */
 
 G_DEFINE_TYPE_WITH_CODE (GoaOwncloudProvider, goa_owncloud_provider, GOA_TYPE_PROVIDER,
+                         goa_provider_ensure_extension_points_registered ();
                          g_io_extension_point_implement (GOA_PROVIDER_EXTENSION_POINT_NAME,
 							 g_define_type_id,
 							 "owncloud",
diff --git a/src/goabackend/goaprovider-priv.h b/src/goabackend/goaprovider-priv.h
new file mode 100644
index 0000000..5ab8bee
--- /dev/null
+++ b/src/goabackend/goaprovider-priv.h
@@ -0,0 +1,43 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/*
+ * Copyright (C) 2013 Red Hat, Inc.
+ *
+ * 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: Debarshi Ray <debarshir gnome org>
+ */
+
+#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_PRIV_H__
+#define __GOA_PROVIDER_PRIV_H__
+
+G_BEGIN_DECLS
+
+/**
+ * GOA_PROVIDER_EXTENSION_POINT_NAME:
+ *
+ * Extension point for #GoaProvider implementations.
+ */
+#define GOA_PROVIDER_EXTENSION_POINT_NAME "goa-backend-provider"
+
+void goa_provider_ensure_extension_points_registered (void);
+
+G_END_DECLS
+
+#endif /* __GOA_PROVIDER_PRIV_H__ */
diff --git a/src/goabackend/goaprovider.c b/src/goabackend/goaprovider.c
index 0b36dfa..b768fb3 100644
--- a/src/goabackend/goaprovider.c
+++ b/src/goabackend/goaprovider.c
@@ -27,6 +27,7 @@
 
 #include "goalogging.h"
 #include "goaprovider.h"
+#include "goaprovider-priv.h"
 #include "goaexchangeprovider.h"
 #include "goagoogleprovider.h"
 #include "goafacebookprovider.h"
@@ -628,19 +629,33 @@ goa_provider_get_credentials_generation_real (GoaProvider *provider)
 
 /* ---------------------------------------------------------------------------------------------------- */
 
-static void
-ensure_ep_and_builtins (void)
+void
+goa_provider_ensure_extension_points_registered (void)
 {
   static gsize once_init_value = 0;
 
   if (g_once_init_enter (&once_init_value))
     {
       GIOExtensionPoint *extension_point;
-      static volatile GType type = 0;
 
       extension_point = g_io_extension_point_register (GOA_PROVIDER_EXTENSION_POINT_NAME);
       g_io_extension_point_set_required_type (extension_point, GOA_TYPE_PROVIDER);
 
+      g_once_init_leave (&once_init_value, 1);
+    }
+}
+
+static void
+ensure_builtins_loaded (void)
+{
+  static gsize once_init_value = 0;
+
+  goa_provider_ensure_extension_points_registered ();
+
+  if (g_once_init_enter (&once_init_value))
+    {
+      static volatile GType type = 0;
+
       /* The order is in which the providers' types are created is
        * important because it affects the order in which they are
        * returned by goa_provider_get_all.
@@ -679,7 +694,6 @@ ensure_ep_and_builtins (void)
     }
 }
 
-
 /* ---------------------------------------------------------------------------------------------------- */
 
 /**
@@ -700,7 +714,7 @@ goa_provider_get_for_provider_type (const gchar *provider_type)
   GIOExtensionPoint *extension_point;
   GoaProvider *ret;
 
-  ensure_ep_and_builtins ();
+  ensure_builtins_loaded ();
 
   ret = NULL;
 
@@ -732,7 +746,7 @@ goa_provider_get_all (void)
   GList *l;
   GIOExtensionPoint *extension_point;
 
-  ensure_ep_and_builtins ();
+  ensure_builtins_loaded ();
 
   ret = NULL;
   extension_point = g_io_extension_point_lookup (GOA_PROVIDER_EXTENSION_POINT_NAME);
diff --git a/src/goabackend/goaprovider.h b/src/goabackend/goaprovider.h
index c96ac4f..cdb081e 100644
--- a/src/goabackend/goaprovider.h
+++ b/src/goabackend/goaprovider.h
@@ -167,13 +167,6 @@ gboolean     goa_provider_ensure_credentials_sync   (GoaProvider         *provid
 guint        goa_provider_get_credentials_generation (GoaProvider        *provider);
 
 
-/**
- * GOA_PROVIDER_EXTENSION_POINT_NAME:
- *
- * Extension point for #GoaProvider implementations.
- */
-#define GOA_PROVIDER_EXTENSION_POINT_NAME "goa-backend-provider"
-
 GList        *goa_provider_get_all (void);
 GoaProvider  *goa_provider_get_for_provider_type (const gchar *provider_type);
 
diff --git a/src/goabackend/goatwitterprovider.c b/src/goabackend/goatwitterprovider.c
index 3895e6f..affba63 100644
--- a/src/goabackend/goatwitterprovider.c
+++ b/src/goabackend/goatwitterprovider.c
@@ -27,6 +27,7 @@
 #include <json-glib/json-glib.h>
 
 #include "goaprovider.h"
+#include "goaprovider-priv.h"
 #include "goaoauthprovider.h"
 #include "goatwitterprovider.h"
 
@@ -58,6 +59,7 @@ struct _GoaTwitterProviderClass
  */
 
 G_DEFINE_TYPE_WITH_CODE (GoaTwitterProvider, goa_twitter_provider, GOA_TYPE_OAUTH_PROVIDER,
+                         goa_provider_ensure_extension_points_registered ();
                          g_io_extension_point_implement (GOA_PROVIDER_EXTENSION_POINT_NAME,
 							 g_define_type_id,
 							 "twitter",
diff --git a/src/goabackend/goawindowsliveprovider.c b/src/goabackend/goawindowsliveprovider.c
index ad50256..fd4299b 100644
--- a/src/goabackend/goawindowsliveprovider.c
+++ b/src/goabackend/goawindowsliveprovider.c
@@ -30,6 +30,7 @@
 #include <webkit/webkit.h>
 
 #include "goaprovider.h"
+#include "goaprovider-priv.h"
 #include "goaoauth2provider.h"
 #include "goawindowsliveprovider.h"
 
@@ -61,6 +62,7 @@ struct _GoaWindowsLiveProviderClass
  */
 
 G_DEFINE_TYPE_WITH_CODE (GoaWindowsLiveProvider, goa_windows_live_provider, GOA_TYPE_OAUTH2_PROVIDER,
+                         goa_provider_ensure_extension_points_registered ();
                          g_io_extension_point_implement (GOA_PROVIDER_EXTENSION_POINT_NAME,
 							 g_define_type_id,
 							 "windows_live",
diff --git a/src/goabackend/goayahooprovider.c b/src/goabackend/goayahooprovider.c
index dc6d011..e0ce7db 100644
--- a/src/goabackend/goayahooprovider.c
+++ b/src/goabackend/goayahooprovider.c
@@ -27,6 +27,7 @@
 #include <json-glib/json-glib.h>
 
 #include "goaprovider.h"
+#include "goaprovider-priv.h"
 #include "goaoauthprovider.h"
 #include "goayahooprovider.h"
 
@@ -58,6 +59,7 @@ struct _GoaYahooProviderClass
  */
 
 G_DEFINE_TYPE_WITH_CODE (GoaYahooProvider, goa_yahoo_provider, GOA_TYPE_OAUTH_PROVIDER,
+                         goa_provider_ensure_extension_points_registered ();
                          g_io_extension_point_implement (GOA_PROVIDER_EXTENSION_POINT_NAME,
 							 g_define_type_id,
 							 "yahoo",


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