[telepathy-gabble/master] register pubsub event handlers in their component

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


---
 src/conn-aliasing.c |   13 +++++++++----
 src/conn-aliasing.h |    3 ---
 src/conn-location.c |   13 +++++++++----
 src/conn-location.h |    3 ---
 src/conn-olpc.c     |   49 +++++++++++++++++++++++++++++++++----------------
 src/conn-olpc.h     |   16 ----------------
 src/wocky-pubsub.c  |   26 ++------------------------
 src/wocky-pubsub.h  |    5 +++--
 8 files changed, 56 insertions(+), 72 deletions(-)

diff --git a/src/conn-aliasing.c b/src/conn-aliasing.c
index 162dd6a..ebe223f 100644
--- a/src/conn-aliasing.c
+++ b/src/conn-aliasing.c
@@ -658,11 +658,13 @@ _grab_nickname (GabbleConnection *self,
 }
 
 
-gboolean
-gabble_conn_aliasing_pep_nick_event_handler (GabbleConnection *conn,
-                                             LmMessage *msg,
-                                             const gchar *from)
+static gboolean
+gabble_conn_aliasing_pep_nick_event_handler (WockyPubsub *pubsub,
+    LmMessage *msg,
+    const gchar *from,
+    gpointer user_data)
 {
+  GabbleConnection *conn = GABBLE_CONNECTION (user_data);
   TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (
       (TpBaseConnection *) conn, TP_HANDLE_TYPE_CONTACT);
   LmMessageNode *node;
@@ -1037,6 +1039,9 @@ conn_aliasing_init (GabbleConnection *conn)
   tp_contacts_mixin_add_contact_attributes_iface (G_OBJECT (conn),
     TP_IFACE_CONNECTION_INTERFACE_ALIASING,
     conn_aliasing_fill_contact_attributes);
+
+  wocky_pubsub_register_event_handler (conn->pubsub, NS_NICK,
+      gabble_conn_aliasing_pep_nick_event_handler, conn);
 }
 
 void
diff --git a/src/conn-aliasing.h b/src/conn-aliasing.h
index 5c81081..8716bb7 100644
--- a/src/conn-aliasing.h
+++ b/src/conn-aliasing.h
@@ -30,9 +30,6 @@ G_BEGIN_DECLS
 void conn_aliasing_init (GabbleConnection *conn);
 void conn_aliasing_iface_init (gpointer g_iface, gpointer iface_data);
 
-gboolean gabble_conn_aliasing_pep_nick_event_handler (GabbleConnection *conn,
-    LmMessage *msg, const gchar *from);
-
 void gabble_conn_aliasing_nickname_updated (GObject *object,
     TpHandle handle, gpointer user_data);
 
diff --git a/src/conn-location.c b/src/conn-location.c
index 093c501..0f70b5f 100644
--- a/src/conn-location.c
+++ b/src/conn-location.c
@@ -510,11 +510,13 @@ update_location_from_msg (GabbleConnection *conn,
   return TRUE;
 }
 
-gboolean
-geolocation_event_handler (GabbleConnection *conn,
-                           LmMessage *msg,
-                           const gchar *from)
+static gboolean
+geolocation_event_handler (WockyPubsub *pubsub,
+    LmMessage *msg,
+    const gchar *from,
+    gpointer user_data)
 {
+  GabbleConnection *conn = GABBLE_CONNECTION (user_data);
   TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (
       (TpBaseConnection *) conn, TP_HANDLE_TYPE_CONTACT);
   TpBaseConnection *base = (TpBaseConnection *) conn;
@@ -568,4 +570,7 @@ conn_location_init (GabbleConnection *conn)
   tp_contacts_mixin_add_contact_attributes_iface (G_OBJECT (conn),
     TP_IFACE_CONNECTION_INTERFACE_LOCATION,
     conn_location_fill_contact_attributes);
+
+  wocky_pubsub_register_event_handler (conn->pubsub, NS_GEOLOC,
+       geolocation_event_handler, conn);
 }
diff --git a/src/conn-location.h b/src/conn-location.h
index e53a28c..fa2d707 100644
--- a/src/conn-location.h
+++ b/src/conn-location.h
@@ -14,9 +14,6 @@ void conn_location_properties_getter (GObject *object, GQuark interface,
 gboolean conn_location_properties_setter (GObject *object, GQuark interface,
     GQuark name, const GValue *value, gpointer setter_data, GError **error);
 
-gboolean geolocation_event_handler (GabbleConnection *conn,
-    LmMessage *msg, const gchar *from);
-
 void conn_location_init (GabbleConnection *conn);
 
 G_END_DECLS
diff --git a/src/conn-olpc.c b/src/conn-olpc.c
index e9914b0..4ebe39a 100644
--- a/src/conn-olpc.c
+++ b/src/conn-olpc.c
@@ -559,11 +559,13 @@ olpc_buddy_info_set_properties (GabbleSvcOLPCBuddyInfo *iface,
     }
 }
 
