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