changeset 24993:7d2e06b29f88

Add state-changed signal to PurpleMedia.
author Mike Ruprecht <maiku@soc.pidgin.im>
date Mon, 05 Jan 2009 06:34:30 +0000
parents d881fc5d907f
children 50309309bc4d
files libpurple/marshallers.list libpurple/media.c libpurple/media.h libpurple/protocols/jabber/jingle/rtp.c
diffstat 4 files changed, 72 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/marshallers.list	Sun Jan 04 12:13:12 2009 +0000
+++ b/libpurple/marshallers.list	Mon Jan 05 06:34:30 2009 +0000
@@ -2,3 +2,4 @@
 VOID:POINTER,POINTER,OBJECT
 BOOLEAN:OBJECT,POINTER,STRING
 VOID:STRING,STRING
+VOID:ENUM,STRING,STRING
--- a/libpurple/media.c	Sun Jan 04 12:13:12 2009 +0000
+++ b/libpurple/media.c	Mon Jan 05 06:34:30 2009 +0000
@@ -122,6 +122,7 @@
 	CANDIDATE_PAIR,
 	CODECS_READY,
 	READY_NEW,
+	STATE_CHANGED,
 	LAST_SIGNAL
 };
 static guint purple_media_signals[LAST_SIGNAL] = {0};
@@ -155,6 +156,22 @@
 	return type;
 }
 
+GType
+purple_media_state_changed_get_type()
+{
+	static GType type = 0;
+	if (type == 0) {
+		static const GEnumValue values[] = {
+			{ PURPLE_MEDIA_STATE_CHANGED_NEW, "PURPLE_MEDIA_STATE_CHANGED_NEW", "new" },
+			{ PURPLE_MEDIA_STATE_CHANGED_CONNECTED, "PURPLE_MEDIA_STATE_CHANGED_CONNECTED", "connected" },
+			{ PURPLE_MEDIA_STATE_CHANGED_END, "PURPLE_MEDIA_STATE_CHANGED_END", "end" },
+			{ 0, NULL, NULL }
+		};
+		type = g_enum_register_static("PurpleMediaStateChangedType", values);
+	}
+	return type;
+}
+
 static void
 purple_media_class_init (PurpleMediaClass *klass)
 {
@@ -236,6 +253,11 @@
 					 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
 					 purple_smarshal_VOID__STRING_STRING,
 					 G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_STRING);
+	purple_media_signals[STATE_CHANGED] = g_signal_new("state-changed", G_TYPE_FROM_CLASS(klass),
+					 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
+					 purple_smarshal_VOID__ENUM_STRING_STRING,
+					 G_TYPE_NONE, 3, PURPLE_MEDIA_TYPE_STATE_CHANGED,
+					 G_TYPE_STRING, G_TYPE_STRING);
 	g_type_class_add_private(klass, sizeof(PurpleMediaPrivate));
 }
 
@@ -845,12 +867,18 @@
 void
 purple_media_hangup(PurpleMedia *media)
 {
+	g_signal_emit(media, purple_media_signals[STATE_CHANGED],
+			0, PURPLE_MEDIA_STATE_CHANGED_END,
+			NULL, NULL);
 	g_signal_emit(media, purple_media_signals[HANGUP], 0);
 }
 
 void
 purple_media_reject(PurpleMedia *media)
 {
+	g_signal_emit(media, purple_media_signals[STATE_CHANGED],
+			0, PURPLE_MEDIA_STATE_CHANGED_END,
+			NULL, NULL);
 	g_signal_emit(media, purple_media_signals[REJECT], 0);
 }
 
@@ -863,6 +891,9 @@
 void
 purple_media_got_hangup(PurpleMedia *media)
 {
+	g_signal_emit(media, purple_media_signals[STATE_CHANGED],
+			0, PURPLE_MEDIA_STATE_CHANGED_END,
+			NULL, NULL);
 	g_signal_emit(media, purple_media_signals[GOT_HANGUP], 0);
 }
 
@@ -1172,6 +1203,10 @@
 	purple_debug_info("media", "connecting new src pad: %s\n", 
 			  gst_pad_link(srcpad, sinkpad) == GST_PAD_LINK_OK ? "success" : "failure");
 	gst_element_set_state(stream->sink, GST_STATE_PLAYING);
+
+	g_signal_emit(stream->session->media, purple_media_signals[STATE_CHANGED],
+				0, PURPLE_MEDIA_STATE_CHANGED_CONNECTED,
+				stream->session->id, stream->participant);
 }
 
 static gchar *
