diff options
author | <robert.mcqueen@collabora.co.uk> | 2006-06-05 10:04:13 +0000 |
---|---|---|
committer | <robert.mcqueen@collabora.co.uk> | 2006-06-05 10:04:13 +0000 |
commit | 8f421d2953e60cbe9761370b421eb0febd981d42 (patch) | |
tree | 06726c18faa5fa79bf7f8e454a046ab5f973151e | |
parent | 6130cf5d5f15223d0c38924fbc9519acd7cd3639 (diff) |
add a connecting method to TpChannelFactoryIface, and only hook up callbacks at CONNECTING, so that if we fail before that, our assertion that there our no callbacks at dispose time is correct
-rw-r--r-- | src/gabble-connection.c | 181 | ||||
-rw-r--r-- | src/gabble-presence-cache.c | 54 | ||||
-rw-r--r-- | src/im-factory.c | 43 | ||||
-rw-r--r-- | src/muc-factory.c | 66 | ||||
-rw-r--r-- | src/roster.c | 77 | ||||
-rw-r--r-- | src/tp-channel-factory-iface.c | 6 | ||||
-rw-r--r-- | src/tp-channel-factory-iface.h | 2 |
7 files changed, 250 insertions, 179 deletions
diff --git a/src/gabble-connection.c b/src/gabble-connection.c index 37c0ab27b..60f0b9a81 100644 --- a/src/gabble-connection.c +++ b/src/gabble-connection.c @@ -287,7 +287,7 @@ gabble_connection_init (GabbleConnection *obj) GValue val = { 0, }; obj->lmconn = lm_connection_new (NULL); - obj->status = TP_CONN_STATUS_CONNECTING; + obj->status = TP_CONN_STATUS_DISCONNECTED; obj->handles = gabble_handle_repo_new (); obj->disco = gabble_disco_new (obj); @@ -866,6 +866,15 @@ gabble_connection_class_init (GabbleConnectionClass *gabble_connection_class) NULL); } +static gboolean +_unref_lm_connection (gpointer data) +{ + LmConnection *conn = (LmConnection *) data; + + lm_connection_unref (conn); + return FALSE; +} + void gabble_connection_dispose (GObject *object) { @@ -915,30 +924,20 @@ gabble_connection_dispose (GObject *object) g_object_unref (self->presence_cache); self->presence_cache = NULL; - if (self->lmconn) - { - if (lm_connection_is_open (self->lmconn)) - { - g_warning ("%s: connection was open when the object was deleted, it'll probably crash now...", G_STRFUNC); - lm_connection_close (self->lmconn, NULL); - } - - lm_connection_unregister_message_handler (self->lmconn, priv->iq_jingle_info_cb, - LM_MESSAGE_TYPE_IQ); - lm_message_handler_unref (priv->iq_jingle_info_cb); - - lm_connection_unregister_message_handler (self->lmconn, priv->iq_jingle_cb, - LM_MESSAGE_TYPE_IQ); - lm_message_handler_unref (priv->iq_jingle_cb); + /* if this is not already the case, we'll crash anyway */ + g_assert (!lm_connection_is_open (self->lmconn)); - lm_connection_unregister_message_handler (self->lmconn, priv->iq_disco_cb, - LM_MESSAGE_TYPE_IQ); - lm_message_handler_unref (priv->iq_disco_cb); + g_assert (priv->iq_jingle_info_cb == NULL); + g_assert (priv->iq_jingle_cb == NULL); + g_assert (priv->iq_disco_cb == NULL); + g_assert (priv->iq_unknown_cb == NULL); - lm_connection_unregister_message_handler (self->lmconn, priv->iq_unknown_cb, - LM_MESSAGE_TYPE_IQ); - lm_message_handler_unref (priv->iq_unknown_cb); - } + /* + * The Loudmouth connection can't be unref'd immediately because this + * function might (indirectly) return into Loudmouth code which expects the + * connection to always be there. + */ + g_idle_add (_unref_lm_connection, self->lmconn); dbus_g_proxy_call_no_reply (bus_proxy, "ReleaseName", G_TYPE_STRING, self->bus_name, @@ -948,15 +947,6 @@ gabble_connection_dispose (GObject *object) G_OBJECT_CLASS (gabble_connection_parent_class)->dispose (object); } -static gboolean -_unref_lm_connection (gpointer data) -{ - LmConnection *conn = (LmConnection *) data; - - lm_connection_unref (conn); - return FALSE; -} - void gabble_connection_finalize (GObject *object) { @@ -965,14 +955,6 @@ gabble_connection_finalize (GObject *object) g_debug ("%s called with %p", G_STRFUNC, object); - /* - * The Loudmouth connection can't be unref'd immediately because this - * function might (indirectly) return into Loudmouth code which expects the - * connection to always be there. - */ - if (self->lmconn) - g_idle_add (_unref_lm_connection, self->lmconn); - g_free (self->bus_name); g_free (self->object_path); @@ -1004,7 +986,6 @@ gabble_connection_finalize (GObject *object) gabble_properties_mixin_finalize (object); G_OBJECT_CLASS (gabble_connection_parent_class)->finalize (object); - } /** @@ -1372,6 +1353,73 @@ do_connect (GabbleConnection *conn, GError **error) return TRUE; } +static void +connect_callbacks (GabbleConnection *conn) +{ + GabbleConnectionPrivate *priv = GABBLE_CONNECTION_GET_PRIVATE (conn); + + g_assert (priv->iq_jingle_info_cb == NULL); + g_assert (priv->iq_jingle_cb == NULL); + g_assert (priv->iq_disco_cb == NULL); + g_assert (priv->iq_unknown_cb == NULL); + + priv->iq_jingle_info_cb = lm_message_handler_new (jingle_info_iq_callback, + conn, NULL); + lm_connection_register_message_handler (conn->lmconn, + priv->iq_jingle_info_cb, + LM_MESSAGE_TYPE_IQ, + LM_HANDLER_PRIORITY_NORMAL); + + priv->iq_jingle_cb = lm_message_handler_new (connection_iq_jingle_cb, + conn, NULL); + lm_connection_register_message_handler (conn->lmconn, priv->iq_jingle_cb, + LM_MESSAGE_TYPE_IQ, + LM_HANDLER_PRIORITY_NORMAL); + + priv->iq_disco_cb = lm_message_handler_new (connection_iq_disco_cb, + conn, NULL); + lm_connection_register_message_handler (conn->lmconn, priv->iq_disco_cb, + LM_MESSAGE_TYPE_IQ, + LM_HANDLER_PRIORITY_NORMAL); + + priv->iq_unknown_cb = lm_message_handler_new (connection_iq_unknown_cb, + conn, NULL); + lm_connection_register_message_handler (conn->lmconn, priv->iq_unknown_cb, + LM_MESSAGE_TYPE_IQ, + LM_HANDLER_PRIORITY_LAST); +} + +static void +disconnect_callbacks (GabbleConnection *conn) +{ + GabbleConnectionPrivate *priv = GABBLE_CONNECTION_GET_PRIVATE (conn); + + g_assert (priv->iq_jingle_info_cb != NULL); + g_assert (priv->iq_jingle_cb != NULL); + g_assert (priv->iq_disco_cb != NULL); + g_assert (priv->iq_unknown_cb != NULL); + + lm_connection_unregister_message_handler (conn->lmconn, priv->iq_jingle_info_cb, + LM_MESSAGE_TYPE_IQ); + lm_message_handler_unref (priv->iq_jingle_info_cb); + priv->iq_jingle_info_cb = NULL; + + lm_connection_unregister_message_handler (conn->lmconn, priv->iq_jingle_cb, + LM_MESSAGE_TYPE_IQ); + lm_message_handler_unref (priv->iq_jingle_cb); + priv->iq_jingle_cb = NULL; + + lm_connection_unregister_message_handler (conn->lmconn, priv->iq_disco_cb, + LM_MESSAGE_TYPE_IQ); + lm_message_handler_unref (priv->iq_disco_cb); + priv->iq_disco_cb = NULL; + + lm_connection_unregister_message_handler (conn->lmconn, priv->iq_unknown_cb, + LM_MESSAGE_TYPE_IQ); + lm_message_handler_unref (priv->iq_unknown_cb); + priv->iq_unknown_cb = NULL; +} + /** * _gabble_connection_connect * @@ -1477,41 +1525,22 @@ _gabble_connection_connect (GabbleConnection *conn, conn, NULL); - priv->iq_jingle_info_cb = lm_message_handler_new (jingle_info_iq_callback, - conn, NULL); - lm_connection_register_message_handler (conn->lmconn, - priv->iq_jingle_info_cb, - LM_MESSAGE_TYPE_IQ, - LM_HANDLER_PRIORITY_NORMAL); - - priv->iq_jingle_cb = lm_message_handler_new (connection_iq_jingle_cb, - conn, NULL); - lm_connection_register_message_handler (conn->lmconn, priv->iq_jingle_cb, - LM_MESSAGE_TYPE_IQ, - LM_HANDLER_PRIORITY_NORMAL); - - priv->iq_disco_cb = lm_message_handler_new (connection_iq_disco_cb, - conn, NULL); - lm_connection_register_message_handler (conn->lmconn, priv->iq_disco_cb, - LM_MESSAGE_TYPE_IQ, - LM_HANDLER_PRIORITY_NORMAL); - - priv->iq_unknown_cb = lm_message_handler_new (connection_iq_unknown_cb, - conn, NULL); - lm_connection_register_message_handler (conn->lmconn, priv->iq_unknown_cb, - LM_MESSAGE_TYPE_IQ, - LM_HANDLER_PRIORITY_LAST); - - if (!do_connect (conn, error)) + if (do_connect (conn, error)) { connection_status_change (conn, - TP_CONN_STATUS_DISCONNECTED, - TP_CONN_STATUS_REASON_NETWORK_ERROR); + TP_CONN_STATUS_CONNECTING, + TP_CONN_STATUS_REASON_REQUESTED); + } + else + { + return FALSE; } return TRUE; } + + static void connection_disconnected_cb (LmConnection *lmconn, LmDisconnectReason lm_reason, @@ -1596,7 +1625,16 @@ connection_status_change (GabbleConnection *conn, g_signal_emit (conn, signals[STATUS_CHANGED], 0, status, reason); - if (status == TP_CONN_STATUS_CONNECTED) + if (status == TP_CONN_STATUS_CONNECTING) + { + /* add our callbacks */ + connect_callbacks (conn); + + /* trigger connecting on all channel factories */ + g_ptr_array_foreach (priv->channel_factories, (GFunc) + tp_channel_factory_iface_connecting, NULL); + } + else if (status == TP_CONN_STATUS_CONNECTED) { /* trigger connected on all channel factories */ g_ptr_array_foreach (priv->channel_factories, (GFunc) @@ -1604,6 +1642,9 @@ connection_status_change (GabbleConnection *conn, } else if (status == TP_CONN_STATUS_DISCONNECTED) { + /* remove our callbacks */ + disconnect_callbacks (conn); + /* trigger disconnected on all channel factories */ g_ptr_array_foreach (priv->channel_factories, (GFunc) tp_channel_factory_iface_disconnected, NULL); diff --git a/src/gabble-presence-cache.c b/src/gabble-presence-cache.c index 5fab1fb1e..9e158e932 100644 --- a/src/gabble-presence-cache.c +++ b/src/gabble-presence-cache.c @@ -77,7 +77,7 @@ static GabblePresence *_cache_insert (GabblePresenceCache *cache, static void gabble_presence_cache_status_changed_cb (GabbleConnection *, TpConnectionStatus, TpConnectionStatusReason, gpointer); -static LmHandlerResult gabble_presence_cache_presence_cb (LmMessageHandler*, +static LmHandlerResult gabble_presence_cache_lm_message_cb (LmMessageHandler*, LmConnection*, LmMessage*, gpointer); static void @@ -147,19 +147,7 @@ gabble_presence_cache_constructor (GType type, guint n_props, priv = GABBLE_PRESENCE_CACHE_PRIV (GABBLE_PRESENCE_CACHE (obj)); priv->status_changed_cb = g_signal_connect (priv->conn, "status-changed", - G_CALLBACK (gabble_presence_cache_status_changed_cb), - obj); - - priv->lm_message_cb = lm_message_handler_new (gabble_presence_cache_presence_cb, - obj, NULL); - lm_connection_register_message_handler (priv->conn->lmconn, - priv->lm_message_cb, - LM_MESSAGE_TYPE_PRESENCE, - LM_HANDLER_PRIORITY_LAST); - lm_connection_register_message_handler (priv->conn->lmconn, - priv->lm_message_cb, - LM_MESSAGE_TYPE_MESSAGE, - LM_HANDLER_PRIORITY_FIRST); + G_CALLBACK (gabble_presence_cache_status_changed_cb), obj); return obj; } @@ -297,20 +285,30 @@ gabble_presence_cache_status_changed_cb (GabbleConnection *conn, switch (status) { case TP_CONN_STATUS_CONNECTING: + g_assert (priv->lm_message_cb == NULL); + + priv->lm_message_cb = lm_message_handler_new (gabble_presence_cache_lm_message_cb, + cache, NULL); + lm_connection_register_message_handler (priv->conn->lmconn, + priv->lm_message_cb, + LM_MESSAGE_TYPE_PRESENCE, + LM_HANDLER_PRIORITY_LAST); + lm_connection_register_message_handler (priv->conn->lmconn, + priv->lm_message_cb, + LM_MESSAGE_TYPE_MESSAGE, + LM_HANDLER_PRIORITY_FIRST); break; case TP_CONN_STATUS_CONNECTED: /* TODO: emit self presence */ break; case TP_CONN_STATUS_DISCONNECTED: - /* disconnect our handlers so they don't get created again */ - if (priv->lm_message_cb) - { - lm_connection_unregister_message_handler (conn->lmconn, - priv->lm_message_cb, - LM_MESSAGE_TYPE_PRESENCE); - lm_message_handler_unref (priv->lm_message_cb); - priv->lm_message_cb = NULL; - } + g_assert (priv->lm_message_cb != NULL); + + lm_connection_unregister_message_handler (conn->lmconn, + priv->lm_message_cb, + LM_MESSAGE_TYPE_PRESENCE); + lm_message_handler_unref (priv->lm_message_cb); + priv->lm_message_cb = NULL; break; default: g_assert_not_reached (); @@ -510,7 +508,7 @@ _parse_message_message (GabblePresenceCache *cache, /** - * gabble_presence_cache_presence_cb: + * gabble_presence_cache_message_cb: * @handler: #LmMessageHandler for this message * @connection: #LmConnection that originated the message * @message: the presence message @@ -519,10 +517,10 @@ _parse_message_message (GabblePresenceCache *cache, * Called by loudmouth when we get an incoming <presence>. */ static LmHandlerResult -gabble_presence_cache_presence_cb (LmMessageHandler *handler, - LmConnection *lmconn, - LmMessage *message, - gpointer user_data) +gabble_presence_cache_lm_message_cb (LmMessageHandler *handler, + LmConnection *lmconn, + LmMessage *message, + gpointer user_data) { GabblePresenceCache *cache = GABBLE_PRESENCE_CACHE (user_data); GabblePresenceCachePrivate *priv = GABBLE_PRESENCE_CACHE_PRIV (cache); diff --git a/src/im-factory.c b/src/im-factory.c index d55619a94..810a647f2 100644 --- a/src/im-factory.c +++ b/src/im-factory.c @@ -39,7 +39,6 @@ #include "tp-channel-factory-iface.h" static void gabble_im_factory_iface_init (gpointer g_iface, gpointer iface_data); -static LmHandlerResult im_factory_message_cb (LmMessageHandler*, LmConnection*, LmMessage*, gpointer); G_DEFINE_TYPE_WITH_CODE (GabbleImFactory, gabble_im_factory, G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE (TP_TYPE_CHANNEL_FACTORY_IFACE, gabble_im_factory_iface_init)); @@ -84,19 +83,11 @@ gabble_im_factory_constructor (GType type, guint n_props, GObjectConstructParam *props) { GObject *obj; - GabbleImFactoryPrivate *priv; + /* GabbleImFactoryPrivate *priv; */ obj = G_OBJECT_CLASS (gabble_im_factory_parent_class)-> constructor (type, n_props, props); - priv = GABBLE_IM_FACTORY_GET_PRIVATE (obj); - - g_assert(priv->conn != NULL); - g_assert(priv->conn->lmconn != NULL); - - priv->message_cb = lm_message_handler_new (im_factory_message_cb, obj, NULL); - lm_connection_register_message_handler (priv->conn->lmconn, priv->message_cb, - LM_MESSAGE_TYPE_MESSAGE, - LM_HANDLER_PRIORITY_LAST); + /* priv = GABBLE_IM_FACTORY_GET_PRIVATE (obj); */ return obj; } @@ -321,6 +312,23 @@ 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); + + g_debug ("%s: adding callbacks", G_STRFUNC); + + 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) { /* nothing to do */ @@ -334,12 +342,12 @@ gabble_im_factory_iface_disconnected (TpChannelFactoryIface *iface) g_debug ("%s: removing callbacks", G_STRFUNC); - if (priv->message_cb) - { - lm_connection_unregister_message_handler (priv->conn->lmconn, priv->message_cb, - LM_MESSAGE_TYPE_MESSAGE); - priv->message_cb = NULL; - } + 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; } struct _ForeachData @@ -409,6 +417,7 @@ 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->foreach = gabble_im_factory_iface_foreach; diff --git a/src/muc-factory.c b/src/muc-factory.c index ff9b07dd9..bf0028c31 100644 --- a/src/muc-factory.c +++ b/src/muc-factory.c @@ -42,9 +42,6 @@ #include "tp-channel-factory-iface.h" static void gabble_muc_factory_iface_init (gpointer g_iface, gpointer iface_data); -static LmHandlerResult muc_factory_message_cb (LmMessageHandler*, LmConnection*, LmMessage*, gpointer); -static LmHandlerResult muc_factory_presence_cb (LmMessageHandler*, LmConnection*, LmMessage*, gpointer); - G_DEFINE_TYPE_WITH_CODE (GabbleMucFactory, gabble_muc_factory, G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE (TP_TYPE_CHANNEL_FACTORY_IFACE, gabble_muc_factory_iface_init)); @@ -93,24 +90,12 @@ gabble_muc_factory_constructor (GType type, guint n_props, GObjectConstructParam *props) { GObject *obj; - GabbleMucFactoryPrivate *priv; + /* GabbleMucFactoryPrivate *priv; */ obj = G_OBJECT_CLASS (gabble_muc_factory_parent_class)-> constructor (type, n_props, props); - priv = GABBLE_MUC_FACTORY_GET_PRIVATE (obj); - - g_assert(priv->conn != NULL); - g_assert(priv->conn->lmconn != NULL); + /* priv = GABBLE_MUC_FACTORY_GET_PRIVATE (obj); */ - priv->message_cb = lm_message_handler_new (muc_factory_message_cb, obj, NULL); - lm_connection_register_message_handler (priv->conn->lmconn, priv->message_cb, - LM_MESSAGE_TYPE_MESSAGE, - LM_HANDLER_PRIORITY_NORMAL); - - priv->presence_cb = lm_message_handler_new (muc_factory_presence_cb, obj, NULL); - lm_connection_register_message_handler (priv->conn->lmconn, priv->presence_cb, - LM_MESSAGE_TYPE_PRESENCE, - LM_HANDLER_PRIORITY_NORMAL); return obj; } @@ -495,6 +480,29 @@ gabble_muc_factory_iface_close_all (TpChannelFactoryIface *iface) } static void +gabble_muc_factory_iface_connecting (TpChannelFactoryIface *iface) +{ + GabbleMucFactory *fac = GABBLE_MUC_FACTORY (iface); + GabbleMucFactoryPrivate *priv = GABBLE_MUC_FACTORY_GET_PRIVATE (fac); + + g_debug ("%s: adding callbacks", G_STRFUNC); + + g_assert (priv->message_cb == NULL); + g_assert (priv->presence_cb == NULL); + + priv->message_cb = lm_message_handler_new (muc_factory_message_cb, fac, NULL); + lm_connection_register_message_handler (priv->conn->lmconn, priv->message_cb, + LM_MESSAGE_TYPE_MESSAGE, + LM_HANDLER_PRIORITY_NORMAL); + + priv->presence_cb = lm_message_handler_new (muc_factory_presence_cb, fac, NULL); + lm_connection_register_message_handler (priv->conn->lmconn, priv->presence_cb, + LM_MESSAGE_TYPE_PRESENCE, + LM_HANDLER_PRIORITY_NORMAL); +} + + +static void gabble_muc_factory_iface_connected (TpChannelFactoryIface *iface) { /* nothing to do */ @@ -508,19 +516,18 @@ gabble_muc_factory_iface_disconnected (TpChannelFactoryIface *iface) g_debug ("%s: removing callbacks", G_STRFUNC); - if (priv->message_cb) - { - lm_connection_unregister_message_handler (priv->conn->lmconn, priv->message_cb, - LM_MESSAGE_TYPE_MESSAGE); - priv->message_cb = NULL; - } + g_assert (priv->message_cb != NULL); + g_assert (priv->presence_cb != NULL); - if (priv->presence_cb) - { - lm_connection_unregister_message_handler (priv->conn->lmconn, priv->presence_cb, - LM_MESSAGE_TYPE_PRESENCE); - priv->presence_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; + + lm_connection_unregister_message_handler (priv->conn->lmconn, priv->presence_cb, + LM_MESSAGE_TYPE_PRESENCE); + lm_message_handler_unref (priv->presence_cb); + priv->presence_cb = NULL; } struct _ForeachData @@ -611,6 +618,7 @@ gabble_muc_factory_iface_init (gpointer g_iface, TpChannelFactoryIfaceClass *klass = (TpChannelFactoryIfaceClass *) g_iface; klass->close_all = gabble_muc_factory_iface_close_all; + klass->connecting = gabble_muc_factory_iface_connecting; klass->connected = gabble_muc_factory_iface_connected; klass->disconnected = gabble_muc_factory_iface_disconnected; klass->foreach = gabble_muc_factory_iface_foreach; diff --git a/src/roster.c b/src/roster.c index fecc07aa0..081e718e1 100644 --- a/src/roster.c +++ b/src/roster.c @@ -83,9 +83,6 @@ static void gabble_roster_set_property (GObject *object, guint property_id, static void gabble_roster_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec); -static LmHandlerResult gabble_roster_iq_cb (LmMessageHandler *, LmConnection *, LmMessage *, gpointer); -static LmHandlerResult gabble_roster_presence_cb (LmMessageHandler *, LmConnection *, LmMessage *, gpointer); - static void _gabble_roster_item_free (GabbleRosterItem *item); G_DEFINE_TYPE_WITH_CODE (GabbleRoster, gabble_roster, G_TYPE_OBJECT, @@ -154,25 +151,11 @@ gabble_roster_constructor (GType type, guint n_props, GObjectConstructParam *props) { GObject *obj; - GabbleRosterPrivate *priv; + /* GabbleRosterPrivate *priv; */ obj = G_OBJECT_CLASS (gabble_roster_parent_class)-> constructor (type, n_props, props); - priv = GABBLE_ROSTER_GET_PRIVATE (GABBLE_ROSTER (obj)); - - priv->iq_cb = lm_message_handler_new (gabble_roster_iq_cb, - obj, NULL); - lm_connection_register_message_handler (priv->conn->lmconn, - priv->iq_cb, - LM_MESSAGE_TYPE_IQ, - LM_HANDLER_PRIORITY_NORMAL); - - priv->presence_cb = lm_message_handler_new (gabble_roster_presence_cb, - obj, NULL); - lm_connection_register_message_handler (priv->conn->lmconn, - priv->presence_cb, - LM_MESSAGE_TYPE_PRESENCE, - LM_HANDLER_PRIORITY_LAST); + /* priv = GABBLE_ROSTER_GET_PRIVATE (GABBLE_ROSTER (obj)); */ return obj; } @@ -998,6 +981,32 @@ gabble_roster_factory_iface_close_all (TpChannelFactoryIface *iface) } static void +gabble_roster_factory_iface_connecting (TpChannelFactoryIface *iface) +{ + GabbleRoster *roster = GABBLE_ROSTER (iface); + GabbleRosterPrivate *priv = GABBLE_ROSTER_GET_PRIVATE (roster); + + g_debug ("%s: adding callbacks", G_STRFUNC); + + g_assert (priv->iq_cb == NULL); + g_assert (priv->presence_cb == NULL); + + priv->iq_cb = lm_message_handler_new (gabble_roster_iq_cb, + roster, NULL); + lm_connection_register_message_handler (priv->conn->lmconn, + priv->iq_cb, + LM_MESSAGE_TYPE_IQ, + LM_HANDLER_PRIORITY_NORMAL); + + priv->presence_cb = lm_message_handler_new (gabble_roster_presence_cb, + roster, NULL); + lm_connection_register_message_handler (priv->conn->lmconn, + priv->presence_cb, + LM_MESSAGE_TYPE_PRESENCE, + LM_HANDLER_PRIORITY_LAST); +} + +static void gabble_roster_factory_iface_connected (TpChannelFactoryIface *iface) { GabbleRoster *roster = GABBLE_ROSTER (iface); @@ -1029,23 +1038,20 @@ gabble_roster_factory_iface_disconnected (TpChannelFactoryIface *iface) g_debug ("%s: removing callbacks", G_STRFUNC); - if (priv->iq_cb) - { - lm_connection_unregister_message_handler (priv->conn->lmconn, - priv->iq_cb, - LM_MESSAGE_TYPE_IQ); - lm_message_handler_unref (priv->iq_cb); - priv->iq_cb = NULL; - } + g_assert (priv->iq_cb != NULL); + g_assert (priv->presence_cb != NULL); - if (priv->presence_cb) - { - lm_connection_unregister_message_handler (priv->conn->lmconn, - priv->presence_cb, - LM_MESSAGE_TYPE_PRESENCE); - lm_message_handler_unref (priv->presence_cb); - priv->presence_cb = NULL; - } + lm_connection_unregister_message_handler (priv->conn->lmconn, + priv->iq_cb, + LM_MESSAGE_TYPE_IQ); + lm_message_handler_unref (priv->iq_cb); + priv->iq_cb = NULL; + + lm_connection_unregister_message_handler (priv->conn->lmconn, + priv->presence_cb, + LM_MESSAGE_TYPE_PRESENCE); + lm_message_handler_unref (priv->presence_cb); + priv->presence_cb = NULL; } struct foreach_data { @@ -1122,6 +1128,7 @@ gabble_roster_factory_iface_init (gpointer g_iface, TpChannelFactoryIfaceClass *klass = (TpChannelFactoryIfaceClass *) g_iface; klass->close_all = gabble_roster_factory_iface_close_all; + klass->connecting = gabble_roster_factory_iface_connecting; klass->connected = gabble_roster_factory_iface_connected; klass->disconnected = gabble_roster_factory_iface_disconnected; klass->foreach = gabble_roster_factory_iface_foreach; diff --git a/src/tp-channel-factory-iface.c b/src/tp-channel-factory-iface.c index 6519c8141..df62e32d0 100644 --- a/src/tp-channel-factory-iface.c +++ b/src/tp-channel-factory-iface.c @@ -73,6 +73,12 @@ tp_channel_factory_iface_close_all (TpChannelFactoryIface *self) } void +tp_channel_factory_iface_connecting (TpChannelFactoryIface *self) +{ + TP_CHANNEL_FACTORY_IFACE_GET_CLASS (self)->connecting (self); +} + +void tp_channel_factory_iface_connected (TpChannelFactoryIface *self) { TP_CHANNEL_FACTORY_IFACE_GET_CLASS (self)->connected (self); diff --git a/src/tp-channel-factory-iface.h b/src/tp-channel-factory-iface.h index 3e5bb4e74..75befd0f2 100644 --- a/src/tp-channel-factory-iface.h +++ b/src/tp-channel-factory-iface.h @@ -66,6 +66,7 @@ struct _TpChannelFactoryIfaceClass { GTypeInterface parent_class; void (*close_all) (TpChannelFactoryIface *); + void (*connecting) (TpChannelFactoryIface *); void (*connected) (TpChannelFactoryIface *); void (*disconnected) (TpChannelFactoryIface *); void (*foreach) (TpChannelFactoryIface *, TpChannelFunc func, gpointer data); @@ -75,6 +76,7 @@ struct _TpChannelFactoryIfaceClass { GType tp_channel_factory_iface_get_type (void); void tp_channel_factory_iface_close_all (TpChannelFactoryIface *); +void tp_channel_factory_iface_connecting (TpChannelFactoryIface *); void tp_channel_factory_iface_connected (TpChannelFactoryIface *); void tp_channel_factory_iface_disconnected (TpChannelFactoryIface *); void tp_channel_factory_iface_foreach (TpChannelFactoryIface *, TpChannelFunc func, gpointer data); |