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