1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gst.base.DataQueue;
26 
27 private import glib.ConstructionException;
28 private import gobject.ObjectG;
29 private import gobject.Signals;
30 private import gst.base.c.functions;
31 public  import gst.base.c.types;
32 private import std.algorithm;
33 
34 
35 /**
36  * #GstDataQueue is an object that handles threadsafe queueing of objects. It
37  * also provides size-related functionality. This object should be used for
38  * any #GstElement that wishes to provide some sort of queueing functionality.
39  */
40 public class DataQueue : ObjectG
41 {
42 	/** the main Gtk struct */
43 	protected GstDataQueue* gstDataQueue;
44 
45 	/** Get the main Gtk struct */
46 	public GstDataQueue* getDataQueueStruct(bool transferOwnership = false)
47 	{
48 		if (transferOwnership)
49 			ownedRef = false;
50 		return gstDataQueue;
51 	}
52 
53 	/** the main Gtk struct as a void* */
54 	protected override void* getStruct()
55 	{
56 		return cast(void*)gstDataQueue;
57 	}
58 
59 	/**
60 	 * Sets our main struct and passes it to the parent class.
61 	 */
62 	public this (GstDataQueue* gstDataQueue, bool ownedRef = false)
63 	{
64 		this.gstDataQueue = gstDataQueue;
65 		super(cast(GObject*)gstDataQueue, ownedRef);
66 	}
67 
68 
69 	/** */
70 	public static GType getType()
71 	{
72 		return gst_data_queue_get_type();
73 	}
74 
75 	/**
76 	 * Creates a new #GstDataQueue. If @fullcallback or @emptycallback are supplied, then
77 	 * the #GstDataQueue will call the respective callback to signal full or empty condition.
78 	 * If the callbacks are NULL the #GstDataQueue will instead emit 'full' and 'empty'
79 	 * signals.
80 	 *
81 	 * Params:
82 	 *     checkfull = the callback used to tell if the element considers the queue full
83 	 *         or not.
84 	 *     fullcallback = the callback which will be called when the queue is considered full.
85 	 *     emptycallback = the callback which will be called when the queue is considered empty.
86 	 *     checkdata = a #gpointer that will be passed to the @checkfull, @fullcallback,
87 	 *         and @emptycallback callbacks.
88 	 *
89 	 * Returns: a new #GstDataQueue.
90 	 *
91 	 * Since: 1.2
92 	 *
93 	 * Throws: ConstructionException GTK+ fails to create the object.
94 	 */
95 	public this(GstDataQueueCheckFullFunction checkfull, GstDataQueueFullCallback fullcallback, GstDataQueueEmptyCallback emptycallback, void* checkdata)
96 	{
97 		auto p = gst_data_queue_new(checkfull, fullcallback, emptycallback, checkdata);
98 
99 		if(p is null)
100 		{
101 			throw new ConstructionException("null returned by new");
102 		}
103 
104 		this(cast(GstDataQueue*) p, true);
105 	}
106 
107 	/**
108 	 * Pop and unref the head-most #GstMiniObject with the given #GType.
109 	 *
110 	 * Params:
111 	 *     type = The #GType of the item to drop.
112 	 *
113 	 * Returns: %TRUE if an element was removed.
114 	 *
115 	 * Since: 1.2
116 	 */
117 	public bool dropHead(GType type)
118 	{
119 		return gst_data_queue_drop_head(gstDataQueue, type) != 0;
120 	}
121 
122 	/**
123 	 * Flushes all the contents of the @queue. Any call to #gst_data_queue_push and
124 	 * #gst_data_queue_pop will be released.
125 	 * MT safe.
126 	 *
127 	 * Since: 1.2
128 	 */
129 	public void flush()
130 	{
131 		gst_data_queue_flush(gstDataQueue);
132 	}
133 
134 	/**
135 	 * Get the current level of the queue.
136 	 *
137 	 * Params:
138 	 *     level = the location to store the result
139 	 *
140 	 * Since: 1.2
141 	 */
142 	public void getLevel(out GstDataQueueSize level)
143 	{
144 		gst_data_queue_get_level(gstDataQueue, &level);
145 	}
146 
147 	/**
148 	 * Queries if there are any items in the @queue.
149 	 * MT safe.
150 	 *
151 	 * Returns: %TRUE if @queue is empty.
152 	 *
153 	 * Since: 1.2
154 	 */
155 	public bool isEmpty()
156 	{
157 		return gst_data_queue_is_empty(gstDataQueue) != 0;
158 	}
159 
160 	/**
161 	 * Queries if @queue is full. This check will be done using the
162 	 * #GstDataQueueCheckFullFunction registered with @queue.
163 	 * MT safe.
164 	 *
165 	 * Returns: %TRUE if @queue is full.
166 	 *
167 	 * Since: 1.2
168 	 */
169 	public bool isFull()
170 	{
171 		return gst_data_queue_is_full(gstDataQueue) != 0;
172 	}
173 
174 	/**
175 	 * Inform the queue that the limits for the fullness check have changed and that
176 	 * any blocking gst_data_queue_push() should be unblocked to recheck the limits.
177 	 *
178 	 * Since: 1.2
179 	 */
180 	public void limitsChanged()
181 	{
182 		gst_data_queue_limits_changed(gstDataQueue);
183 	}
184 
185 	/**
186 	 * Retrieves the first @item available on the @queue without removing it.
187 	 * If the queue is currently empty, the call will block until at least
188 	 * one item is available, OR the @queue is set to the flushing state.
189 	 * MT safe.
190 	 *
191 	 * Params:
192 	 *     item = pointer to store the returned #GstDataQueueItem.
193 	 *
194 	 * Returns: %TRUE if an @item was successfully retrieved from the @queue.
195 	 *
196 	 * Since: 1.2
197 	 */
198 	public bool peek(out GstDataQueueItem* item)
199 	{
200 		return gst_data_queue_peek(gstDataQueue, &item) != 0;
201 	}
202 
203 	/**
204 	 * Retrieves the first @item available on the @queue. If the queue is currently
205 	 * empty, the call will block until at least one item is available, OR the
206 	 * @queue is set to the flushing state.
207 	 * MT safe.
208 	 *
209 	 * Params:
210 	 *     item = pointer to store the returned #GstDataQueueItem.
211 	 *
212 	 * Returns: %TRUE if an @item was successfully retrieved from the @queue.
213 	 *
214 	 * Since: 1.2
215 	 */
216 	public bool pop(out GstDataQueueItem* item)
217 	{
218 		return gst_data_queue_pop(gstDataQueue, &item) != 0;
219 	}
220 
221 	/**
222 	 * Pushes a #GstDataQueueItem (or a structure that begins with the same fields)
223 	 * on the @queue. If the @queue is full, the call will block until space is
224 	 * available, OR the @queue is set to flushing state.
225 	 * MT safe.
226 	 *
227 	 * Note that this function has slightly different semantics than gst_pad_push()
228 	 * and gst_pad_push_event(): this function only takes ownership of @item and
229 	 * the #GstMiniObject contained in @item if the push was successful. If %FALSE
230 	 * is returned, the caller is responsible for freeing @item and its contents.
231 	 *
232 	 * Params:
233 	 *     item = a #GstDataQueueItem.
234 	 *
235 	 * Returns: %TRUE if the @item was successfully pushed on the @queue.
236 	 *
237 	 * Since: 1.2
238 	 */
239 	public bool push(GstDataQueueItem* item)
240 	{
241 		return gst_data_queue_push(gstDataQueue, item) != 0;
242 	}
243 
244 	/**
245 	 * Pushes a #GstDataQueueItem (or a structure that begins with the same fields)
246 	 * on the @queue. It ignores if the @queue is full or not and forces the @item
247 	 * to be pushed anyway.
248 	 * MT safe.
249 	 *
250 	 * Note that this function has slightly different semantics than gst_pad_push()
251 	 * and gst_pad_push_event(): this function only takes ownership of @item and
252 	 * the #GstMiniObject contained in @item if the push was successful. If %FALSE
253 	 * is returned, the caller is responsible for freeing @item and its contents.
254 	 *
255 	 * Params:
256 	 *     item = a #GstDataQueueItem.
257 	 *
258 	 * Returns: %TRUE if the @item was successfully pushed on the @queue.
259 	 *
260 	 * Since: 1.2
261 	 */
262 	public bool pushForce(GstDataQueueItem* item)
263 	{
264 		return gst_data_queue_push_force(gstDataQueue, item) != 0;
265 	}
266 
267 	/**
268 	 * Sets the queue to flushing state if @flushing is %TRUE. If set to flushing
269 	 * state, any incoming data on the @queue will be discarded. Any call currently
270 	 * blocking on #gst_data_queue_push or #gst_data_queue_pop will return straight
271 	 * away with a return value of %FALSE. While the @queue is in flushing state,
272 	 * all calls to those two functions will return %FALSE.
273 	 *
274 	 * MT Safe.
275 	 *
276 	 * Params:
277 	 *     flushing = a #gboolean stating if the queue will be flushing or not.
278 	 *
279 	 * Since: 1.2
280 	 */
281 	public void setFlushing(bool flushing)
282 	{
283 		gst_data_queue_set_flushing(gstDataQueue, flushing);
284 	}
285 
286 	/**
287 	 * Reports that the queue became empty (empty).
288 	 * A queue is empty if the total amount of visible items inside it (num-visible, time,
289 	 * size) is lower than the boundary values which can be set through the GObject
290 	 * properties.
291 	 */
292 	gulong addOnEmpty(void delegate(DataQueue) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
293 	{
294 		return Signals.connect(this, "empty", dlg, connectFlags ^ ConnectFlags.SWAPPED);
295 	}
296 
297 	/**
298 	 * Reports that the queue became full (full).
299 	 * A queue is full if the total amount of data inside it (num-visible, time,
300 	 * size) is higher than the boundary values which can be set through the GObject
301 	 * properties.
302 	 */
303 	gulong addOnFull(void delegate(DataQueue) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
304 	{
305 		return Signals.connect(this, "full", dlg, connectFlags ^ ConnectFlags.SWAPPED);
306 	}
307 }