changeset 29169:98a1b62a0f7e

Add participant creation and destruction to the Fs2 media backend.
author maiku@pidgin.im
date Mon, 26 Oct 2009 20:00:00 +0000
parents 1156bf88b4d3
children 7b0931b3e060
files libpurple/media/backend-fs2.c libpurple/media/backend-fs2.h
diffstat 2 files changed, 77 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/media/backend-fs2.c	Mon Oct 26 19:11:29 2009 +0000
+++ b/libpurple/media/backend-fs2.c	Mon Oct 26 20:00:00 2009 +0000
@@ -110,6 +110,7 @@
 	gchar *conference_type;
 
 	GHashTable *sessions;
+	GHashTable *participants;
 };
 
 enum {
@@ -176,6 +177,15 @@
 		}
 	}
 
+	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 @@
 	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
+_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 @@
 		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 @@
 	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);
+}
--- a/libpurple/media/backend-fs2.h	Mon Oct 26 19:11:29 2009 +0000
+++ b/libpurple/media/backend-fs2.h	Mon Oct 26 20:00:00 2009 +0000
@@ -65,6 +65,9 @@
 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