gstbus.h 4.95 KB
Newer Older
Wim Taymans's avatar
Wim Taymans committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/* GStreamer
 * Copyright (C) 2004 Wim Taymans <wim@fluendo.com>
 *
 * gstbus.h: Header for GstBus subsystem
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#ifndef __GST_BUS_H__
#define __GST_BUS_H__

Wim Taymans's avatar
Wim Taymans committed
25 26 27
typedef struct _GstBus GstBus;
typedef struct _GstBusClass GstBusClass;

Wim Taymans's avatar
Wim Taymans committed
28 29 30 31 32 33 34 35 36 37 38 39 40 41
#include <gst/gstmessage.h>
#include <gst/gstclock.h>

G_BEGIN_DECLS

/* --- standard type macros --- */
#define GST_TYPE_BUS              (gst_bus_get_type ())
#define GST_BUS(bus)              (G_TYPE_CHECK_INSTANCE_CAST ((bus), GST_TYPE_BUS, GstBus))
#define GST_IS_BUS(bus)           (G_TYPE_CHECK_INSTANCE_TYPE ((bus), GST_TYPE_BUS))
#define GST_BUS_CLASS(bclass)     (G_TYPE_CHECK_CLASS_CAST ((bclass), GST_TYPE_BUS, GstBusClass))
#define GST_IS_BUS_CLASS(bclass)  (G_TYPE_CHECK_CLASS_TYPE ((bclass), GST_TYPE_BUS))
#define GST_BUS_GET_CLASS(bus)    (G_TYPE_INSTANCE_GET_CLASS ((bus), GST_TYPE_BUS, GstBusClass))
#define GST_BUS_CAST(bus)         ((GstBus*)(bus))

42 43 44 45 46 47
typedef enum {
  GST_BUS_FLUSHING		= GST_OBJECT_FLAG_LAST,

  GST_BUS_FLAG_LAST		= GST_OBJECT_FLAG_LAST + 1
} GstBusFlags;

Wim Taymans's avatar
Wim Taymans committed
48 49 50 51 52 53 54
typedef enum
{
  GST_BUS_DROP = 0,             /* drop message */
  GST_BUS_PASS = 1,             /* pass message to async queue */
  GST_BUS_ASYNC = 2,            /* pass message to async queue, continue if message is handled */
} GstBusSyncReply;

55 56 57
/**
 * GstBusSyncHandler:
 * @bus: the #GstBus that sent the message
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
58
 * @message: the #GstMessage
59 60 61
 * @data: user data that has been given, when registering the handler
 *
 * Handler will be invoked synchronously, when a new message has been injected
62 63
 * into the bus. This function is mostly used internally. Only one sync handler
 * can be attached to a given bus.
64 65 66
 *
 * Returns: #GstBusSyncReply stating what to do with the message
 */
67 68
typedef GstBusSyncReply (*GstBusSyncHandler) 	(GstBus * bus, GstMessage * message, gpointer data);

69
/**
70
 * GstBusFunc:
71
 * @bus: the #GstBus that sent the message
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
72
 * @message: the #GstMessage
73 74
 * @data: user data that has been given, when registering the handler
 *
75 76 77 78 79 80
 * Specifies the type of function passed to #gst_bus_add_watch() or 
 * #gst_bus_add_watch_full(), which is called from the mainloop when a message
 * is available on the bus.
 *
 * The message passed to the function will be unreffed after execution of this
 * function so it should not be freed in the function. 
81
 *
82
 * Returns: %FALSE if the event source should be removed. 
83
 */
84
typedef gboolean 	(*GstBusFunc)	 	(GstBus * bus, GstMessage * message, gpointer data);
Wim Taymans's avatar
Wim Taymans committed
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104

struct _GstBus
{
  GstObject 	    object;

  /*< private > */
  GQueue           *queue;
  GMutex           *queue_lock;

  GstBusSyncHandler sync_handler;
  gpointer 	    sync_handler_data;

  /*< private > */
  gpointer _gst_reserved[GST_PADDING];
};

struct _GstBusClass
{
  GstObjectClass parent_class;

105
  /* signals */
106 107
  void (*message)  	(GstBus *bus, GstMessage *message);
  void (*sync_message)  (GstBus *bus, GstMessage *message);
108

Wim Taymans's avatar
Wim Taymans committed
109 110 111 112 113 114 115 116 117 118
  /*< private > */
  gpointer _gst_reserved[GST_PADDING];
};

GType 			gst_bus_get_type 		(void);

GstBus*			gst_bus_new	 		(void);

gboolean 		gst_bus_post 			(GstBus * bus, GstMessage * message);

119
gboolean 		gst_bus_have_pending 		(GstBus * bus);
Wim Taymans's avatar
Wim Taymans committed
120 121
GstMessage *		gst_bus_peek 			(GstBus * bus);
GstMessage *		gst_bus_pop 			(GstBus * bus);
122
void			gst_bus_set_flushing		(GstBus * bus, gboolean flushing);
Wim Taymans's avatar
Wim Taymans committed
123

124
/* synchronous dispatching */
Wim Taymans's avatar
Wim Taymans committed
125 126
void 			gst_bus_set_sync_handler 	(GstBus * bus, GstBusSyncHandler func,
    							 gpointer data);
127
/* GSource based dispatching */
128
GSource *		gst_bus_create_watch 		(GstBus * bus);
Wim Taymans's avatar
Wim Taymans committed
129 130
guint 			gst_bus_add_watch_full 		(GstBus * bus,
    							 gint priority,
131
    							 GstBusFunc func, 
Wim Taymans's avatar
Wim Taymans committed
132 133 134
							 gpointer user_data, 
							 GDestroyNotify notify);
guint 			gst_bus_add_watch 		(GstBus * bus,
135
    							 GstBusFunc func, 
Wim Taymans's avatar
Wim Taymans committed
136
							 gpointer user_data);
137

138
/* polling the bus */
139
GstMessage*		gst_bus_poll			(GstBus *bus, GstMessageType events,
Wim Taymans's avatar
Wim Taymans committed
140 141
                                                         GstClockTimeDiff timeout);

142 143 144 145 146
/* signal based dispatching helper functions. */
gboolean		gst_bus_async_signal_func	(GstBus *bus, GstMessage *message,
							 gpointer data);
GstBusSyncReply		gst_bus_sync_signal_handler	(GstBus *bus, GstMessage *message,
							 gpointer data);
147 148
/* add watch that dispatches signals */
guint 			gst_bus_add_signal_watch 	(GstBus * bus);
149

Wim Taymans's avatar
Wim Taymans committed
150
G_END_DECLS
151

Wim Taymans's avatar
Wim Taymans committed
152
#endif /* __GST_BUS_H__ */