[telepathy-gabble/master] add a wocky_pubsub_start method passing the session instead of passing it to the constructor

Guillaume Desmottes guillaume.desmottes at collabora.co.uk
Fri Sep 25 02:29:44 PDT 2009


This allow us the instantiate the Pubsub object during the construction
of the connection and so other components can already register their
event handlers *before* the connection has been connected and so the
session created.
---
 src/connection.c   |    4 +++-
 src/wocky-pubsub.c |   45 +++++++++++++--------------------------------
 src/wocky-pubsub.h |    5 ++++-
 3 files changed, 20 insertions(+), 34 deletions(-)

diff --git a/src/connection.c b/src/connection.c
index aa1615b..da9278d 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -328,6 +328,8 @@ gabble_connection_constructor (GType type,
 
   tp_base_connection_register_with_contacts_mixin (TP_BASE_CONNECTION (self));
 
+  self->pubsub = wocky_pubsub_new ();
+
   conn_aliasing_init (self);
   conn_avatars_init (self);
   conn_presence_init (self);
@@ -1526,7 +1528,7 @@ connector_connected (GabbleConnection *self,
 
   lm_connection_set_porter (self->lmconn, priv->porter);
 
-  self->pubsub = wocky_pubsub_new (self->session);
+  wocky_pubsub_start (self->pubsub, self->session);
 
   /* Don't use wocky_session_start as we don't want to start all the
    * components (Roster, presence-manager, etc) for now */
diff --git a/src/wocky-pubsub.c b/src/wocky-pubsub.c
index ea5c3f3..1d27ade 100644
--- a/src/wocky-pubsub.c
+++ b/src/wocky-pubsub.c
@@ -63,12 +63,6 @@ pubsub_event_handler_free (PubsubEventHandler *handler)
   g_slice_free (PubsubEventHandler, handler);
 }
 
-/* properties */
-enum
-{
-  PROP_SESSION = 1,
-};
-
 /* signal enum */
 enum
 {
@@ -97,7 +91,6 @@ struct _WockyPubsubPrivate
     (G_TYPE_INSTANCE_GET_PRIVATE ((o), WOCKY_TYPE_PUBSUB, \
     WockyPubsubPrivate))
 
-
 static void
 wocky_pubsub_init (WockyPubsub *obj)
 {
@@ -113,14 +106,8 @@ wocky_pubsub_set_property (GObject *object,
     const GValue *value,
     GParamSpec *pspec)
 {
-  WockyPubsubPrivate *priv =
-      WOCKY_PUBSUB_GET_PRIVATE (object);
-
   switch (property_id)
     {
-      case PROP_SESSION:
-        priv->session = g_value_get_object (value);
-        break;
       default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
         break;
@@ -133,14 +120,8 @@ wocky_pubsub_get_property (GObject *object,
     GValue *value,
     GParamSpec *pspec)
 {
-  WockyPubsubPrivate *priv =
-      WOCKY_PUBSUB_GET_PRIVATE (object);
-
   switch (property_id)
     {
-      case PROP_SESSION:
-        g_value_set_object (value, priv->session);
-        break;
       default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
         break;
@@ -151,9 +132,6 @@ static void
 wocky_pubsub_constructed (GObject *object)
 {
   WockyPubsub *self = WOCKY_PUBSUB (object);
-  WockyPubsubPrivate *priv = WOCKY_PUBSUB_GET_PRIVATE (self);
-
-  g_assert (priv->session != NULL);
 
   /* FIXME: should be done by the components */
   wocky_pubsub_register_event_handler (self, NS_NICK,
@@ -207,7 +185,6 @@ static void
 wocky_pubsub_class_init (WockyPubsubClass *wocky_pubsub_class)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (wocky_pubsub_class);
-  GParamSpec *spec;
 
   g_type_class_add_private (wocky_pubsub_class,
       sizeof (WockyPubsubPrivate));
@@ -217,13 +194,6 @@ wocky_pubsub_class_init (WockyPubsubClass *wocky_pubsub_class)
   object_class->get_property = wocky_pubsub_get_property;
   object_class->dispose = wocky_pubsub_dispose;
   object_class->finalize = wocky_pubsub_finalize;
-
-  spec = g_param_spec_object ("session", "Session",
-      "Wocky Session",
-      WOCKY_TYPE_SESSION,
-      G_PARAM_READWRITE |
-      G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
-  g_object_class_install_property (object_class, PROP_SESSION, spec);
 }
 
 static gboolean
@@ -375,13 +345,24 @@ pubsub_msg_event_cb (LmMessageHandler *handler,
 }
 
 WockyPubsub *
-wocky_pubsub_new (WockySession *session)
+wocky_pubsub_new (void)
 {
   return g_object_new (WOCKY_TYPE_PUBSUB,
-      "session", session,
       NULL);
 }
 
+void
+wocky_pubsub_start (WockyPubsub *self,
+    WockySession *session)
+{
+  WockyPubsubPrivate *priv = WOCKY_PUBSUB_GET_PRIVATE (self);
+
+  g_assert (priv->session == NULL);
+  priv->session = session;
+
+  /* TODO: register handler */
+}
+
 guint
 wocky_pubsub_register_event_handler (WockyPubsub *self,
     const gchar *ns,
diff --git a/src/wocky-pubsub.h b/src/wocky-pubsub.h
index 107af2f..478b980 100644
--- a/src/wocky-pubsub.h
+++ b/src/wocky-pubsub.h
@@ -55,7 +55,10 @@ GType wocky_pubsub_get_type (void);
   (G_TYPE_INSTANCE_GET_CLASS ((obj), WOCKY_TYPE_PUBSUB, \
    WockyPubsubClass))
 
-WockyPubsub * wocky_pubsub_new (WockySession *session);
+WockyPubsub * wocky_pubsub_new (void);
+
+void wocky_pubsub_start (WockyPubsub *pubsub,
+    WockySession *session);
 
 typedef gboolean (* WockyPubsubEventHandlerFunction) (GabbleConnection *conn,
     WockyXmppStanza *msg,
-- 
1.5.6.5




More information about the telepathy-commits mailing list