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  * Conversion parameters:
26  * inFile  = GstObject.html
27  * outPack = gstreamer
28  * outFile = ObjectGst
29  * strct   = GstObject
30  * realStrct=
31  * ctorStrct=
32  * clss    = ObjectGst
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- gst_object_
41  * 	- gst_
42  * omit structs:
43  * omit prefixes:
44  * omit code:
45  * 	- gst_object_save_thyself
46  * 	- gst_object_restore_thyself
47  * 	- gst_class_signal_emit_by_name
48  * 	- gst_class_signal_connect
49  * omit signals:
50  * imports:
51  * 	- glib.Str
52  * 	- gobject.ObjectG
53  * 	- glib.ErrorG
54  * 	- glib.ListG
55  * 	- gobject.ParamSpec
56  * structWrap:
57  * 	- GError* -> ErrorG
58  * 	- GList* -> ListG
59  * 	- GObject* -> ObjectG
60  * 	- GParamSpec* -> ParamSpec
61  * 	- GstObject* -> ObjectGst
62  * module aliases:
63  * local aliases:
64  * overrides:
65  */
66 
67 module gstreamer.ObjectGst;
68 
69 public  import gstreamerc.gstreamertypes;
70 
71 private import gstreamerc.gstreamer;
72 private import glib.ConstructionException;
73 private import gobject.ObjectG;
74 
75 private import gobject.Signals;
76 public  import gtkc.gdktypes;
77 
78 private import glib.Str;
79 private import gobject.ObjectG;
80 private import glib.ErrorG;
81 private import glib.ListG;
82 private import gobject.ParamSpec;
83 
84 
85 
86 private import gobject.ObjectG;
87 
88 /**
89  * Description
90  * GstObject provides a root for the object hierarchy tree filed in by the
91  * GStreamer library. It is currently a thin wrapper on top of
92  * GObject. It is an abstract class that is not very usable on its own.
93  * GstObject gives us basic refcounting, parenting functionality and locking.
94  * Most of the function are just extended for special GStreamer needs and can be
95  * found under the same name in the base class of GstObject which is GObject
96  * (e.g. g_object_ref() becomes gst_object_ref()).
97  * The most interesting difference between GstObject and GObject is the
98  * "floating" reference count. A GObject is created with a reference count of
99  * 1, owned by the creator of the GObject. (The owner of a reference is the
100  * code section that has the right to call gst_object_unref() in order to
101  * remove that reference.) A GstObject is created with a reference count of 1
102  * also, but it isn't owned by anyone; Instead, the initial reference count
103  * of a GstObject is "floating". The floating reference can be removed by
104  * anyone at any time, by calling gst_object_sink(). gst_object_sink() does
105  * nothing if an object is already sunk (has no floating reference).
106  * When you add a GstElement to its parent container, the parent container will
107  * do this:
108  * $(DDOC_COMMENT example)
109  * This means that the container now owns a reference to the child element
110  * (since it called gst_object_ref()), and the child element has no floating
111  * reference.
112  * The purpose of the floating reference is to keep the child element alive
113  * until you add it to a parent container, which then manages the lifetime of
114  * the object itself:
115  * $(DDOC_COMMENT example)
116  * Another effect of this is, that calling gst_object_unref() on a bin object,
117  * will also destoy all the GstElement objects in it. The same is true for
118  * calling gst_bin_remove().
119  * Special care has to be taken for all methods that gst_object_sink() an object
120  * since if the caller of those functions had a floating reference to the object,
121  * the object reference is now invalid.
122  * In contrast to GObject instances, GstObject adds a name property. The functions
123  * gst_object_set_name() and gst_object_get_name() are used to set/get the name
124  * of the object.
125  * Last reviewed on 2005-11-09 (0.9.4)
126  */
127 public class ObjectGst : ObjectG
128 {
129 	
130 	/** the main Gtk struct */
131 	protected GstObject* gstObject;
132 	
133 	
134 	public GstObject* getObjectGstStruct()
135 	{
136 		return gstObject;
137 	}
138 	
139 	
140 	/** the main Gtk struct as a void* */
141 	protected override void* getStruct()
142 	{
143 		return cast(void*)gstObject;
144 	}
145 	
146 	/**
147 	 * Sets our main struct and passes it to the parent class
148 	 */
149 	public this (GstObject* gstObject)
150 	{
151 		super(cast(GObject*)gstObject);
152 		this.gstObject = gstObject;
153 	}
154 	
155 	protected override void setStruct(GObject* obj)
156 	{
157 		super.setStruct(obj);
158 		gstObject = cast(GstObject*)obj;
159 	}
160 	
161 	/**
162 	 */
163 	int[string] connectedSignals;
164 	
165 	void delegate(ObjectGst, ParamSpec, ObjectGst)[] onDeepNotifyListeners;
166 	/**
167 	 * The deep notify signal is used to be notified of property changes. It is
168 	 * typically attached to the toplevel bin to receive notifications from all
169 	 * the elements contained in that bin.
170 	 */
171 	void addOnDeepNotify(void delegate(ObjectGst, ParamSpec, ObjectGst) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
172 	{
173 		if ( !("deep-notify" in connectedSignals) )
174 		{
175 			Signals.connectData(
176 			getStruct(),
177 			"deep-notify",
178 			cast(GCallback)&callBackDeepNotify,
179 			cast(void*)this,
180 			null,
181 			connectFlags);
182 			connectedSignals["deep-notify"] = 1;
183 		}
184 		onDeepNotifyListeners ~= dlg;
185 	}
186 	extern(C) static void callBackDeepNotify(GstObject* gstobjectStruct, GstObject* propObject, GParamSpec* prop, ObjectGst _objectGst)
187 	{
188 		foreach ( void delegate(ObjectGst, ParamSpec, ObjectGst) dlg ; _objectGst.onDeepNotifyListeners )
189 		{
190 			dlg(ObjectG.getDObject!(ObjectGst)(propObject), ObjectG.getDObject!(ParamSpec)(prop), _objectGst);
191 		}
192 	}
193 	
194 	void delegate(void*, ObjectGst)[] onObjectSavedListeners;
195 	/**
196 	 * Trigered whenever a new object is saved to XML. You can connect to this
197 	 * signal to insert custom XML tags into the core XML.
198 	 */
199 	void addOnObjectSaved(void delegate(void*, ObjectGst) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
200 	{
201 		if ( !("object-saved" in connectedSignals) )
202 		{
203 			Signals.connectData(
204 			getStruct(),
205 			"object-saved",
206 			cast(GCallback)&callBackObjectSaved,
207 			cast(void*)this,
208 			null,
209 			connectFlags);
210 			connectedSignals["object-saved"] = 1;
211 		}
212 		onObjectSavedListeners ~= dlg;
213 	}
214 	extern(C) static void callBackObjectSaved(GstObject* gstobjectStruct, void* xmlNode, ObjectGst _objectGst)
215 	{
216 		foreach ( void delegate(void*, ObjectGst) dlg ; _objectGst.onObjectSavedListeners )
217 		{
218 			dlg(xmlNode, _objectGst);
219 		}
220 	}
221 	
222 	void delegate(ObjectG, ObjectGst)[] onParentSetListeners;
223 	/**
224 	 * Emitted when the parent of an object is set.
225 	 */
226 	void addOnParentSet(void delegate(ObjectG, ObjectGst) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
227 	{
228 		if ( !("parent-set" in connectedSignals) )
229 		{
230 			Signals.connectData(
231 			getStruct(),
232 			"parent-set",
233 			cast(GCallback)&callBackParentSet,
234 			cast(void*)this,
235 			null,
236 			connectFlags);
237 			connectedSignals["parent-set"] = 1;
238 		}
239 		onParentSetListeners ~= dlg;
240 	}
241 	extern(C) static void callBackParentSet(GstObject* gstobjectStruct, GObject* parent, ObjectGst _objectGst)
242 	{
243 		foreach ( void delegate(ObjectG, ObjectGst) dlg ; _objectGst.onParentSetListeners )
244 		{
245 			dlg(ObjectG.getDObject!(ObjectG)(parent), _objectGst);
246 		}
247 	}
248 	
249 	void delegate(ObjectG, ObjectGst)[] onParentUnsetListeners;
250 	/**
251 	 * Emitted when the parent of an object is unset.
252 	 */
253 	void addOnParentUnset(void delegate(ObjectG, ObjectGst) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
254 	{
255 		if ( !("parent-unset" in connectedSignals) )
256 		{
257 			Signals.connectData(
258 			getStruct(),
259 			"parent-unset",
260 			cast(GCallback)&callBackParentUnset,
261 			cast(void*)this,
262 			null,
263 			connectFlags);
264 			connectedSignals["parent-unset"] = 1;
265 		}
266 		onParentUnsetListeners ~= dlg;
267 	}
268 	extern(C) static void callBackParentUnset(GstObject* gstobjectStruct, GObject* parent, ObjectGst _objectGst)
269 	{
270 		foreach ( void delegate(ObjectG, ObjectGst) dlg ; _objectGst.onParentUnsetListeners )
271 		{
272 			dlg(ObjectG.getDObject!(ObjectG)(parent), _objectGst);
273 		}
274 	}
275 	
276 	
277 	/**
278 	 * Sets the name of object, or gives object a guaranteed unique
279 	 * name (if name is NULL).
280 	 * This function makes a copy of the provided name, so the caller
281 	 * retains ownership of the name it sent.
282 	 * Params:
283 	 * name = new name of object
284 	 * Returns: TRUE if the name could be set. Since Objects that have a parent cannot be renamed, this function returns FALSE in those cases. MT safe. This function grabs and releases object's LOCK.
285 	 */
286 	public int setName(string name)
287 	{
288 		// gboolean gst_object_set_name (GstObject *object,  const gchar *name);
289 		return gst_object_set_name(gstObject, Str.toStringz(name));
290 	}
291 	
292 	/**
293 	 * Returns a copy of the name of object.
294 	 * Caller should g_free() the return value after usage.
295 	 * For a nameless object, this returns NULL, which you can safely g_free()
296 	 * as well.
297 	 * Returns: the name of object. g_free() after usage. MT safe. This function grabs and releases object's LOCK.
298 	 */
299 	public string getName()
300 	{
301 		// gchar* gst_object_get_name (GstObject *object);
302 		return Str.toString(gst_object_get_name(gstObject));
303 	}
304 	
305 	/**
306 	 * Sets the parent of object to parent. The object's reference count will
307 	 * be incremented, and any floating reference will be removed (see gst_object_sink()).
308 	 * This function causes the parent-set signal to be emitted when the parent
309 	 * was successfully set.
310 	 * Params:
311 	 * parent = new parent of object
312 	 * Returns: TRUE if parent could be set or FALSE when object already had a parent or object and parent are the same. MT safe. Grabs and releases object's LOCK.
313 	 */
314 	public int setParent(ObjectGst parent)
315 	{
316 		// gboolean gst_object_set_parent (GstObject *object,  GstObject *parent);
317 		return gst_object_set_parent(gstObject, (parent is null) ? null : parent.getObjectGstStruct());
318 	}
319 	
320 	/**
321 	 * Returns the parent of object. This function increases the refcount
322 	 * of the parent object so you should gst_object_unref() it after usage.
323 	 * Returns: parent of object, this can be NULL if object has no parent. unref after usage. MT safe. Grabs and releases object's LOCK.
324 	 */
325 	public ObjectGst getParent()
326 	{
327 		// GstObject* gst_object_get_parent (GstObject *object);
328 		auto p = gst_object_get_parent(gstObject);
329 		
330 		if(p is null)
331 		{
332 			return null;
333 		}
334 		
335 		return ObjectG.getDObject!(ObjectGst)(cast(GstObject*) p);
336 	}
337 	
338 	/**
339 	 * Clear the parent of object, removing the associated reference.
340 	 * This function decreases the refcount of object.
341 	 * MT safe. Grabs and releases object's lock.
342 	 */
343 	public void unparent()
344 	{
345 		// void gst_object_unparent (GstObject *object);
346 		gst_object_unparent(gstObject);
347 	}
348 	
349 	/**
350 	 * Returns a copy of the name prefix of object.
351 	 * Caller should g_free() the return value after usage.
352 	 * For a prefixless object, this returns NULL, which you can safely g_free()
353 	 * as well.
354 	 * Returns: the name prefix of object. g_free() after usage. MT safe. This function grabs and releases object's LOCK.
355 	 */
356 	public string getNamePrefix()
357 	{
358 		// gchar* gst_object_get_name_prefix (GstObject *object);
359 		return Str.toString(gst_object_get_name_prefix(gstObject));
360 	}
361 	
362 	/**
363 	 * Sets the name prefix of object to name_prefix.
364 	 * This function makes a copy of the provided name prefix, so the caller
365 	 * retains ownership of the name prefix it sent.
366 	 * MT safe. This function grabs and releases object's LOCK.
367 	 * Params:
368 	 * namePrefix = new name prefix of object
369 	 */
370 	public void setNamePrefix(string namePrefix)
371 	{
372 		// void gst_object_set_name_prefix (GstObject *object,  const gchar *name_prefix);
373 		gst_object_set_name_prefix(gstObject, Str.toStringz(namePrefix));
374 	}
375 	
376 	/**
377 	 * A default deep_notify signal callback for an object. The user data
378 	 * should contain a pointer to an array of strings that should be excluded
379 	 * from the notify. The default handler will print the new value of the property
380 	 * using g_print.
381 	 * MT safe. This function grabs and releases object's LOCK for getting its
382 	 *  path string.
383 	 * Params:
384 	 * object = the GObject that signalled the notify.
385 	 * orig = a GstObject that initiated the notify.
386 	 * pspec = a GParamSpec of the property.
387 	 * excludedProps = a set of user-specified properties to exclude or
388 	 *  NULL to show all changes.
389 	 */
390 	public static void defaultDeepNotify(ObjectG object, ObjectGst orig, ParamSpec pspec, string[] excludedProps)
391 	{
392 		// void gst_object_default_deep_notify (GObject *object,  GstObject *orig,  GParamSpec *pspec,  gchar **excluded_props);
393 		gst_object_default_deep_notify((object is null) ? null : object.getObjectGStruct(), (orig is null) ? null : orig.getObjectGstStruct(), (pspec is null) ? null : pspec.getParamSpecStruct(), Str.toStringzArray(excludedProps));
394 	}
395 	
396 	/**
397 	 * A default error function.
398 	 * The default handler will simply print the error string using g_print.
399 	 * Params:
400 	 * error = the GError.
401 	 * dbug = an additional debug information string, or NULL.
402 	 */
403 	public void defaultError(ErrorG error, string dbug)
404 	{
405 		// void gst_object_default_error (GstObject *source,  GError *error,  gchar *debug);
406 		gst_object_default_error(gstObject, (error is null) ? null : error.getErrorGStruct(), Str.toStringz(dbug));
407 	}
408 	
409 	/**
410 	 * Checks to see if there is any object named name in list. This function
411 	 * does not do any locking of any kind. You might want to protect the
412 	 * provided list with the lock of the owner of the list. This function
413 	 * will lock each GstObject in the list to compare the name, so be
414 	 * carefull when passing a list with a locked object.
415 	 * Params:
416 	 * list = a list of GstObject to check through
417 	 * name = the name to search for
418 	 * Returns: TRUE if a GstObject named name does not appear in list, FALSE if it does. MT safe. Grabs and releases the LOCK of each object in the list.
419 	 */
420 	public static int checkUniqueness(ListG list, string name)
421 	{
422 		// gboolean gst_object_check_uniqueness (GList *list,  const gchar *name);
423 		return gst_object_check_uniqueness((list is null) ? null : list.getListGStruct(), Str.toStringz(name));
424 	}
425 	
426 	/**
427 	 * Check if object has an ancestor ancestor somewhere up in
428 	 * the hierarchy.
429 	 * Params:
430 	 * ancestor = a GstObject to check as ancestor
431 	 * Returns: TRUE if ancestor is an ancestor of object. MT safe. Grabs and releases object's locks.
432 	 */
433 	public int hasAncestor(ObjectGst ancestor)
434 	{
435 		// gboolean gst_object_has_ancestor (GstObject *object,  GstObject *ancestor);
436 		return gst_object_has_ancestor(gstObject, (ancestor is null) ? null : ancestor.getObjectGstStruct());
437 	}
438 	
439 	/**
440 	 * Increments the refence count on object. This function
441 	 * does not take the lock on object because it relies on
442 	 * atomic refcounting.
443 	 * This object returns the input parameter to ease writing
444 	 * Params:
445 	 * object = a GstObject to reference
446 	 * Returns: A pointer to object
447 	 */
448 	public static void* doref(void* object)
449 	{
450 		// gpointer gst_object_ref (gpointer object);
451 		return gst_object_ref(object);
452 	}
453 	
454 	/**
455 	 * Decrements the refence count on object. If reference count hits
456 	 * zero, destroy object. This function does not take the lock
457 	 * on object as it relies on atomic refcounting.
458 	 * The unref method should never be called with the LOCK held since
459 	 * this might deadlock the dispose function.
460 	 * Params:
461 	 * object = a GstObject to unreference
462 	 */
463 	public static void unref(void* object)
464 	{
465 		// void gst_object_unref (gpointer object);
466 		gst_object_unref(object);
467 	}
468 	
469 	/**
470 	 * If object was floating, the GST_OBJECT_FLOATING flag is removed
471 	 * and object is unreffed. When object was not floating,
472 	 * this function does nothing.
473 	 * Any newly created object has a refcount of 1 and is floating.
474 	 * This function should be used when creating a new object to
475 	 * symbolically 'take ownership' of object. This done by first doing a
476 	 * gst_object_ref() to keep a reference to object and then gst_object_sink()
477 	 * to remove and unref any floating references to object.
478 	 * Use gst_object_set_parent() to have this done for you.
479 	 * MT safe. This function grabs and releases object lock.
480 	 * Params:
481 	 * object = a GstObject to sink
482 	 */
483 	public static void sink(void* object)
484 	{
485 		// void gst_object_sink (gpointer object);
486 		gst_object_sink(object);
487 	}
488 	
489 	/**
490 	 * Unrefs the GstObject pointed to by oldobj, refs newobj and
491 	 * puts newobj in *oldobj. Be carefull when calling this
492 	 * function, it does not take any locks. You might want to lock
493 	 * the object owning oldobj pointer before calling this
494 	 * function.
495 	 * Make sure not to LOCK oldobj because it might be unreffed
496 	 * which could cause a deadlock when it is disposed.
497 	 * Params:
498 	 * oldobj = pointer to a place of a GstObject to replace
499 	 * newobj = a new GstObject
500 	 */
501 	public static void replace(ref ObjectGst oldobj, ObjectGst newobj)
502 	{
503 		// void gst_object_replace (GstObject **oldobj,  GstObject *newobj);
504 		GstObject* outoldobj = (oldobj is null) ? null : oldobj.getObjectGstStruct();
505 		
506 		gst_object_replace(&outoldobj, (newobj is null) ? null : newobj.getObjectGstStruct());
507 		
508 		oldobj = ObjectG.getDObject!(ObjectGst)(outoldobj);
509 	}
510 	
511 	/**
512 	 * Generates a string describing the path of object in
513 	 * the object hierarchy. Only useful (or used) for debugging.
514 	 * Returns: a string describing the path of object. You must g_free() the string after usage. MT safe. Grabs and releases the GstObject's LOCK for all objects in the hierarchy.
515 	 */
516 	public string getPathString()
517 	{
518 		// gchar* gst_object_get_path_string (GstObject *object);
519 		return Str.toString(gst_object_get_path_string(gstObject));
520 	}
521 }