[PATCH 2/3] media: make "init-media" signal handler optional

David Woodhouse dwmw2 at infradead.org
Fri Mar 13 10:47:08 EDT 2015


Change the logic so that the PurpleMedia instance isn't disposed when
"init-media" has no connected handlers.

We want the media object freed only when some signal callback function
explicitly returns FALSE, indicating an error during the initialization.

This is mostly useful for the imminent addition of private media streams.
---
 libpurple/mediamanager.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/libpurple/mediamanager.c b/libpurple/mediamanager.c
index 6b31289..79d0806 100644
--- a/libpurple/mediamanager.c
+++ b/libpurple/mediamanager.c
@@ -313,7 +313,7 @@ purple_media_manager_create_media(PurpleMediaManager *manager,
 {
 #ifdef USE_VV
 	PurpleMedia *media;
-	gboolean signal_ret;
+	guint signal_id;
 
 	media = PURPLE_MEDIA(g_object_new(purple_media_get_type(),
 			     "manager", manager,
@@ -322,12 +322,17 @@ purple_media_manager_create_media(PurpleMediaManager *manager,
 			     "initiator", initiator,
 			     NULL));
 
-	g_signal_emit(manager, purple_media_manager_signals[INIT_MEDIA], 0,
-			media, account, remote_user, &signal_ret);
+	signal_id = purple_media_manager_signals[INIT_MEDIA];
 
-	if (signal_ret == FALSE) {
-		g_object_unref(media);
-		return NULL;
+	if (g_signal_has_handler_pending(manager, signal_id, 0, FALSE)) {
+		gboolean signal_ret;
+
+		g_signal_emit(manager, signal_id, 0, media, account, remote_user,
+				&signal_ret);
+		if (signal_ret == FALSE) {
+			g_object_unref(media);
+			return NULL;
+		}
 	}
 
 	manager->priv->medias = g_list_append(manager->priv->medias, media);
-- 
2.1.0


-- 
David Woodhouse                            Open Source Technology Centre
David.Woodhouse at intel.com                              Intel Corporation
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 5745 bytes
Desc: not available
URL: <https://pidgin.im/pipermail/devel/attachments/20150313/e410aac7/attachment-0001.bin>


More information about the Devel mailing list