bus: Add a function to remove a bus watch

If a bus watch is added to the non default main context it's not
possible to remove it using g_source_remove().

Fixes: https://bugzilla.gnome.org/show_bug.cgi?id=735195
This commit is contained in:
Linus Svensson 2014-08-19 23:28:52 +02:00 committed by Sebastian Dröge
parent 8bf0cbf4a8
commit c8b512d2f0
4 changed files with 48 additions and 5 deletions

View file

@ -897,8 +897,9 @@ gst_bus_add_watch_full_unlocked (GstBus * bus, gint priority,
* When @func is called, the message belongs to the caller; if you want to
* keep a copy of it, call gst_message_ref() before leaving @func.
*
* The watch can be removed using g_source_remove() or by returning %FALSE
* from @func.
* The watch can be removed using gst_bus_remove_watch() or by returning %FALSE
* from @func. If the watch was added to the default main context it is also
* possible to remove the watch using g_source_remove().
*
* MT safe.
*
@ -936,8 +937,9 @@ gst_bus_add_watch_full (GstBus * bus, gint priority,
* There can only be a single bus watch per bus, you must remove it before you
* can set a new one.
*
* The watch can be removed using g_source_remove() or by returning %FALSE
* from @func.
* The watch can be removed using gst_bus_remove_watch() or by returning %FALSE
* from @func. If the watch was added to the default main context it is also
* possible to remove the watch using g_source_remove().
*
* Returns: The event source id or 0 if @bus already got an event source.
*
@ -950,6 +952,45 @@ gst_bus_add_watch (GstBus * bus, GstBusFunc func, gpointer user_data)
user_data, NULL);
}
/**
* gst_bus_remove_watch:
* @bus: a #GstBus to remove the watch from.
*
* Removes an installed bus watch from @bus.
*
* Returns: %TRUE on success or %FALSE if @bus has no event source.
*
* Since: 1.6
*
*/
gboolean
gst_bus_remove_watch (GstBus * bus)
{
GSource *watch_id;
g_return_val_if_fail (GST_IS_BUS (bus), FALSE);
GST_OBJECT_LOCK (bus);
if (bus->priv->signal_watch == NULL) {
GST_ERROR_OBJECT (bus, "no bus watch was present");
goto no_watch;
}
watch_id = bus->priv->signal_watch;
GST_OBJECT_UNLOCK (bus);
g_source_destroy (watch_id);
return TRUE;
no_watch:
GST_OBJECT_UNLOCK (bus);
return FALSE;
}
typedef struct
{
GMainLoop *loop;

View file

@ -159,6 +159,7 @@ guint gst_bus_add_watch_full (GstBus * bus,
guint gst_bus_add_watch (GstBus * bus,
GstBusFunc func,
gpointer user_data);
gboolean gst_bus_remove_watch (GstBus * bus);
/* polling the bus */
GstMessage* gst_bus_poll (GstBus *bus, GstMessageType events,

View file

@ -188,7 +188,7 @@ GST_START_TEST (test_watch)
fail_unless_equals_int (num_eos, 10);
fail_unless_equals_int (num_app, 10);
g_source_remove (id);
fail_unless (gst_bus_remove_watch (test_bus));
g_main_loop_unref (main_loop);
gst_object_unref ((GstObject *) test_bus);

View file

@ -206,6 +206,7 @@ EXPORTS
gst_bus_pop_filtered
gst_bus_post
gst_bus_remove_signal_watch
gst_bus_remove_watch
gst_bus_set_flushing
gst_bus_set_sync_handler
gst_bus_sync_reply_get_type