@@ -1259,12 +1294,19 @@
 		session->type = purple_media_from_fs(type, type_direction);
 
 		purple_media_add_session(media, session);
+		g_signal_emit(media, purple_media_signals[STATE_CHANGED],
+				0, PURPLE_MEDIA_STATE_CHANGED_NEW,
+				session->id, NULL);
 	}
 
 	if (!(participant = purple_media_add_participant(media, who))) {
 		purple_media_remove_session(media, session);
 		g_free(session);
 		return FALSE;
+	} else {
+		g_signal_emit(media, purple_media_signals[STATE_CHANGED],
+				0, PURPLE_MEDIA_STATE_CHANGED_NEW,
+				NULL, who);
 	}
 
 	stream = purple_media_get_stream(media, sess_id, who);
@@ -1310,6 +1352,9 @@
 		g_signal_connect(G_OBJECT(fsstream),
 				 "src-pad-added", G_CALLBACK(purple_media_src_pad_added_cb), stream);
 
+		g_signal_emit(media, purple_media_signals[STATE_CHANGED],
+				0, PURPLE_MEDIA_STATE_CHANGED_NEW,
+				session->id, who);
 	} else if (*direction != type_direction) {	
 		/* change direction */
 		g_object_set(stream->stream, "direction", type_direction, NULL);
@@ -1350,7 +1395,7 @@
 void
 purple_media_remove_stream(PurpleMedia *media, const gchar *sess_id, const gchar *who)
 {
-	
+	/* Add state-changed end emits in here when this is implemented */
 }
 
 PurpleMediaSessionType
--- a/libpurple/media.h	Sun Jan 04 12:13:12 2009 +0000
+++ b/libpurple/media.h	Mon Jan 05 06:34:30 2009 +0000
@@ -45,6 +45,8 @@
 #define PURPLE_IS_MEDIA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), PURPLE_TYPE_MEDIA))
 #define PURPLE_MEDIA_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj), PURPLE_TYPE_MEDIA, PurpleMediaClass))
 
+#define PURPLE_MEDIA_TYPE_STATE_CHANGED	(purple_media_state_changed_get_type())
+
 /** @copydoc _PurpleMedia */
 typedef struct _PurpleMedia PurpleMedia;
 /** @copydoc _PurpleMediaClass */
@@ -69,6 +71,13 @@
 	PURPLE_MEDIA_VIDEO = PURPLE_MEDIA_RECV_VIDEO | PURPLE_MEDIA_SEND_VIDEO
 } PurpleMediaSessionType;
 
+/** Media state-changed types */
+typedef enum {
+	PURPLE_MEDIA_STATE_CHANGED_NEW = 0,
+	PURPLE_MEDIA_STATE_CHANGED_CONNECTED,
+	PURPLE_MEDIA_STATE_CHANGED_END,
+} PurpleMediaStateChangedType;
+
 #ifdef USE_VV
 
 /** The media class */
@@ -95,6 +104,13 @@
  */
 GType purple_media_get_type(void);
 
+/**
+ * Gets the type of the state-changed enum
+ *
+ * @return The state-changed enum's GType
+ */
+GType purple_media_state_changed_get_type(void);
+
 /**************************************************************************/
 /** @name Media Utility Functions                                         */
 /**************************************************************************/
--- a/libpurple/protocols/jabber/jingle/rtp.c	Sun Jan 04 12:13:12 2009 +0000
+++ b/libpurple/protocols/jabber/jingle/rtp.c	Mon Jan 05 06:34:30 2009 +0000
@@ -329,6 +329,13 @@
 	}
 }
 
+static void
+jingle_rtp_state_changed_cb(PurpleMedia *media, PurpleMediaStateChangedType type,
+		gchar *sid, gchar *name, JingleSession *session)
+{
+	purple_debug_info("jingle-rtp", "state-changed: type %d id: %s name: %s\n", type, sid, name);
+}
+
 static PurpleMedia *
 jingle_rtp_create_media(JingleContent *content)
 {
@@ -368,6 +375,8 @@
 				 G_CALLBACK(jingle_rtp_candidate_pair_established_cb), session);
 	g_signal_connect(G_OBJECT(media), "ready-new",
 				 G_CALLBACK(jingle_rtp_ready_cb), session);
+	g_signal_connect(G_OBJECT(media), "state-changed",
+				 G_CALLBACK(jingle_rtp_state_changed_cb), session);
 
 	g_object_unref(session);
 	return media;