Commit 410315b3 authored by Andy Wingo Wingo's avatar Andy Wingo Wingo

gst/gstbus.c (gst_bus_remove_signal_watch): New function, removes signal...

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  <wingo@pobox.com>

* 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.
parent 52b24de9
......@@ -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
<SUBSECTION Standard>
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
......
......@@ -27,6 +27,9 @@ network connections also need a protocol to do this.
#GstBuffer, #GstCaps, #GstEvent
</para>
<!-- ##### SECTION Stability_Level ##### -->
<!-- ##### ENUM GstDPHeaderFlag ##### -->
<para>
......
......@@ -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;
}
}
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment