cpw.maiku.media_refactor: 72a18ec4: Add participant creation and destruction...

maiku at pidgin.im maiku at pidgin.im
Mon Oct 26 22:46:00 EDT 2009


-----------------------------------------------------------------
Revision: 72a18ec43a3d2df1852c024e9f8e225560c2773a
Ancestor: d311a2216e2c5b72132d6c66f527620ffe65d2c8
Author: maiku at pidgin.im
Date: 2009-10-26T20:00:00
Branch: im.pidgin.cpw.maiku.media_refactor
URL: http://d.pidgin.im/viewmtn/revision/info/72a18ec43a3d2df1852c024e9f8e225560c2773a

Modified files:
        libpurple/media/backend-fs2.c libpurple/media/backend-fs2.h

ChangeLog: 

Add participant creation and destruction to the Fs2 media backend.

-------------- next part --------------
============================================================
--- libpurple/media/backend-fs2.c	a509a884a78b939763cd8413c1422e0c0643eeb3
+++ libpurple/media/backend-fs2.c	423de3e611b07d1c7a74673687e5750038962e98
@@ -110,6 +110,7 @@ struct _PurpleMediaBackendFs2Private
 	gchar *conference_type;
 
 	GHashTable *sessions;
+	GHashTable *participants;
 };
 
 enum {
@@ -176,6 +177,15 @@ purple_media_backend_fs2_dispose(GObject
 		}
 	}
 
+	if (priv->participants) {
+		GList *participants =
+				g_hash_table_get_values(priv->participants);
+		for (; participants; participants = g_list_delete_link(
+				participants, participants))
+			g_object_unref(participants->data);
+		priv->participants = NULL;
+	}
+
 	if (priv->media) {
 		g_object_remove_weak_pointer(G_OBJECT(priv->media),
 				(gpointer*)&priv->media);
@@ -437,6 +447,22 @@ _get_session(PurpleMediaBackendFs2 *self
 	return session;
 }
 
+static FsParticipant *
+_get_participant(PurpleMediaBackendFs2 *self, const gchar *name)
+{
+	PurpleMediaBackendFs2Private *priv;
+	FsParticipant *participant = NULL;
+
+	g_return_val_if_fail(PURPLE_IS_MEDIA_BACKEND_FS2(self), NULL);
+
+	priv = PURPLE_MEDIA_BACKEND_FS2_GET_PRIVATE(self);
+
+	if (priv->participants != NULL)
+		participant = g_hash_table_lookup(priv->participants, name);
+
+	return participant;
+}
+
 static PurpleMediaBackendFs2Session *
 _get_session_from_fs_stream(PurpleMediaBackendFs2 *self, FsStream *stream)
 {
@@ -963,6 +989,40 @@ static gboolean
 }
 
 static gboolean
+_create_participant(PurpleMediaBackendFs2 *self, const gchar *name)
+{
+	PurpleMediaBackendFs2Private *priv =
+			PURPLE_MEDIA_BACKEND_FS2_GET_PRIVATE(self);
+	FsParticipant *participant;
+	GError *err = NULL;
+
+	participant = fs_conference_new_participant(
+			priv->conference, name, &err);
+
+	if (err) {
+		purple_debug_error("backend-fs2",
+				"Error creating participant: %s\n",
+				err->message);
+		g_error_free(err);
+		return FALSE;
+	}
+
+	if (!priv->participants) {
+		purple_debug_info("backend-fs2",
+				"Creating hash table for participants\n");
+		priv->participants = g_hash_table_new_full(g_str_hash,
+				g_str_equal, g_free, NULL);
+	}
+
+	g_hash_table_insert(priv->participants, g_strdup(name), participant);
+
+	g_signal_emit_by_name(priv->media, "state-changed",
+			PURPLE_MEDIA_STATE_NEW, NULL, name);
+
+	return TRUE;
+}
+
+static gboolean
 purple_media_backend_fs2_add_stream(PurpleMediaBackend *self,
 		const gchar *sess_id, const gchar *who,
 		PurpleMediaSessionType type, gboolean initiator,
@@ -987,6 +1047,13 @@ purple_media_backend_fs2_add_stream(Purp
 		return FALSE;
 	}
 
+	if (_get_participant(backend, who) == NULL &&
+			!_create_participant(backend, who)) {
+		purple_debug_error("backend-fs2",
+				"Error creating the participant.\n");
+		return FALSE;
+	}
+
 	return TRUE;
 }
 
@@ -1039,3 +1106,10 @@ purple_media_backend_fs2_get_session(Pur
 	PurpleMediaBackendFs2Session *session = _get_session(self, sess_id);
 	return session != NULL? session->session : NULL;
 }
+
+FsParticipant *
+purple_media_backend_fs2_get_participant(PurpleMediaBackendFs2 *self,
+		const gchar *name)
+{
+	return _get_participant(self, name);
+}
============================================================
--- libpurple/media/backend-fs2.h	2fdfd0db572646b9c422dd07c84dbe19ba30c7a2
+++ libpurple/media/backend-fs2.h	73a1ac762bed68a708bb7111205a88ae028dd1c1
@@ -65,6 +65,9 @@ FsSession *purple_media_backend_fs2_get_
 FsSession *purple_media_backend_fs2_get_session(
 		PurpleMediaBackendFs2 *self,
 		const gchar *sess_id);
+FsParticipant *purple_media_backend_fs2_get_participant(
+		PurpleMediaBackendFs2 *self,
+		const gchar *name);
 /* end tmp */
 
 G_END_DECLS


More information about the Commits mailing list