[gnome-online-accounts/gnome-3-20] telepathy: Implement GoaProvider:initialize to start the linker



commit 710036061321260bc2909def1a57f5c795197dfd
Author: Debarshi Ray <debarshir gnome org>
Date:   Thu May 26 19:31:28 2016 +0200

    telepathy: Implement GoaProvider:initialize to start the linker
    
    ... instead of starting it from goa-daemon.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=766733

 src/daemon/Makefile.am                          |    8 -----
 src/daemon/main.c                               |   16 ---------
 src/goabackend/Makefile.am                      |    1 +
 src/goabackend/goatelepathyprovider.c           |   39 +++++++++++++++++++++++
 src/{daemon => goabackend}/goatpaccountlinker.c |    0
 src/{daemon => goabackend}/goatpaccountlinker.h |    0
 6 files changed, 40 insertions(+), 24 deletions(-)
---
diff --git a/src/daemon/Makefile.am b/src/daemon/Makefile.am
index 2c09cdc..b318b6a 100644
--- a/src/daemon/Makefile.am
+++ b/src/daemon/Makefile.am
@@ -31,17 +31,10 @@ goa_daemon_SOURCES =                                                \
        goadaemon.h             goadaemon.c                     \
        $(NULL)
 
-if BUILD_TELEPATHY
-goa_daemon_SOURCES +=                                          \
-       goatpaccountlinker.h    goatpaccountlinker.c            \
-       $(NULL)
-endif
-
 goa_daemon_CFLAGS =                                            \
        $(GLIB_CFLAGS)                                          \
        $(GTK_CFLAGS)                                           \
        $(REST_CFLAGS)                                          \
-       $(TP_CFLAGS)                                            \
        $(NULL)
 
 goa_daemon_LDADD =                                             \
@@ -50,7 +43,6 @@ goa_daemon_LDADD =                                            \
        $(top_builddir)/src/goabackend/libgoa-backend-1.0.la    \
        $(GTK_LIBS)                                             \
        $(REST_LIBS)                                            \
-       $(TP_LIBS)                                              \
        $(NULL)
 
 clean-local :
diff --git a/src/daemon/main.c b/src/daemon/main.c
index 11fbbb1..85fd351 100644
--- a/src/daemon/main.c
+++ b/src/daemon/main.c
@@ -26,11 +26,6 @@
 
 #include "goadaemon.h"
 
-#ifdef GOA_TELEPATHY_ENABLED
-#include "goatpaccountlinker.h"
-#endif
-
-
 /* ---------------------------------------------------------------------------------------------------- */
 
 static GMainLoop *loop = NULL;
@@ -44,10 +39,6 @@ static GOptionEntry opt_entries[] =
 };
 static GoaDaemon *the_daemon = NULL;
 
-#ifdef GOA_TELEPATHY_ENABLED
-static GoaTpAccountLinker *tp_linker = NULL;
-#endif
-
 static void
 on_bus_acquired (GDBusConnection *connection,
                  const gchar     *name,
@@ -73,10 +64,6 @@ on_name_acquired (GDBusConnection *connection,
                   gpointer         user_data)
 {
   g_debug ("Acquired the name %s on the session message bus", name);
-
-#ifdef GOA_TELEPATHY_ENABLED
-  tp_linker = goa_tp_account_linker_new ();
-#endif
 }
 
 static gboolean
@@ -138,9 +125,6 @@ main (int    argc,
 
  out:
   g_clear_object (&the_daemon);
-#ifdef GOA_TELEPATHY_ENABLED
-  g_clear_object (&tp_linker);
-#endif
   if (name_owner_id != 0)
     g_bus_unown_name (name_owner_id);
   g_clear_pointer (&loop, (GDestroyNotify) g_main_loop_unref);
diff --git a/src/goabackend/Makefile.am b/src/goabackend/Makefile.am
index 22c271a..81029b8 100644
--- a/src/goabackend/Makefile.am
+++ b/src/goabackend/Makefile.am
@@ -109,6 +109,7 @@ if BUILD_TELEPATHY
 libgoa_backend_1_0_la_SOURCES +=                                       \
        goatelepathyfactory.h           goatelepathyfactory.c           \
        goatelepathyprovider.h          goatelepathyprovider.c          \
+       goatpaccountlinker.h            goatpaccountlinker.c            \
        $(NULL)
 endif
 
diff --git a/src/goabackend/goatelepathyprovider.c b/src/goabackend/goatelepathyprovider.c
index 2bcd947..df03f4d 100644
--- a/src/goabackend/goatelepathyprovider.c
+++ b/src/goabackend/goatelepathyprovider.c
@@ -26,6 +26,7 @@
 #include "goaprovider.h"
 #include "goaprovider-priv.h"
 #include "goatelepathyprovider.h"
+#include "goatpaccountlinker.h"
 #include "goaobjectskeletonutils.h"
 #include "goautils.h"
 
@@ -79,6 +80,11 @@ G_DEFINE_TYPE (GoaTelepathyProvider, goa_telepathy_provider, GOA_TYPE_PROVIDER);
 
 /* ---------------------------------------------------------------------------------------------------- */
 
+static GoaTpAccountLinker *tp_linker = NULL;
+static guint name_watcher_id = 0;
+
+/* ---------------------------------------------------------------------------------------------------- */
+
 /* Telepathy / telepathy-account widgets utility functions. */
 
 static void
@@ -267,6 +273,38 @@ get_provider_features (GoaProvider *provider)
 
 /* ---------------------------------------------------------------------------------------------------- */
 
+static void
+on_name_acquired (GDBusConnection *connection,
+                  const gchar     *name,
+                  const gchar     *name_owner,
+                  gpointer         user_data)
+{
+  tp_linker = goa_tp_account_linker_new ();
+  g_bus_unwatch_name (name_watcher_id);
+  name_watcher_id = 0;
+}
+
+static void
+initialize (GoaProvider *provider)
+{
+  static gsize once_init_value = 0;
+
+  if (g_once_init_enter (&once_init_value))
+    {
+      name_watcher_id = g_bus_watch_name (G_BUS_TYPE_SESSION,
+                                          "org.gnome.OnlineAccounts",
+                                          G_BUS_NAME_WATCHER_FLAGS_NONE,
+                                          on_name_acquired,
+                                          NULL,
+                                          NULL,
+                                          NULL);
+
+      g_once_init_leave (&once_init_value, 1);
+    }
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
 typedef struct
 {
   GMainLoop *loop;
@@ -1022,6 +1060,7 @@ goa_telepathy_provider_class_init (GoaTelepathyProviderClass *klass)
   provider_class->get_provider_icon     = get_provider_icon;
   provider_class->get_provider_group    = get_provider_group;
   provider_class->get_provider_features = get_provider_features;
+  provider_class->initialize            = initialize;
   provider_class->add_account           = add_account;
   provider_class->refresh_account       = refresh_account;
   provider_class->build_object          = build_object;
diff --git a/src/daemon/goatpaccountlinker.c b/src/goabackend/goatpaccountlinker.c
similarity index 100%
rename from src/daemon/goatpaccountlinker.c
rename to src/goabackend/goatpaccountlinker.c
diff --git a/src/daemon/goatpaccountlinker.h b/src/goabackend/goatpaccountlinker.h
similarity index 100%
rename from src/daemon/goatpaccountlinker.h
rename to src/goabackend/goatpaccountlinker.h


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