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