[next] telepathy-gabble: GabbleMucFactory: find IM channels by asking the IM factory, not dbus-glib

Simon McVittie smcv at kemper.freedesktop.org
Thu Apr 3 07:26:41 PDT 2014


Module: telepathy-gabble
Branch: next
Commit: 0d9b654b34ba66ccfb0ff500d65620a7d9f39e3d
URL:    http://cgit.freedesktop.org/telepathy/telepathy-gabble/commit/?id=0d9b654b34ba66ccfb0ff500d65620a7d9f39e3d

Author: Simon McVittie <simon.mcvittie at collabora.co.uk>
Date:   Tue Mar 18 19:07:55 2014 +0000

GabbleMucFactory: find IM channels by asking the IM factory, not dbus-glib

---

 src/connection.c  |    1 +
 src/im-factory.c  |   18 ++++++++++++++++++
 src/im-factory.h  |    3 +++
 src/muc-factory.c |   49 ++++++++++++++++++++++++++++++-------------------
 4 files changed, 52 insertions(+), 19 deletions(-)

diff --git a/src/connection.c b/src/connection.c
index 4823c7a..88202bb 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -332,6 +332,7 @@ _gabble_connection_create_channel_managers (TpBaseConnection *conn)
 
   self->muc_factory = g_object_new (GABBLE_TYPE_MUC_FACTORY,
       "connection", self,
+      "im-factory", self->priv->im_factory,
       NULL);
   g_ptr_array_add (channel_managers, self->muc_factory);
 
diff --git a/src/im-factory.c b/src/im-factory.c
index 4b581e3..b4b6315 100644
--- a/src/im-factory.c
+++ b/src/im-factory.c
@@ -815,3 +815,21 @@ caps_channel_manager_iface_init (gpointer g_iface,
 
   iface->get_contact_caps = gabble_im_factory_get_contact_caps;
 }
