From 410315b375e69d095e39254c8ec476bfd14aa6b6 Mon Sep 17 00:00:00 2001 From: Andy Wingo Date: Thu, 29 Sep 2005 16:04:31 +0000 Subject: [PATCH] gst/gstbus.c (gst_bus_remove_signal_watch): New function, removes signal watches previously added via gst_bus_add_sig... Original commit message from CVS: 2005-09-29 Andy Wingo * gst/gstbus.c (gst_bus_remove_signal_watch): New function, removes signal watches previously added via gst_bus_add_signal_watch. (gst_bus_add_signal_watch): Don't return the source id, just store it on the bus if there wasn't an id already. * gst/gstbus.h (GstBus): Add a couple new fields. API changes for add_signal_watch and remove_signal_watch. --- docs/gst/gstreamer-sections.txt | 7 ++++ docs/libs/tmpl/gstdataprotocol.sgml | 3 ++ gst/gstbus.c | 68 +++++++++++++++++++++++++++++++++---- gst/gstbus.h | 9 +++-- 4 files changed, 78 insertions(+), 9 deletions(-) diff --git a/docs/gst/gstreamer-sections.txt b/docs/gst/gstreamer-sections.txt index 313c721..c37a1b1 100644 --- a/docs/gst/gstreamer-sections.txt +++ b/docs/gst/gstreamer-sections.txt @@ -92,9 +92,13 @@ gst_bus_peek gst_bus_pop gst_bus_set_flushing gst_bus_set_sync_handler +gst_bus_sync_signal_handler gst_bus_create_watch gst_bus_add_watch_full gst_bus_add_watch +gst_bus_async_signal_func +gst_bus_add_signal_watch +gst_bus_remove_signal_watch gst_bus_poll GstBusClass @@ -488,6 +492,7 @@ gst_element_lost_state gst_element_message_full gst_element_no_more_pads gst_element_post_message +gst_element_provide_clock gst_element_provides_clock gst_element_query gst_element_query_convert @@ -969,6 +974,8 @@ GST_MESSAGE_TRACE_NAME GST_MESSAGE_TYPE GST_MESSAGE_UNLOCK GST_MESSAGE_WAIT +gst_message_type_to_quark +gst_message_type_get_name gst_message_copy gst_message_get_structure gst_message_make_writable diff --git a/docs/libs/tmpl/gstdataprotocol.sgml b/docs/libs/tmpl/gstdataprotocol.sgml index 0277c7c..c5446c9 100644 --- a/docs/libs/tmpl/gstdataprotocol.sgml +++ b/docs/libs/tmpl/gstdataprotocol.sgml @@ -27,6 +27,9 @@ network connections also need a protocol to do this. #GstBuffer, #GstCaps, #GstEvent + + + diff --git a/gst/gstbus.c b/gst/gstbus.c index f1a2868..4abd3e6 100644 --- a/gst/gstbus.c +++ b/gst/gstbus.c @@ -867,22 +867,76 @@ gst_bus_sync_signal_handler (GstBus * bus, GstMessage * message, gpointer data) /** * gst_bus_add_signal_watch: - * @bus: a #GstBus to create the watch for + * @bus: a #GstBus on which you want to recieve the "message" signal * * Adds a bus signal watch to the default main context with the default priority. * After calling this statement, the bus will emit the message signal for each * message posted on the bus. * - * The watch can be removed using #g_source_remove(). - * - * Returns: The event source id. + * This function may be called multiple times. To clean up, the caller is + * responsible for calling gst_bus_remove_signal_watch() as many times as this + * function is called. * * MT safe. */ -guint +void gst_bus_add_signal_watch (GstBus * bus) { - g_return_val_if_fail (GST_IS_BUS (bus), 0); + g_return_if_fail (GST_IS_BUS (bus)); + + /* I know the callees don't take this lock, so go ahead and abuse it */ + GST_LOCK (bus); - return gst_bus_add_watch (bus, gst_bus_async_signal_func, NULL); + if (bus->num_signal_watchers > 0) + goto done; + + g_assert (bus->signal_watch_id == 0); + + bus->signal_watch_id = + gst_bus_add_watch (bus, gst_bus_async_signal_func, NULL); + +done: + + bus->num_signal_watchers++; + + GST_UNLOCK (bus); +} + +/** + * gst_bus_remove_signal_watch: + * @bus: a #GstBus you previously added a signal watch to + * + * Removes a signal watch previously added with gst_bus_add_signal_watch(). + * + * MT safe. + */ +void +gst_bus_remove_signal_watch (GstBus * bus) +{ + g_return_if_fail (GST_IS_BUS (bus)); + + /* I know the callees don't take this lock, so go ahead and abuse it */ + GST_LOCK (bus); + + if (bus->num_signal_watchers == 0) + goto error; + + bus->num_signal_watchers--; + + if (bus->num_signal_watchers > 0) + goto done; + + g_source_remove (bus->signal_watch_id); + bus->signal_watch_id = 0; + +done: + GST_UNLOCK (bus); + return; + +error: + { + g_critical ("Bus %s has no signal watches attached", GST_OBJECT_NAME (bus)); + GST_UNLOCK (bus); + return; + } } diff --git a/gst/gstbus.h b/gst/gstbus.h index f7f2fea..9bbb719 100644 --- a/gst/gstbus.h +++ b/gst/gstbus.h @@ -94,6 +94,9 @@ struct _GstBus GstBusSyncHandler sync_handler; gpointer sync_handler_data; + guint signal_watch_id; + guint num_signal_watchers; + /*< private > */ gpointer _gst_reserved[GST_PADDING]; }; @@ -144,8 +147,10 @@ gboolean gst_bus_async_signal_func (GstBus *bus, GstMessage *message, gpointer data); GstBusSyncReply gst_bus_sync_signal_handler (GstBus *bus, GstMessage *message, gpointer data); -/* add watch that dispatches signals */ -guint gst_bus_add_signal_watch (GstBus * bus); + +/* convenience api to add/remove a gsource that emits the async signals */ +void gst_bus_add_signal_watch (GstBus * bus); +void gst_bus_remove_signal_watch (GstBus * bus); G_END_DECLS -- 2.7.4