1 /* Libvisual - The audio visualisation framework.
2  *
3  * Copyright (C) 2004, 2005 Dennis Smit <ds@nerds-incorporated.org>
4  *
5  * Authors: Dennis Smit <ds@nerds-incorporated.org>
6  *
7  * $Id:
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU Lesser General Public License as
11  * published by the Free Software Foundation; either version 2.1
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22  */
23 
24 #ifndef _LV_OBJECT_H
25 #define _LV_OBJECT_H
26 
27 #include <libvisual/lv_common.h>
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif /* __cplusplus */
32 
33 #define VISUAL_OBJECT(obj)				(VISUAL_CHECK_CAST ((obj), 0, VisObject))
34 
35 typedef struct _VisObject VisObject;
36 
37 /**
38  * The function defination for an object destructor. This can be assigned to any VisObject
39  * and is mostly used for internal usage or by support libraries. Keep in mind that this should not free
40  * the VisObject itself. This is done in the visual_object_destroy function itself.
41  *
42  * The destructor function should be safe to enter more than once, the object always contains the object
43  * however make sure that freed members are set to NULL and that it's checked.
44  *
45  * @arg object The VisObject that is passed to the destructor.
46  *
47  * @return VISUAL_OK on succes, -VISUAL_ERROR_OBJECT_DTOR_FAILED on failure.
48  */
49 typedef int (*VisObjectDtorFunc)(VisObject *object);
50 
51 /**
52  * The VisObject structure contains all the VisObject housekeeping data like refcounting and a pointer
53  * to the VisObjectDtorFunc. Also it's possible to set private data on a VisObject.
54  *
55  * Nearly all libvisual structures inherent from a VisObject.
56  */
57 struct _VisObject {
58 	int			 allocated;	/**< Set to TRUE if this object is allocated and should be freed completely.
59 						  * if set to FALSE, it will run the VisObjectDtorFunc but won't free the VisObject
60 						  * itself when refcount reaches 0. */
61 	int			 refcount;	/**< Contains the number of references to this object. */
62 	VisObjectDtorFunc	 dtor;		/**< Pointer to the object destruction function. */
63 
64 	void			*priv;		/**< Private which can be used by application or plugin developers
65 						 * depending on the sub class object. */
66 };
67 
68 void visual_object_list_destroyer (void *data);
69 
70 VisObject *visual_object_new (void);
71 int visual_object_free (VisObject *object);
72 int visual_object_destroy (VisObject *object);
73 
74 int visual_object_initialize (VisObject *object, int allocated, VisObjectDtorFunc dtor);
75 
76 int visual_object_ref (VisObject *object);
77 int visual_object_unref (VisObject *object);
78 
79 int visual_object_set_private (VisObject *object, void *priv);
80 void *visual_object_get_private (VisObject *object);
81 
82 #ifdef __cplusplus
83 }
84 #endif /* __cplusplus */
85 
86 #endif /* _LV_OBJECT_H */
87