[Telepathy-commits] [telepathy-gabble/master] GabbleImFactory: instead of using TpChannelFactoryIface's connecting/connected/disconnected callbacks, just bind to status-changed directly

Simon McVittie simon.mcvittie at collabora.co.uk
Wed Aug 20 09:38:29 PDT 2008


20080728154033-53eee-74ad32313b22bfb16d87e73e999ab0524a392e7c.gz
---
 src/im-factory.c |   83 ++++++++++++++++++++++++++----------------------------
 1 files changed, 40 insertions(+), 43 deletions(-)

diff --git a/src/im-factory.c b/src/im-factory.c
index 7e514f2..340e8a7 100644
--- a/src/im-factory.c
+++ b/src/im-factory.c
@@ -84,16 +84,23 @@ gabble_im_factory_init (GabbleImFactory *self)
   self->priv->dispose_has_run = FALSE;
 }
 
+
+static void connection_status_changed_cb (GabbleConnection *conn,
+    guint status, guint reason, GabbleImFactory *self);
+
+
 static GObject *
 gabble_im_factory_constructor (GType type, guint n_props,
                                GObjectConstructParam *props)
 {
-  GObject *obj;
-  /* GabbleImFactoryPrivate *priv; */
-
-  obj = G_OBJECT_CLASS (gabble_im_factory_parent_class)->
+  GObject *obj = G_OBJECT_CLASS (gabble_im_factory_parent_class)->
            constructor (type, n_props, props);
-  /* priv = GABBLE_IM_FACTORY_GET_PRIVATE (obj); */
+  GabbleImFactory *self = GABBLE_IM_FACTORY (obj);
+
+  /* conn is guaranteed to live longer than the GabbleImFactory, so this
+   * never needs disconnecting */
+  g_signal_connect (self->priv->conn, "status-changed",
+      (GCallback) connection_status_changed_cb, obj);
 
   return obj;
 }
@@ -406,44 +413,37 @@ gabble_im_factory_iface_close_all (TpChannelFactoryIface *iface)
     }
 }
 
-static void
-gabble_im_factory_iface_connecting (TpChannelFactoryIface *iface)
-{
-  GabbleImFactory *fac = GABBLE_IM_FACTORY (iface);
-  GabbleImFactoryPrivate *priv = GABBLE_IM_FACTORY_GET_PRIVATE (fac);
-
-  DEBUG ("adding callbacks");
-
-  g_assert (priv->message_cb == NULL);
-
-  priv->message_cb = lm_message_handler_new (im_factory_message_cb, fac, NULL);
-  lm_connection_register_message_handler (priv->conn->lmconn, priv->message_cb,
-                                          LM_MESSAGE_TYPE_MESSAGE,
-                                          LM_HANDLER_PRIORITY_LAST);
-}
-
-
 
 static void
-gabble_im_factory_iface_connected (TpChannelFactoryIface *iface)
+connection_status_changed_cb (GabbleConnection *conn,
+                              guint status,
+                              guint reason,
+                              GabbleImFactory *self)
 {
-  /* nothing to do */
-}
-
-static void
-gabble_im_factory_iface_disconnected (TpChannelFactoryIface *iface)
-{
-  GabbleImFactory *fac = GABBLE_IM_FACTORY (iface);
-  GabbleImFactoryPrivate *priv = GABBLE_IM_FACTORY_GET_PRIVATE (fac);
-
-  DEBUG ("removing callbacks");
-
-  g_assert (priv->message_cb != NULL);
-
-  lm_connection_unregister_message_handler (priv->conn->lmconn,
-      priv->message_cb, LM_MESSAGE_TYPE_MESSAGE);
-  lm_message_handler_unref (priv->message_cb);
-  priv->message_cb = NULL;
+  if (status == TP_CONNECTION_STATUS_CONNECTING)
+    {
+      DEBUG ("adding callbacks");
+      g_assert (self->priv->message_cb == NULL);
+
+      self->priv->message_cb = lm_message_handler_new (im_factory_message_cb,
+          self, NULL);
+      lm_connection_register_message_handler (self->priv->conn->lmconn,
+          self->priv->message_cb, LM_MESSAGE_TYPE_MESSAGE,
+          LM_HANDLER_PRIORITY_LAST);
+    }
+  else if (status == TP_CONNECTION_STATUS_DISCONNECTED)
+    {
+      /* this can be called before we have ever been CONNECTING, so we need
+       * to guard it */
+      if (self->priv->message_cb != NULL)
+        {
+          DEBUG ("removing callbacks");
+          lm_connection_unregister_message_handler (self->priv->conn->lmconn,
+              self->priv->message_cb, LM_MESSAGE_TYPE_MESSAGE);
+          lm_message_handler_unref (self->priv->message_cb);
+          self->priv->message_cb = NULL;
+        }
+    }
 }
 
 
@@ -527,9 +527,6 @@ gabble_im_factory_iface_init (gpointer g_iface,
   TpChannelFactoryIfaceClass *klass = (TpChannelFactoryIfaceClass *) g_iface;
 
   klass->close_all = gabble_im_factory_iface_close_all;
-  klass->connecting = gabble_im_factory_iface_connecting;
-  klass->connected = gabble_im_factory_iface_connected;
-  klass->disconnected = gabble_im_factory_iface_disconnected;
   klass->request = gabble_im_factory_iface_request;
 
   /* this function is basically the same for channel factory and channel
-- 
1.5.6.3




More information about the Telepathy-commits mailing list