gst/gstmessage.c: Fixed a few forgotten variables on previous commit
[platform/upstream/gstreamer.git] / gst / gstbus.h
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., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21
22 #ifndef __GST_BUS_H__
23 #define __GST_BUS_H__
24
25 typedef struct _GstBus GstBus;
26 typedef struct _GstBusClass GstBusClass;
27
28 #include <gst/gstmessage.h>
29 #include <gst/gstclock.h>
30
31 G_BEGIN_DECLS
32
33 /* --- standard type macros --- */
34 #define GST_TYPE_BUS              (gst_bus_get_type ())
35 #define GST_BUS(bus)              (G_TYPE_CHECK_INSTANCE_CAST ((bus), GST_TYPE_BUS, GstBus))
36 #define GST_IS_BUS(bus)           (G_TYPE_CHECK_INSTANCE_TYPE ((bus), GST_TYPE_BUS))
37 #define GST_BUS_CLASS(bclass)     (G_TYPE_CHECK_CLASS_CAST ((bclass), GST_TYPE_BUS, GstBusClass))
38 #define GST_IS_BUS_CLASS(bclass)  (G_TYPE_CHECK_CLASS_TYPE ((bclass), GST_TYPE_BUS))
39 #define GST_BUS_GET_CLASS(bus)    (G_TYPE_INSTANCE_GET_CLASS ((bus), GST_TYPE_BUS, GstBusClass))
40 #define GST_BUS_CAST(bus)         ((GstBus*)(bus))
41
42 /**
43  * GstBusFlags:
44  * @GST_BUS_FLUSHING: The bus is currently dropping all messages
45  * @GST_BUS_FLAG_LAST: offset to define more flags
46  *
47  * The standard flags that a bus may have.
48  */
49 typedef enum {
50   GST_BUS_FLUSHING              = GST_OBJECT_FLAG_LAST,
51
52   GST_BUS_FLAG_LAST             = GST_OBJECT_FLAG_LAST + 1
53 } GstBusFlags;
54
55 /**
56  * GstBusSyncReply:
57  * @GST_BUS_DROP: drop the message
58  * @GST_BUS_PASS: pass the message to the async queue
59  * @GST_BUS_ASYNC: pass message to async queue, continue if message is handled
60  *
61  * The result values for a GstBusSyncHandler.
62  */
63 typedef enum
64 {
65   GST_BUS_DROP = 0,
66   GST_BUS_PASS = 1,
67   GST_BUS_ASYNC = 2,
68 } GstBusSyncReply;
69
70 /**
71  * GstBusSyncHandler:
72  * @bus: the #GstBus that sent the message
73  * @message: the #GstMessage
74  * @data: user data that has been given, when registering the handler
75  *
76  * Handler will be invoked synchronously, when a new message has been injected
77  * into the bus. This function is mostly used internally. Only one sync handler
78  * can be attached to a given bus.
79  *
80  * Returns: #GstBusSyncReply stating what to do with the message
81  */
82 typedef GstBusSyncReply (*GstBusSyncHandler)    (GstBus * bus, GstMessage * message, gpointer data);
83
84 /**
85  * GstBusFunc:
86  * @bus: the #GstBus that sent the message
87  * @message: the #GstMessage
88  * @data: user data that has been given, when registering the handler
89  *
90  * Specifies the type of function passed to #gst_bus_add_watch() or 
91  * #gst_bus_add_watch_full(), which is called from the mainloop when a message
92  * is available on the bus.
93  *
94  * The message passed to the function will be unreffed after execution of this
95  * function so it should not be freed in the function. 
96  *
97  * Returns: %FALSE if the event source should be removed. 
98  */
99 typedef gboolean        (*GstBusFunc)           (GstBus * bus, GstMessage * message, gpointer data);
100
101 struct _GstBus
102 {
103   GstObject         object;
104
105   /*< private > */
106   GQueue           *queue;
107   GMutex           *queue_lock;
108
109   GstBusSyncHandler sync_handler;
110   gpointer          sync_handler_data;
111
112   guint             signal_watch_id;
113   guint             num_signal_watchers;
114
115   /*< private > */
116   gpointer _gst_reserved[GST_PADDING];
117 };
118
119 struct _GstBusClass
120 {
121   GstObjectClass parent_class;
122
123   /* signals */
124   void (*message)       (GstBus *bus, GstMessage *message);
125   void (*sync_message)  (GstBus *bus, GstMessage *message);
126
127   /*< private > */
128   gpointer _gst_reserved[GST_PADDING];
129 };
130
131 GType                   gst_bus_get_type                (void);
132
133 GstBus*                 gst_bus_new                     (void);
134
135 gboolean                gst_bus_post                    (GstBus * bus, GstMessage * message);
136
137 gboolean                gst_bus_have_pending            (GstBus * bus);
138 GstMessage *            gst_bus_peek                    (GstBus * bus);
139 GstMessage *            gst_bus_pop                     (GstBus * bus);
140 void                    gst_bus_set_flushing            (GstBus * bus, gboolean flushing);
141
142 /* synchronous dispatching */
143 void                    gst_bus_set_sync_handler        (GstBus * bus, GstBusSyncHandler func,
144                                                          gpointer data);
145 /* GSource based dispatching */
146 GSource *               gst_bus_create_watch            (GstBus * bus);
147 guint                   gst_bus_add_watch_full          (GstBus * bus,
148                                                          gint priority,
149                                                          GstBusFunc func, 
150                                                          gpointer user_data, 
151                                                          GDestroyNotify notify);
152 guint                   gst_bus_add_watch               (GstBus * bus,
153                                                          GstBusFunc func, 
154                                                          gpointer user_data);
155
156 /* polling the bus */
157 GstMessage*             gst_bus_poll                    (GstBus *bus, GstMessageType events,
158                                                          GstClockTimeDiff timeout);
159
160 /* signal based dispatching helper functions. */
161 gboolean                gst_bus_async_signal_func       (GstBus *bus, GstMessage *message,
162                                                          gpointer data);
163 GstBusSyncReply         gst_bus_sync_signal_handler     (GstBus *bus, GstMessage *message,
164                                                          gpointer data);
165
166 /* convenience api to add/remove a gsource that emits the async signals */
167 void                    gst_bus_add_signal_watch        (GstBus * bus);
168 void                    gst_bus_remove_signal_watch     (GstBus * bus);
169
170 G_END_DECLS
171
172 #endif /* __GST_BUS_H__ */