gstbus.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /* GStreamer
  2. * Copyright (C) 2004 Wim Taymans <wim@fluendo.com>
  3. *
  4. * gstbus.h: Header for GstBus subsystem
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Library General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Library General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Library General Public
  17. * License along with this library; if not, write to the
  18. * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
  19. * Boston, MA 02110-1301, USA.
  20. */
  21. #ifndef __GST_BUS_H__
  22. #define __GST_BUS_H__
  23. typedef struct _GstBus GstBus;
  24. typedef struct _GstBusPrivate GstBusPrivate;
  25. typedef struct _GstBusClass GstBusClass;
  26. #include <gst/gstmessage.h>
  27. #include <gst/gstclock.h>
  28. G_BEGIN_DECLS
  29. /* --- standard type macros --- */
  30. #define GST_TYPE_BUS (gst_bus_get_type ())
  31. #define GST_BUS(bus) (G_TYPE_CHECK_INSTANCE_CAST ((bus), GST_TYPE_BUS, GstBus))
  32. #define GST_IS_BUS(bus) (G_TYPE_CHECK_INSTANCE_TYPE ((bus), GST_TYPE_BUS))
  33. #define GST_BUS_CLASS(bclass) (G_TYPE_CHECK_CLASS_CAST ((bclass), GST_TYPE_BUS, GstBusClass))
  34. #define GST_IS_BUS_CLASS(bclass) (G_TYPE_CHECK_CLASS_TYPE ((bclass), GST_TYPE_BUS))
  35. #define GST_BUS_GET_CLASS(bus) (G_TYPE_INSTANCE_GET_CLASS ((bus), GST_TYPE_BUS, GstBusClass))
  36. #define GST_BUS_CAST(bus) ((GstBus*)(bus))
  37. /**
  38. * GstBusFlags:
  39. * @GST_BUS_FLUSHING: The bus is currently dropping all messages
  40. * @GST_BUS_FLAG_LAST: offset to define more flags
  41. *
  42. * The standard flags that a bus may have.
  43. */
  44. typedef enum {
  45. GST_BUS_FLUSHING = (GST_OBJECT_FLAG_LAST << 0),
  46. /* padding */
  47. GST_BUS_FLAG_LAST = (GST_OBJECT_FLAG_LAST << 1)
  48. } GstBusFlags;
  49. /**
  50. * GstBusSyncReply:
  51. * @GST_BUS_DROP: drop the message
  52. * @GST_BUS_PASS: pass the message to the async queue
  53. * @GST_BUS_ASYNC: pass message to async queue, continue if message is handled
  54. *
  55. * The result values for a GstBusSyncHandler.
  56. */
  57. typedef enum
  58. {
  59. GST_BUS_DROP = 0,
  60. GST_BUS_PASS = 1,
  61. GST_BUS_ASYNC = 2
  62. } GstBusSyncReply;
  63. /**
  64. * GstBusSyncHandler:
  65. * @bus: the #GstBus that sent the message
  66. * @message: the #GstMessage
  67. * @user_data: user data that has been given, when registering the handler
  68. *
  69. * Handler will be invoked synchronously, when a new message has been injected
  70. * into the bus. This function is mostly used internally. Only one sync handler
  71. * can be attached to a given bus.
  72. *
  73. * If the handler returns GST_BUS_DROP, it should unref the message, else the
  74. * message should not be unreffed by the sync handler.
  75. *
  76. * Returns: #GstBusSyncReply stating what to do with the message
  77. */
  78. typedef GstBusSyncReply (*GstBusSyncHandler) (GstBus * bus, GstMessage * message, gpointer user_data);
  79. /**
  80. * GstBusFunc:
  81. * @bus: the #GstBus that sent the message
  82. * @message: the #GstMessage
  83. * @user_data: user data that has been given, when registering the handler
  84. *
  85. * Specifies the type of function passed to gst_bus_add_watch() or
  86. * gst_bus_add_watch_full(), which is called from the mainloop when a message
  87. * is available on the bus.
  88. *
  89. * The message passed to the function will be unreffed after execution of this
  90. * function so it should not be freed in the function.
  91. *
  92. * Note that this function is used as a GSourceFunc which means that returning
  93. * %FALSE will remove the GSource from the mainloop.
  94. *
  95. * Returns: %FALSE if the event source should be removed.
  96. */
  97. typedef gboolean (*GstBusFunc) (GstBus * bus, GstMessage * message, gpointer user_data);
  98. /**
  99. * GstBus:
  100. *
  101. * The opaque #GstBus data structure.
  102. */
  103. struct _GstBus
  104. {
  105. GstObject object;
  106. /*< private >*/
  107. GstBusPrivate *priv;
  108. gpointer _gst_reserved[GST_PADDING];
  109. };
  110. struct _GstBusClass
  111. {
  112. GstObjectClass parent_class;
  113. /* signals */
  114. void (*message) (GstBus *bus, GstMessage *message);
  115. void (*sync_message) (GstBus *bus, GstMessage *message);
  116. /*< private >*/
  117. gpointer _gst_reserved[GST_PADDING];
  118. };
  119. GType gst_bus_get_type (void);
  120. GstBus* gst_bus_new (void);
  121. gboolean gst_bus_post (GstBus * bus, GstMessage * message);
  122. gboolean gst_bus_have_pending (GstBus * bus);
  123. GstMessage * gst_bus_peek (GstBus * bus);
  124. GstMessage * gst_bus_pop (GstBus * bus);
  125. GstMessage * gst_bus_pop_filtered (GstBus * bus, GstMessageType types);
  126. GstMessage * gst_bus_timed_pop (GstBus * bus, GstClockTime timeout);
  127. GstMessage * gst_bus_timed_pop_filtered (GstBus * bus, GstClockTime timeout, GstMessageType types);
  128. void gst_bus_set_flushing (GstBus * bus, gboolean flushing);
  129. /* synchronous dispatching */
  130. void gst_bus_set_sync_handler (GstBus * bus, GstBusSyncHandler func,
  131. gpointer user_data, GDestroyNotify notify);
  132. /* GSource based dispatching */
  133. GSource * gst_bus_create_watch (GstBus * bus);
  134. guint gst_bus_add_watch_full (GstBus * bus,
  135. gint priority,
  136. GstBusFunc func,
  137. gpointer user_data,
  138. GDestroyNotify notify);
  139. guint gst_bus_add_watch (GstBus * bus,
  140. GstBusFunc func,
  141. gpointer user_data);
  142. gboolean gst_bus_remove_watch (GstBus * bus);
  143. /* polling the bus */
  144. GstMessage* gst_bus_poll (GstBus *bus, GstMessageType events,
  145. GstClockTime timeout);
  146. /* signal based dispatching helper functions. */
  147. gboolean gst_bus_async_signal_func (GstBus *bus, GstMessage *message,
  148. gpointer data);
  149. GstBusSyncReply gst_bus_sync_signal_handler (GstBus *bus, GstMessage *message,
  150. gpointer data);
  151. /* convenience api to add/remove a gsource that emits the async signals */
  152. void gst_bus_add_signal_watch (GstBus * bus);
  153. void gst_bus_add_signal_watch_full (GstBus * bus, gint priority);
  154. void gst_bus_remove_signal_watch (GstBus * bus);
  155. void gst_bus_enable_sync_message_emission (GstBus * bus);
  156. void gst_bus_disable_sync_message_emission (GstBus * bus);
  157. #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC
  158. G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstBus, gst_object_unref)
  159. #endif
  160. G_END_DECLS
  161. #endif /* __GST_BUS_H__ */