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.MiniObject;
26 
27 private import gobject.ObjectG;
28 private import gstreamerc.gstreamer;
29 public  import gstreamerc.gstreamertypes;
30 
31 
32 /**
33  * #GstMiniObject is a simple structure that can be used to implement refcounted
34  * types.
35  * 
36  * Subclasses will include #GstMiniObject as the first member in their structure
37  * and then call gst_mini_object_init() to initialize the #GstMiniObject fields.
38  * 
39  * gst_mini_object_ref() and gst_mini_object_unref() increment and decrement the
40  * refcount respectively. When the refcount of a mini-object reaches 0, the
41  * dispose function is called first and when this returns %TRUE, the free
42  * function of the miniobject is called.
43  * 
44  * A copy can be made with gst_mini_object_copy().
45  * 
46  * gst_mini_object_is_writable() will return %TRUE when the refcount of the
47  * object is exactly 1, meaning the current caller has the only reference to the
48  * object. gst_mini_object_make_writable() will return a writable version of the
49  * object, which might be a new copy when the refcount was not 1.
50  * 
51  * Opaque data can be associated with a #GstMiniObject with
52  * gst_mini_object_set_qdata() and gst_mini_object_get_qdata(). The data is
53  * meant to be specific to the particular object and is not automatically copied
54  * with gst_mini_object_copy() or similar methods.
55  * 
56  * A weak reference can be added and remove with gst_mini_object_weak_ref()
57  * and gst_mini_object_weak_unref() respectively.
58  */
59 public class MiniObject
60 {
61 	/** the main Gtk struct */
62 	protected GstMiniObject* gstMiniObject;
63 
64 	/** Get the main Gtk struct */
65 	public GstMiniObject* getMiniObjectStruct()
66 	{
67 		return gstMiniObject;
68 	}
69 
70 	/** the main Gtk struct as a void* */
71 	protected void* getStruct()
72 	{
73 		return cast(void*)gstMiniObject;
74 	}
75 
76 	/**
77 	 * Sets our main struct and passes it to the parent class.
78 	 */
79 	public this (GstMiniObject* gstMiniObject)
80 	{
81 		this.gstMiniObject = gstMiniObject;
82 	}
83 
84 
85 	/**
86 	 * Creates a copy of the mini-object.
87 	 *
88 	 * MT safe
89 	 *
90 	 * Return: the new mini-object.
91 	 */
92 	public MiniObject copy()
93 	{
94 		auto p = gst_mini_object_copy(gstMiniObject);
95 		
96 		if(p is null)
97 		{
98 			return null;
99 		}
100 		
101 		return ObjectG.getDObject!(MiniObject)(cast(GstMiniObject*) p);
102 	}
103 
104 	/**
105 	 * This function gets back user data pointers stored via
106 	 * gst_mini_object_set_qdata().
107 	 *
108 	 * Params:
109 	 *     quark = A #GQuark, naming the user data pointer
110 	 *
111 	 * Return: The user data pointer set, or
112 	 *     %NULL
113 	 */
114 	public void* getQdata(GQuark quark)
115 	{
116 		return gst_mini_object_get_qdata(gstMiniObject, quark);
117 	}
118 
119 	/**
120 	 * Initializes a mini-object with the desired type and copy/dispose/free
121 	 * functions.
122 	 *
123 	 * Params:
124 	 *     flags = initial #GstMiniObjectFlags
125 	 *     type = the #GType of the mini-object to create
126 	 *     copyFunc = the copy function, or %NULL
127 	 *     disposeFunc = the dispose function, or %NULL
128 	 *     freeFunc = the free function or %NULL
129 	 */
130 	public void init(uint flags, GType type, GstMiniObjectCopyFunction copyFunc, GstMiniObjectDisposeFunction disposeFunc, GstMiniObjectFreeFunction freeFunc)
131 	{
132 		gst_mini_object_init(gstMiniObject, flags, type, copyFunc, disposeFunc, freeFunc);
133 	}
134 
135 	/**
136 	 * If @mini_object has the LOCKABLE flag set, check if the current EXCLUSIVE
137 	 * lock on @object is the only one, this means that changes to the object will
138 	 * not be visible to any other object.
139 	 *
140 	 * If the LOCKABLE flag is not set, check if the refcount of @mini_object is
141 	 * exactly 1, meaning that no other reference exists to the object and that the
142 	 * object is therefore writable.
143 	 *
144 	 * Modification of a mini-object should only be done after verifying that it
145 	 * is writable.
146 	 *
147 	 * Return: %TRUE if the object is writable.
148 	 */
149 	public bool isWritable()
150 	{
151 		return gst_mini_object_is_writable(gstMiniObject) != 0;
152 	}
153 
154 	/**
155 	 * Lock the mini-object with the specified access mode in @flags.
156 	 *
157 	 * Params:
158 	 *     flags = #GstLockFlags
159 	 *
160 	 * Return: %TRUE if @object could be locked.
161 	 */
162 	public bool lock(GstLockFlags flags)
163 	{
164 		return gst_mini_object_lock(gstMiniObject, flags) != 0;
165 	}
166 
167 	/**
168 	 * Checks if a mini-object is writable.  If not, a writable copy is made and
169 	 * returned.  This gives away the reference to the original mini object,
170 	 * and returns a reference to the new object.
171 	 *
172 	 * MT safe
173 	 *
174 	 * Return: a mini-object (possibly the same pointer) that
175 	 *     is writable.
176 	 */
177 	public MiniObject makeWritable()
178 	{
179 		auto p = gst_mini_object_make_writable(gstMiniObject);
180 		
181 		if(p is null)
182 		{
183 			return null;
184 		}
185 		
186 		return ObjectG.getDObject!(MiniObject)(cast(GstMiniObject*) p);
187 	}
188 
189 	/**
190 	 * Increase the reference count of the mini-object.
191 	 *
192 	 * Note that the refcount affects the writability
193 	 * of @mini-object, see gst_mini_object_is_writable(). It is
194 	 * important to note that keeping additional references to
195 	 * GstMiniObject instances can potentially increase the number
196 	 * of memcpy operations in a pipeline, especially if the miniobject
197 	 * is a #GstBuffer.
198 	 *
199 	 * Return: the mini-object.
200 	 */
201 	public MiniObject doref()
202 	{
203 		auto p = gst_mini_object_ref(gstMiniObject);
204 		
205 		if(p is null)
206 		{
207 			return null;
208 		}
209 		
210 		return ObjectG.getDObject!(MiniObject)(cast(GstMiniObject*) p);
211 	}
212 
213 	/**
214 	 * This sets an opaque, named pointer on a miniobject.
215 	 * The name is specified through a #GQuark (retrieved e.g. via
216 	 * g_quark_from_static_string()), and the pointer
217 	 * can be gotten back from the @object with gst_mini_object_get_qdata()
218 	 * until the @object is disposed.
219 	 * Setting a previously set user data pointer, overrides (frees)
220 	 * the old pointer set, using %NULL as pointer essentially
221 	 * removes the data stored.
222 	 *
223 	 * @destroy may be specified which is called with @data as argument
224 	 * when the @object is disposed, or the data is being overwritten by
225 	 * a call to gst_mini_object_set_qdata() with the same @quark.
226 	 *
227 	 * Params:
228 	 *     quark = A #GQuark, naming the user data pointer
229 	 *     data = An opaque user data pointer
230 	 *     destroy = Function to invoke with @data as argument, when @data
231 	 *         needs to be freed
232 	 */
233 	public void setQdata(GQuark quark, void* data, GDestroyNotify destroy)
234 	{
235 		gst_mini_object_set_qdata(gstMiniObject, quark, data, destroy);
236 	}
237 
238 	/**
239 	 * This function gets back user data pointers stored via gst_mini_object_set_qdata()
240 	 * and removes the data from @object without invoking its destroy() function (if
241 	 * any was set).
242 	 *
243 	 * Params:
244 	 *     quark = A #GQuark, naming the user data pointer
245 	 *
246 	 * Return: The user data pointer set, or
247 	 *     %NULL
248 	 */
249 	public void* stealQdata(GQuark quark)
250 	{
251 		return gst_mini_object_steal_qdata(gstMiniObject, quark);
252 	}
253 
254 	/**
255 	 * Unlock the mini-object with the specified access mode in @flags.
256 	 *
257 	 * Params:
258 	 *     flags = #GstLockFlags
259 	 */
260 	public void unlock(GstLockFlags flags)
261 	{
262 		gst_mini_object_unlock(gstMiniObject, flags);
263 	}
264 
265 	/**
266 	 * Decreases the reference count of the mini-object, possibly freeing
267 	 * the mini-object.
268 	 */
269 	public void unref()
270 	{
271 		gst_mini_object_unref(gstMiniObject);
272 	}
273 
274 	/**
275 	 * Adds a weak reference callback to a mini object. Weak references are
276 	 * used for notification when a mini object is finalized. They are called
277 	 * "weak references" because they allow you to safely hold a pointer
278 	 * to the mini object without calling gst_mini_object_ref()
279 	 * (gst_mini_object_ref() adds a strong reference, that is, forces the object
280 	 * to stay alive).
281 	 *
282 	 * Params:
283 	 *     notify = callback to invoke before the mini object is freed
284 	 *     data = extra data to pass to notify
285 	 */
286 	public void weakRef(GstMiniObjectNotify notify, void* data)
287 	{
288 		gst_mini_object_weak_ref(gstMiniObject, notify, data);
289 	}
290 
291 	/**
292 	 * Removes a weak reference callback from a mini object.
293 	 *
294 	 * Params:
295 	 *     notify = callback to search for
296 	 *     data = data to search for
297 	 */
298 	public void weakUnref(GstMiniObjectNotify notify, void* data)
299 	{
300 		gst_mini_object_weak_unref(gstMiniObject, notify, data);
301 	}
302 
303 	/**
304 	 * Atomically modifies a pointer to point to a new mini-object.
305 	 * The reference count of @olddata is decreased and the reference count of
306 	 * @newdata is increased.
307 	 *
308 	 * Either @newdata and the value pointed to by @olddata may be %NULL.
309 	 *
310 	 * Params:
311 	 *     olddata = pointer to a pointer to a
312 	 *         mini-object to be replaced
313 	 *     newdata = pointer to new mini-object
314 	 *
315 	 * Return: %TRUE if @newdata was different from @olddata
316 	 */
317 	public static bool replace(ref MiniObject olddata, MiniObject newdata)
318 	{
319 		GstMiniObject* outolddata = olddata.getMiniObjectStruct();
320 		
321 		auto p = gst_mini_object_replace(&outolddata, (newdata is null) ? null : newdata.getMiniObjectStruct()) != 0;
322 		
323 		olddata = ObjectG.getDObject!(MiniObject)(outolddata);
324 		
325 		return p;
326 	}
327 
328 	/**
329 	 * Replace the current #GstMiniObject pointer to by @olddata with %NULL and
330 	 * return the old value.
331 	 *
332 	 * Params:
333 	 *     olddata = pointer to a pointer to a mini-object to
334 	 *         be stolen
335 	 *
336 	 * Return: the #GstMiniObject at @oldata
337 	 */
338 	public static MiniObject steal(ref MiniObject olddata)
339 	{
340 		GstMiniObject* outolddata = olddata.getMiniObjectStruct();
341 		
342 		auto p = gst_mini_object_steal(&outolddata);
343 		
344 		olddata = ObjectG.getDObject!(MiniObject)(outolddata);
345 		
346 		if(p is null)
347 		{
348 			return null;
349 		}
350 		
351 		return ObjectG.getDObject!(MiniObject)(cast(GstMiniObject*) p);
352 	}
353 
354 	/**
355 	 * Modifies a pointer to point to a new mini-object. The modification
356 	 * is done atomically. This version is similar to gst_mini_object_replace()
357 	 * except that it does not increase the refcount of @newdata and thus
358 	 * takes ownership of @newdata.
359 	 *
360 	 * Either @newdata and the value pointed to by @olddata may be %NULL.
361 	 *
362 	 * Params:
363 	 *     olddata = pointer to a pointer to a mini-object to
364 	 *         be replaced
365 	 *     newdata = pointer to new mini-object
366 	 *
367 	 * Return: %TRUE if @newdata was different from @olddata
368 	 */
369 	public static bool take(ref MiniObject olddata, MiniObject newdata)
370 	{
371 		GstMiniObject* outolddata = olddata.getMiniObjectStruct();
372 		
373 		auto p = gst_mini_object_take(&outolddata, (newdata is null) ? null : newdata.getMiniObjectStruct()) != 0;
374 		
375 		olddata = ObjectG.getDObject!(MiniObject)(outolddata);
376 		
377 		return p;
378 	}
379 }