[telepathy-gabble/master] conn-olpc: use WockyPepService to get events
Guillaume Desmottes
guillaume.desmottes at collabora.co.uk
Mon Sep 21 07:07:07 PDT 2009
---
src/conn-olpc.c | 136 ++++++++++++++++++++++++++++++------------------------
src/connection.c | 38 +++++++++++----
src/connection.h | 8 ++--
3 files changed, 108 insertions(+), 74 deletions(-)
diff --git a/src/conn-olpc.c b/src/conn-olpc.c
index d44ed94..6c43166 100644
--- a/src/conn-olpc.c
+++ b/src/conn-olpc.c
@@ -597,37 +597,39 @@ olpc_buddy_info_set_properties (GabbleSvcOLPCBuddyInfo *iface,
}
}
-static gboolean
-olpc_buddy_info_properties_event_handler (WockyPubsub *pubsub,
- LmMessage *msg,
- const gchar *from,
- gpointer user_data)
+static void
+olpc_buddy_props_pep_node_changed (WockyPepService *pep,
+ WockyBareContact *contact,
+ WockyXmppStanza *stanza,
+ GabbleConnection *conn)
{
- GabbleConnection *conn = GABBLE_CONNECTION (user_data);
TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (
(TpBaseConnection *) conn, TP_HANDLE_TYPE_CONTACT);
GHashTable *properties;
LmMessageNode *node;
TpBaseConnection *base = (TpBaseConnection *) conn;
TpHandle handle;
+ const gchar *jid;
- handle = tp_handle_ensure (contact_repo, from, NULL, NULL);
+ jid = wocky_bare_contact_get_jid (contact);
+ handle = tp_handle_ensure (contact_repo, jid, NULL, NULL);
if (handle == 0)
{
- DEBUG ("Invalid from: %s", from);
- return FALSE;
+ DEBUG ("Invalid from: %s", jid);
+ return;
}
if (handle == base->self_handle)
/* Ignore echoed pubsub notifications */
- return TRUE;
+ goto out;
- node = lm_message_node_find_child (msg->node, "properties");
+ node = lm_message_node_find_child (stanza->node, "properties");
properties = lm_message_node_extract_properties (node, "property");
gabble_svc_olpc_buddy_info_emit_properties_changed (conn, handle,
properties);
g_hash_table_destroy (properties);
- return TRUE;
+out:
+ tp_handle_unref (contact_repo, handle);
}
static void
@@ -1243,36 +1245,38 @@ olpc_buddy_info_set_activities (GabbleSvcOLPCBuddyInfo *iface,
* the case */
}
-static gboolean
-olpc_buddy_info_activities_event_handler (WockyPubsub *pubsub,
- LmMessage *msg,
- const gchar *from,
- gpointer user_data)
+static void
+olpc_activities_pep_node_changed (WockyPepService *pep,
+ WockyBareContact *contact,
+ WockyXmppStanza *stanza,
+ GabbleConnection *conn)
{
- GabbleConnection *conn = GABBLE_CONNECTION (user_data);
TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (
(TpBaseConnection *) conn, TP_HANDLE_TYPE_CONTACT);
GPtrArray *activities;
TpBaseConnection *base = (TpBaseConnection *) conn;
TpHandle handle;
+ const gchar *jid;
- handle = tp_handle_ensure (contact_repo, from, NULL, NULL);
+ jid = wocky_bare_contact_get_jid (contact);
+ handle = tp_handle_ensure (contact_repo, jid, NULL, NULL);
if (handle == 0)
{
- DEBUG ("Invalid from: %s", from);
- return FALSE;
+ DEBUG ("Invalid from: %s", jid);
+ return;
}
if (handle == base->self_handle)
/* Ignore echoed pubsub notifications */
- return TRUE;
+ goto out;
- extract_activities (conn, msg, handle);
+ extract_activities (conn, stanza, handle);
activities = get_buddy_activities (conn, handle);
gabble_svc_olpc_buddy_info_emit_activities_changed (conn, handle,
activities);
free_activities (activities);
- return TRUE;
+out:
+ tp_handle_unref (contact_repo, handle);
}
static GabbleOlpcActivity *
@@ -1606,34 +1610,35 @@ olpc_buddy_info_set_current_activity (GabbleSvcOLPCBuddyInfo *iface,
lm_message_unref (msg);
}
-static gboolean
-olpc_buddy_info_current_activity_event_handler (WockyPubsub *pubsub,
- LmMessage *msg,
- const gchar *from,
- gpointer user_data)
+static void
+olpc_current_act_pep_node_changed (WockyPepService *pep,
+ WockyBareContact *contact,
+ WockyXmppStanza *stanza,
+ GabbleConnection *conn)
{
- GabbleConnection *conn = GABBLE_CONNECTION (user_data);
TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (
(TpBaseConnection *) conn, TP_HANDLE_TYPE_CONTACT);
TpBaseConnection *base = (TpBaseConnection *) conn;
LmMessageNode *node;
GabbleOlpcActivity *activity;
TpHandle handle;
+ const gchar *jid;
- handle = tp_handle_ensure (contact_repo, from, NULL, NULL);
+ jid = wocky_bare_contact_get_jid (contact);
+ handle = tp_handle_ensure (contact_repo, jid, NULL, NULL);
if (handle == 0)
{
- DEBUG ("Invalid from: %s", from);
- return FALSE;
+ DEBUG ("Invalid from: %s", jid);
+ return;
}
if (handle == base->self_handle)
/* Ignore echoed pubsub notifications */
- return TRUE;
+ goto out;
- node = lm_message_node_find_child (msg->node, "activity");
+ node = lm_message_node_find_child (stanza->node, "activity");
- activity = extract_current_activity (conn, node, from, TRUE);
+ activity = extract_current_activity (conn, node, jid, TRUE);
if (activity != NULL)
{
DEBUG ("emitting CurrentActivityChanged(contact#%u, ID \"%s\", room#%u)",
@@ -1649,7 +1654,8 @@ olpc_buddy_info_current_activity_event_handler (WockyPubsub *pubsub,
"", 0);
}
- return TRUE;
+out:
+ tp_handle_unref (contact_repo, handle);
}
void
@@ -2182,30 +2188,33 @@ update_activities_properties (GabbleConnection *conn,
return TRUE;
}
-static gboolean
-olpc_activities_properties_event_handler (WockyPubsub *pubsub,
- LmMessage *msg,
- const gchar *from,
- gpointer user_data)
+static void
+olpc_act_props_pep_node_changed (WockyPepService *pep,
+ WockyBareContact *contact,
+ WockyXmppStanza *stanza,
+ GabbleConnection *conn)
{
- GabbleConnection *conn = GABBLE_CONNECTION (user_data);
TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (
(TpBaseConnection *) conn, TP_HANDLE_TYPE_CONTACT);
TpBaseConnection *base = (TpBaseConnection *) conn;
TpHandle handle;
+ const gchar *jid;
- handle = tp_handle_ensure (contact_repo, from, NULL, NULL);
+ jid = wocky_bare_contact_get_jid (contact);
+ handle = tp_handle_ensure (contact_repo, jid, NULL, NULL);
if (handle == 0)
{
- DEBUG ("Invalid from: %s", from);
- return FALSE;
+ DEBUG ("Invalid from: %s", jid);
+ return;
}
if (handle == base->self_handle)
/* Ignore echoed pubsub notifications */
- return TRUE;
+ goto out;
- return update_activities_properties (conn, from, msg);
+ update_activities_properties (conn, jid, stanza);
+out:
+ tp_handle_unref (contact_repo, handle);
}
static void
@@ -3776,18 +3785,25 @@ conn_olpc_activity_properties_init (GabbleConnection *conn)
g_signal_connect (conn->olpc_gadget_manager, "new-channels",
G_CALLBACK (gadget_manager_new_channels_cb), conn);
- conn->pubsub_olpc_buddy_props_event_id = wocky_pubsub_register_event_handler (
- conn->pubsub, NS_OLPC_BUDDY_PROPS,
- olpc_buddy_info_properties_event_handler, conn);
- conn->pubsub_olpc_activities_event_id = wocky_pubsub_register_event_handler (
- conn->pubsub, NS_OLPC_ACTIVITIES,
- olpc_buddy_info_activities_event_handler, conn);
- conn->pubsub_olpc_current_act_props_event_id =
- wocky_pubsub_register_event_handler (conn->pubsub, NS_OLPC_CURRENT_ACTIVITY,
- olpc_buddy_info_current_activity_event_handler, conn);
- conn->pubsub_olpc_act_props_props_event_id =
- wocky_pubsub_register_event_handler (conn->pubsub, NS_OLPC_ACTIVITY_PROPS,
- olpc_activities_properties_event_handler, conn);
+ conn->pep_olpc_buddy_props = wocky_pep_service_new (NS_OLPC_BUDDY_PROPS,
+ TRUE);
+ g_signal_connect (conn->pep_olpc_buddy_props, "changed",
+ G_CALLBACK (olpc_buddy_props_pep_node_changed), conn);
+
+ conn->pep_olpc_activities = wocky_pep_service_new (NS_OLPC_ACTIVITIES,
+ TRUE);
+ g_signal_connect (conn->pep_olpc_activities, "changed",
+ G_CALLBACK (olpc_activities_pep_node_changed), conn);
+
+ conn->pep_olpc_current_act = wocky_pep_service_new (NS_OLPC_CURRENT_ACTIVITY,
+ TRUE);
+ g_signal_connect (conn->pep_olpc_current_act, "changed",
+ G_CALLBACK (olpc_current_act_pep_node_changed), conn);
+
+ conn->pep_olpc_act_props = wocky_pep_service_new (NS_OLPC_ACTIVITY_PROPS,
+ TRUE);
+ g_signal_connect (conn->pep_olpc_act_props, "changed",
+ G_CALLBACK (olpc_act_props_pep_node_changed), conn);
}
static void
diff --git a/src/connection.c b/src/connection.c
index 31ee415..44cb5e2 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -990,16 +990,6 @@ gabble_connection_dispose (GObject *object)
priv->disconnect_timer = 0;
}
- /* unregister pubsub event handlers */
- wocky_pubsub_unregister_event_handler (self->pubsub,
- self->pubsub_olpc_buddy_props_event_id);
- wocky_pubsub_unregister_event_handler (self->pubsub,
- self->pubsub_olpc_activities_event_id);
- wocky_pubsub_unregister_event_handler (self->pubsub,
- self->pubsub_olpc_current_act_props_event_id);
- wocky_pubsub_unregister_event_handler (self->pubsub,
- self->pubsub_olpc_act_props_props_event_id);
-
if (self->pep_location != NULL)
{
g_object_unref (self->pep_location);
@@ -1012,6 +1002,30 @@ gabble_connection_dispose (GObject *object)
self->pep_nick = NULL;
}
+ if (self->pep_olpc_buddy_props != NULL)
+ {
+ g_object_unref (self->pep_olpc_buddy_props);
+ self->pep_olpc_buddy_props = NULL;
+ }
+
+ if (self->pep_olpc_activities != NULL)
+ {
+ g_object_unref (self->pep_olpc_activities);
+ self->pep_olpc_activities = NULL;
+ }
+
+ if (self->pep_olpc_current_act != NULL)
+ {
+ g_object_unref (self->pep_olpc_current_act);
+ self->pep_olpc_current_act = NULL;
+ }
+
+ if (self->pep_olpc_act_props != NULL)
+ {
+ g_object_unref (self->pep_olpc_act_props);
+ self->pep_olpc_act_props = NULL;
+ }
+
if (self->pubsub != NULL)
{
g_object_unref (self->pubsub);
@@ -1551,6 +1565,10 @@ connector_connected (GabbleConnection *self,
wocky_pubsub_start (self->pubsub, self->session);
wocky_pep_service_start (self->pep_location, self->session);
wocky_pep_service_start (self->pep_nick, self->session);
+ wocky_pep_service_start (self->pep_olpc_buddy_props, self->session);
+ wocky_pep_service_start (self->pep_olpc_activities, self->session);
+ wocky_pep_service_start (self->pep_olpc_current_act, self->session);
+ wocky_pep_service_start (self->pep_olpc_act_props, 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/connection.h b/src/connection.h
index b2e6764..4210ece 100644
--- a/src/connection.h
+++ b/src/connection.h
@@ -196,10 +196,10 @@ struct _GabbleConnection {
WockyPubsub *pubsub;
WockyPepService *pep_nick;
WockyPepService *pep_location;
- guint pubsub_olpc_buddy_props_event_id;
- guint pubsub_olpc_activities_event_id;
- guint pubsub_olpc_current_act_props_event_id;
- guint pubsub_olpc_act_props_props_event_id;
+ WockyPepService *pep_olpc_buddy_props;
+ WockyPepService *pep_olpc_activities;
+ WockyPepService *pep_olpc_current_act;
+ WockyPepService *pep_olpc_act_props;
GabbleConnectionPrivate *priv;
};
--
1.5.6.5
More information about the telepathy-commits
mailing list