-gboolean
-olpc_buddy_info_properties_event_handler (GabbleConnection *conn,
-                                          LmMessage *msg,
-                                          const gchar *from)
+static gboolean
+olpc_buddy_info_properties_event_handler (WockyPubsub *pubsub,
+    LmMessage *msg,
+    const gchar *from,
+    gpointer user_data)
 {
+  GabbleConnection *conn = GABBLE_CONNECTION (user_data);
   TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (
       (TpBaseConnection *) conn, TP_HANDLE_TYPE_CONTACT);
   GHashTable *properties;
@@ -1178,11 +1180,13 @@ olpc_buddy_info_set_activities (GabbleSvcOLPCBuddyInfo *iface,
    * the case */
 }
 
-gboolean
-olpc_buddy_info_activities_event_handler (GabbleConnection *conn,
-                                          LmMessage *msg,
-                                          const gchar *from)
+static gboolean
+olpc_buddy_info_activities_event_handler (WockyPubsub *pubsub,
+    LmMessage *msg,
+    const gchar *from,
+    gpointer user_data)
 {
+  GabbleConnection *conn = GABBLE_CONNECTION (user_data);
   TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (
       (TpBaseConnection *) conn, TP_HANDLE_TYPE_CONTACT);
   GPtrArray *activities;
@@ -1515,11 +1519,13 @@ olpc_buddy_info_set_current_activity (GabbleSvcOLPCBuddyInfo *iface,
   lm_message_unref (msg);
 }
 
-gboolean
-olpc_buddy_info_current_activity_event_handler (GabbleConnection *conn,
-                                                LmMessage *msg,
-                                                const gchar *from)
+static gboolean
+olpc_buddy_info_current_activity_event_handler (WockyPubsub *pubsub,
+    LmMessage *msg,
+    const gchar *from,
+    gpointer user_data)
 {
+  GabbleConnection *conn = GABBLE_CONNECTION (user_data);
   TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (
       (TpBaseConnection *) conn, TP_HANDLE_TYPE_CONTACT);
   TpBaseConnection *base = (TpBaseConnection *) conn;
@@ -2089,11 +2095,13 @@ update_activities_properties (GabbleConnection *conn,
   return TRUE;
 }
 
-gboolean
-olpc_activities_properties_event_handler (GabbleConnection *conn,
-                                          LmMessage *msg,
-                                          const gchar *from)
+static gboolean
+olpc_activities_properties_event_handler (WockyPubsub *pubsub,
+    LmMessage *msg,
+    const gchar *from,
+    gpointer user_data)
 {
+  GabbleConnection *conn = GABBLE_CONNECTION (user_data);
   TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (
       (TpBaseConnection *) conn, TP_HANDLE_TYPE_CONTACT);
   TpBaseConnection *base = (TpBaseConnection *) conn;
@@ -3680,6 +3688,15 @@ conn_olpc_activity_properties_init (GabbleConnection *conn)
 
   g_signal_connect (conn->olpc_gadget_manager, "new-channels",
       G_CALLBACK (gadget_manager_new_channels_cb), conn);
+
+  wocky_pubsub_register_event_handler (conn->pubsub, NS_OLPC_BUDDY_PROPS,
+      olpc_buddy_info_properties_event_handler, conn);
+  wocky_pubsub_register_event_handler (conn->pubsub, NS_OLPC_ACTIVITIES,
+      olpc_buddy_info_activities_event_handler, conn);
+  wocky_pubsub_register_event_handler (conn->pubsub, NS_OLPC_CURRENT_ACTIVITY,
+      olpc_buddy_info_current_activity_event_handler, conn);
+  wocky_pubsub_register_event_handler (conn->pubsub, NS_OLPC_ACTIVITY_PROPS,
+      olpc_activities_properties_event_handler, conn);
 }
 
 static void
diff --git a/src/conn-olpc.h b/src/conn-olpc.h
index 62fbd23..9df7966 100644
--- a/src/conn-olpc.h
+++ b/src/conn-olpc.h
@@ -28,22 +28,6 @@
 void
 olpc_buddy_info_iface_init (gpointer g_iface, gpointer iface_data);
 
-gboolean
-olpc_buddy_info_properties_event_handler (GabbleConnection *conn,
-    LmMessage *msg, const gchar *from);
-
-gboolean
-olpc_buddy_info_activities_event_handler (GabbleConnection *conn,
-    LmMessage *msg, const gchar *from);
-
-gboolean
-olpc_buddy_info_current_activity_event_handler (GabbleConnection *conn,
-    LmMessage *msg, const gchar *from);
-
-gboolean
-olpc_activities_properties_event_handler (GabbleConnection *conn,
-    LmMessage *msg, const gchar *from);
-
 void gabble_connection_connected_olpc (GabbleConnection *conn);
 
 void
diff --git a/src/wocky-pubsub.c b/src/wocky-pubsub.c
index 1d27ade..428d662 100644
--- a/src/wocky-pubsub.c
+++ b/src/wocky-pubsub.c
@@ -129,26 +129,6 @@ wocky_pubsub_get_property (GObject *object,
 }
 
 static void
-wocky_pubsub_constructed (GObject *object)
-{
-  WockyPubsub *self = WOCKY_PUBSUB (object);
-
-  /* FIXME: should be done by the components */
-  wocky_pubsub_register_event_handler (self, NS_NICK,
-      gabble_conn_aliasing_pep_nick_event_handler, NULL);
-  wocky_pubsub_register_event_handler (self, NS_OLPC_BUDDY_PROPS,
-      olpc_buddy_info_properties_event_handler, NULL);
-  wocky_pubsub_register_event_handler (self, NS_OLPC_ACTIVITIES,
-      olpc_buddy_info_activities_event_handler, NULL);
-  wocky_pubsub_register_event_handler (self, NS_OLPC_CURRENT_ACTIVITY,
-      olpc_buddy_info_current_activity_event_handler, NULL);
-  wocky_pubsub_register_event_handler (self, NS_OLPC_ACTIVITY_PROPS,
-      olpc_activities_properties_event_handler, NULL);
-  wocky_pubsub_register_event_handler (self, NS_GEOLOC,
-       geolocation_event_handler, NULL);
-}
-
-static void
 wocky_pubsub_dispose (GObject *object)
 {
   WockyPubsub *self = WOCKY_PUBSUB (object);
@@ -189,7 +169,6 @@ wocky_pubsub_class_init (WockyPubsubClass *wocky_pubsub_class)
   g_type_class_add_private (wocky_pubsub_class,
       sizeof (WockyPubsubPrivate));
 
-  object_class->constructed = wocky_pubsub_constructed;
   object_class->set_property = wocky_pubsub_set_property;
   object_class->get_property = wocky_pubsub_get_property;
   object_class->dispose = wocky_pubsub_dispose;
@@ -198,7 +177,6 @@ wocky_pubsub_class_init (WockyPubsubClass *wocky_pubsub_class)
 
 static gboolean
 gabble_pubsub_event_handler (WockyPubsub *self,
-    GabbleConnection *conn,
     WockyXmppStanza *msg,
     const gchar *from,
     WockyXmppNode *item_node)
@@ -228,7 +206,7 @@ gabble_pubsub_event_handler (WockyPubsub *self,
 
       if (strcmp (handler->ns, event_ns) == 0)
         {
-          handler->handle_function (conn, msg, from);
+          handler->handle_function (self, msg, from, handler->user_data);
           return TRUE;
         }
     }
@@ -339,7 +317,7 @@ pubsub_msg_event_cb (LmMessageHandler *handler,
       return LM_HANDLER_RESULT_REMOVE_MESSAGE;
     }
 
-  gabble_pubsub_event_handler (self, conn, message, from, node);
+  gabble_pubsub_event_handler (self, message, from, node);
 
   return LM_HANDLER_RESULT_REMOVE_MESSAGE;
 }
diff --git a/src/wocky-pubsub.h b/src/wocky-pubsub.h
index 478b980..9e30453 100644
--- a/src/wocky-pubsub.h
+++ b/src/wocky-pubsub.h
@@ -60,9 +60,10 @@ WockyPubsub * wocky_pubsub_new (void);
 void wocky_pubsub_start (WockyPubsub *pubsub,
     WockySession *session);
 
-typedef gboolean (* WockyPubsubEventHandlerFunction) (GabbleConnection *conn,
+typedef gboolean (* WockyPubsubEventHandlerFunction) (WockyPubsub *pubsub,
     WockyXmppStanza *msg,
-    const gchar *from);
+    const gchar *from,
+    gpointer user_data);
 
 guint wocky_pubsub_register_event_handler (WockyPubsub *pubsub,
     const gchar *ns,
-- 
1.5.6.5




More information about the telepathy-commits mailing list