+
+GabbleIMChannel *
+gabble_im_factory_dup_channel (GabbleImFactory *self,
+    const gchar *path)
+{
+  GHashTableIter iter;
+  gpointer v;
+
+  g_hash_table_iter_init (&iter, self->priv->channels);
+
+  while (g_hash_table_iter_next (&iter, NULL, &v))
+    {
+      if (!tp_strdiff (tp_base_channel_get_object_path (v), path))
+        return GABBLE_IM_CHANNEL (g_object_ref (v));
+    }
+
+  return NULL;
+}
diff --git a/src/im-factory.h b/src/im-factory.h
index ea21100..442d895 100644
--- a/src/im-factory.h
+++ b/src/im-factory.h
@@ -41,6 +41,9 @@ struct _GabbleImFactory {
 
 GType gabble_im_factory_get_type (void);
 
+GabbleIMChannel *gabble_im_factory_dup_channel (GabbleImFactory *self,
+    const gchar *path);
+
 /* TYPE MACROS */
 #define GABBLE_TYPE_IM_FACTORY \
   (gabble_im_factory_get_type ())
diff --git a/src/muc-factory.c b/src/muc-factory.c
index 2636d8f..bce98d5 100644
--- a/src/muc-factory.c
+++ b/src/muc-factory.c
@@ -36,6 +36,7 @@
 #include "debug.h"
 #include "disco.h"
 #include "im-channel.h"
+#include "im-factory.h"
 #ifdef ENABLE_VOIP
 #include "media-factory.h"
 #endif
@@ -61,6 +62,7 @@ G_DEFINE_TYPE_WITH_CODE (GabbleMucFactory, gabble_muc_factory, G_TYPE_OBJECT,
 enum
 {
   PROP_CONNECTION = 1,
+  PROP_IM_FACTORY,
   LAST_PROPERTY
 };
 
@@ -74,6 +76,9 @@ struct _GabbleMucFactoryPrivate
   GabbleConnection *conn;
   gulong status_changed_id;
 
+  /* (transfer full) */
+  GabbleImFactory *im_factory;
+
   guint message_cb_id;
   /* GUINT_TO_POINTER(room_handle) => (GabbleMucChannel *) */
   GHashTable *text_channels;
@@ -148,6 +153,7 @@ gabble_muc_factory_dispose (GObject *object)
   priv->dispose_has_run = TRUE;
 
   gabble_muc_factory_close_all (fac);
+  g_assert (priv->im_factory == NULL);
   g_assert (priv->text_channels == NULL);
   g_assert (priv->text_needed_for_tube == NULL);
   g_assert (priv->queued_requests == NULL);
@@ -173,6 +179,9 @@ gabble_muc_factory_get_property (GObject    *object,
     case PROP_CONNECTION:
       g_value_set_object (value, priv->conn);
       break;
+    case PROP_IM_FACTORY:
+      g_value_set_object (value, priv->im_factory);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
       break;
@@ -192,6 +201,9 @@ gabble_muc_factory_set_property (GObject      *object,
     case PROP_CONNECTION:
       priv->conn = g_value_get_object (value);
       break;
+    case PROP_IM_FACTORY:
+      priv->im_factory = g_value_dup_object (value);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
       break;
@@ -218,6 +230,12 @@ gabble_muc_factory_class_init (GabbleMucFactoryClass *gabble_muc_factory_class)
       GABBLE_TYPE_CONNECTION,
       G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
   g_object_class_install_property (object_class, PROP_CONNECTION, param_spec);
+
+  param_spec = g_param_spec_object ("im-factory", "GabbleImFactory object",
+      "IM channel factory",
+      GABBLE_TYPE_IM_FACTORY,
+      G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+  g_object_class_install_property (object_class, PROP_IM_FACTORY, param_spec);
 }
 
 /**
@@ -877,6 +895,8 @@ gabble_muc_factory_close_all (GabbleMucFactory *self)
 
   DEBUG ("closing channels");
 
+  g_clear_object (&self->priv->im_factory);
+
   if (priv->status_changed_id != 0)
     {
       g_signal_handler_disconnect (priv->conn,
@@ -1220,41 +1240,32 @@ handle_text_channel_request (GabbleMucFactory *self,
   /* look at the list of initial channels, build a set of handles to invite */
   if (initial_channels != NULL)
     {
-      TpDBusDaemon *dbus_daemon = tp_base_connection_get_dbus_daemon (conn);
-      DBusGConnection *bus = tp_proxy_get_dbus_connection (dbus_daemon);
-
       for (i = 0; i < initial_channels->len; i++)
         {
           const char *object_path = g_ptr_array_index (initial_channels, i);
-          GObject *object;
+          GabbleIMChannel *channel;
           TpHandle handle;
-          TpBaseConnection *connection;
-
-          object = dbus_g_connection_lookup_g_object (bus, object_path);
-
-          if (!GABBLE_IS_IM_CHANNEL (object))
-            {
-              DEBUG ("Channel %s is not an ImChannel, ignoring",
-                  object_path);
-              continue;
-            }
 
-          connection = tp_base_channel_get_connection (
-              TP_BASE_CHANNEL (object));
+          /* FIXME: this is O(number of channels * number of paths) but
+           * neither is likely to be very large so it'll do for now */
+          channel = gabble_im_factory_dup_channel (priv->im_factory,
+              object_path);
 
-          if ((GabbleConnection *) connection != priv->conn)
+          if (channel == NULL)
             {
-              DEBUG ("Channel %s is from a different Connection, ignoring",
+              /* FIXME: shouldn't this raise an error? */
+              DEBUG ("Channel %s does not exist on this connection, ignoring",
                   object_path);
               continue;
             }
 
           handle = tp_base_channel_get_target_handle (
-              TP_BASE_CHANNEL (object));
+              TP_BASE_CHANNEL (channel));
 
           tp_handle_set_add (handles, handle);
           tp_intset_add (continue_handles, handle);
           g_hash_table_insert (final_channels, (char *) object_path, NULL);
+          g_object_unref (channel);
         }
     }
 



More information about the telepathy-commits mailing list