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 gstreamer.AtomicQueue;
26 
27 private import glib.ConstructionException;
28 private import gobject.ObjectG;
29 private import gstreamer.c.functions;
30 public  import gstreamer.c.types;
31 public  import gstreamerc.gstreamertypes;
32 private import gtkd.Loader;
33 
34 
35 /**
36  * The #GstAtomicQueue object implements a queue that can be used from multiple
37  * threads without performing any blocking operations.
38  */
39 public class AtomicQueue
40 {
41 	/** the main Gtk struct */
42 	protected GstAtomicQueue* gstAtomicQueue;
43 	protected bool ownedRef;
44 
45 	/** Get the main Gtk struct */
46 	public GstAtomicQueue* getAtomicQueueStruct(bool transferOwnership = false)
47 	{
48 		if (transferOwnership)
49 			ownedRef = false;
50 		return gstAtomicQueue;
51 	}
52 
53 	/** the main Gtk struct as a void* */
54 	protected void* getStruct()
55 	{
56 		return cast(void*)gstAtomicQueue;
57 	}
58 
59 	/**
60 	 * Sets our main struct and passes it to the parent class.
61 	 */
62 	public this (GstAtomicQueue* gstAtomicQueue, bool ownedRef = false)
63 	{
64 		this.gstAtomicQueue = gstAtomicQueue;
65 		this.ownedRef = ownedRef;
66 	}
67 
68 	~this ()
69 	{
70 		if ( Linker.isLoaded(LIBRARY_GSTREAMER) && ownedRef )
71 			gst_atomic_queue_unref(gstAtomicQueue);
72 	}
73 
74 
75 	/** */
76 	public static GType getType()
77 	{
78 		return gst_atomic_queue_get_type();
79 	}
80 
81 	/**
82 	 * Create a new atomic queue instance. @initial_size will be rounded up to the
83 	 * nearest power of 2 and used as the initial size of the queue.
84 	 *
85 	 * Params:
86 	 *     initialSize = initial queue size
87 	 *
88 	 * Returns: a new #GstAtomicQueue
89 	 *
90 	 * Throws: ConstructionException GTK+ fails to create the object.
91 	 */
92 	public this(uint initialSize)
93 	{
94 		auto p = gst_atomic_queue_new(initialSize);
95 
96 		if(p is null)
97 		{
98 			throw new ConstructionException("null returned by new");
99 		}
100 
101 		this(cast(GstAtomicQueue*) p);
102 	}
103 
104 	/**
105 	 * Get the amount of items in the queue.
106 	 *
107 	 * Returns: the number of elements in the queue.
108 	 */
109 	public uint length()
110 	{
111 		return gst_atomic_queue_length(gstAtomicQueue);
112 	}
113 
114 	/**
115 	 * Peek the head element of the queue without removing it from the queue.
116 	 *
117 	 * Returns: the head element of @queue or
118 	 *     %NULL when the queue is empty.
119 	 */
120 	public void* peek()
121 	{
122 		return gst_atomic_queue_peek(gstAtomicQueue);
123 	}
124 
125 	/**
126 	 * Get the head element of the queue.
127 	 *
128 	 * Returns: the head element of @queue or %NULL when
129 	 *     the queue is empty.
130 	 */
131 	public void* pop()
132 	{
133 		return gst_atomic_queue_pop(gstAtomicQueue);
134 	}
135 
136 	/**
137 	 * Append @data to the tail of the queue.
138 	 *
139 	 * Params:
140 	 *     data = the data
141 	 */
142 	public void push(void* data)
143 	{
144 		gst_atomic_queue_push(gstAtomicQueue, data);
145 	}
146 
147 	/**
148 	 * Increase the refcount of @queue.
149 	 */
150 	public void doref()
151 	{
152 		gst_atomic_queue_ref(gstAtomicQueue);
153 	}
154 
155 	/**
156 	 * Unref @queue and free the memory when the refcount reaches 0.
157 	 */
158 	public void unref()
159 	{
160 		gst_atomic_queue_unref(gstAtomicQueue);
161 	}
162 }