[Telepathy-commits] [telepathy-gabble/master] add object argument to gabble_bytestream_factory_negotiate_stream

Guillaume Desmottes guillaume.desmottes at collabora.co.uk
Mon Feb 23 07:20:22 PST 2009


---
 src/bytestream-factory.c |   36 ++++++++++++++++++++++++++++++++++++
 src/bytestream-factory.h |    2 +-
 2 files changed, 37 insertions(+), 1 deletions(-)

diff --git a/src/bytestream-factory.c b/src/bytestream-factory.c
index ccb52b7..7e87961 100644
--- a/src/bytestream-factory.c
+++ b/src/bytestream-factory.c
@@ -1446,8 +1446,21 @@ struct _streaminit_reply_cb_data
   gchar *stream_id;
   GabbleBytestreamFactoryNegotiateReplyFunc func;
   gpointer user_data;
+  GObject *object;
+  gboolean object_alive;
 };
 
+static void
+negotiate_stream_object_destroy_notify_cb (gpointer _data,
+                                           GObject *where_the_object_was)
+{
+  struct _streaminit_reply_cb_data *data =
+    (struct _streaminit_reply_cb_data*) _data;
+
+  data->object = NULL;
+  data->object_alive = FALSE;
+}
+
 /* Called when we receive the reply of a SI request */
 static LmHandlerResult
 streaminit_reply_cb (GabbleConnection *conn,
@@ -1470,6 +1483,18 @@ streaminit_reply_cb (GabbleConnection *conn,
   TpHandle peer_handle = 0;
   gboolean success = FALSE;
 
+  if (data->object != NULL)
+    {
+      g_object_weak_unref (data->object,
+          negotiate_stream_object_destroy_notify_cb, data);
+    }
+
+  if (!data->object_alive)
+    {
+      DEBUG ("Object which requested the bytestream was disposed. Ignoring");
+      return LM_HANDLER_RESULT_REMOVE_MESSAGE;
+    }
+
   if (lm_message_get_sub_type (reply_msg) != LM_MESSAGE_SUB_TYPE_RESULT)
     {
       DEBUG ("stream %s declined", data->stream_id);
@@ -1557,6 +1582,8 @@ END:
  * @stream_id: the stream identifier
  * @func: the callback to call when we receive the answser of the request
  * @user_data: user data to pass to the callback
+ * @object: if non-NULL the handler will follow the lifetime of that object,
+ * which means that if the object is destroyed the callback will not be invoked.
  * @error: pointer in which to return a GError in case of failure.
  *
  * Send a Stream Initiation (XEP-0095) request.
@@ -1567,6 +1594,7 @@ gabble_bytestream_factory_negotiate_stream (GabbleBytestreamFactory *self,
                                             const gchar *stream_id,
                                             GabbleBytestreamFactoryNegotiateReplyFunc func,
                                             gpointer user_data,
+                                            GObject *object,
                                             GError **error)
 {
   GabbleBytestreamFactoryPrivate *priv;
@@ -1583,6 +1611,14 @@ gabble_bytestream_factory_negotiate_stream (GabbleBytestreamFactory *self,
   data->stream_id = g_strdup (stream_id);
   data->func = func;
   data->user_data = user_data;
+  data->object_alive = TRUE;
+  data->object = object;
+
+  if (object != NULL)
+    {
+      g_object_weak_ref (object, negotiate_stream_object_destroy_notify_cb,
+          data);
+    }
 
   result = _gabble_connection_send_with_reply (priv->conn, msg,
       streaminit_reply_cb, G_OBJECT (self), data, error);
diff --git a/src/bytestream-factory.h b/src/bytestream-factory.h
index 8751ac0..be0012f 100644
--- a/src/bytestream-factory.h
+++ b/src/bytestream-factory.h
@@ -95,7 +95,7 @@ LmMessage *gabble_bytestream_factory_make_multi_accept_iq (
 gboolean gabble_bytestream_factory_negotiate_stream (
     GabbleBytestreamFactory *fac, LmMessage *msg, const gchar *stream_id,
     GabbleBytestreamFactoryNegotiateReplyFunc func,
-    gpointer user_data, GError **error);
+    gpointer user_data, GObject *object, GError **error);
 
 gchar *gabble_bytestream_factory_generate_stream_id (void);
 
-- 
1.5.6.5




More information about the telepathy-commits mailing list