Change GST_.*_PADDING to _gst_padding[GST_PADDING];
[platform/upstream/gstreamer.git] / gst / gstobject.h
1 /* GStreamer
2  * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3  *                    2000 Wim Taymans <wtay@chello.be>
4  *
5  * gstobject.h: Header for base GstObject
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23
24 #ifndef __GST_OBJECT_H__
25 #define __GST_OBJECT_H__
26
27 #include <gst/gstconfig.h>
28
29 #include <glib-object.h>        /* note that this gets wrapped in __GST_OBJECT_H__ */
30 #include <gst/gstmarshal.h>
31
32 #include <gst/gsttypes.h>
33
34 G_BEGIN_DECLS
35
36 extern GType _gst_object_type;
37
38 #define GST_TYPE_OBJECT                 (_gst_object_type)
39 #define GST_IS_OBJECT(obj)              (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_OBJECT))
40 #define GST_IS_OBJECT_CLASS(klass)      (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_OBJECT))
41 #define GST_OBJECT_GET_CLASS(obj)       (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_OBJECT, GstObjectClass))
42
43 #define GST_OBJECT_CAST(obj)            ((GstObject*)(obj))
44 #define GST_OBJECT_CLASS_CAST(klass)    ((GstObjectClass*)(klass))
45
46 #ifdef GST_TYPE_PARANOID
47 # define GST_OBJECT(obj)                (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_OBJECT, GstObject))
48 # define GST_OBJECT_CLASS(klass)        (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_OBJECT, GstObjectClass))
49 #else
50 # define GST_OBJECT                     GST_OBJECT_CAST
51 # define GST_OBJECT_CLASS               GST_OBJECT_CLASS_CAST
52 #endif
53
54 /* make sure we don't change the object size but stil make it compile
55  * without libxml */
56 #ifdef GST_DISABLE_LOADSAVE_REGISTRY
57 #define xmlNodePtr      gpointer
58 #endif
59
60 typedef enum
61 {
62   GST_DESTROYED   = 0,
63   GST_FLOATING,
64
65   GST_OBJECT_FLAG_LAST   = 4
66 } GstObjectFlags;
67
68 struct _GstObject {
69   GObject       object;
70
71   gchar         *name;
72
73   /* locking for all sorts of things */
74   GMutex        *lock;
75   /* this object's parent */
76   GstObject     *parent;
77
78   guint32       flags;
79
80   gpointer _gst_reserved[GST_PADDING];
81 };
82
83 /* signal_object is used to signal to the whole class */
84 struct _GstObjectClass {
85   GObjectClass  parent_class;
86
87   gchar         *path_string_separator;
88   GObject       *signal_object;
89
90   /* signals */
91   void          (*parent_set)           (GstObject *object, GstObject *parent);
92   void          (*parent_unset)         (GstObject *object, GstObject *parent);
93   void          (*object_saved)         (GstObject *object, xmlNodePtr parent);
94   void          (*deep_notify)          (GstObject *object, GstObject *orig, GParamSpec *pspec);
95
96   /* functions go here */
97   void          (*destroy)              (GstObject *object);
98
99   xmlNodePtr    (*save_thyself)         (GstObject *object, xmlNodePtr parent);
100   void          (*restore_thyself)      (GstObject *object, xmlNodePtr self);
101
102   gpointer _gst_reserved[GST_PADDING];
103 };
104
105 #define GST_FLAGS(obj)                  (GST_OBJECT_CAST (obj)->flags)
106 #define GST_FLAG_IS_SET(obj,flag)       (GST_FLAGS (obj) & (1<<(flag)))
107 #define GST_FLAG_SET(obj,flag)          G_STMT_START{ (GST_FLAGS (obj) |= (1<<(flag))); }G_STMT_END
108 #define GST_FLAG_UNSET(obj,flag)        G_STMT_START{ (GST_FLAGS (obj) &= ~(1<<(flag))); }G_STMT_END
109
110 #define GST_OBJECT_NAME(obj)            (const gchar*)(((GstObject *)(obj))->name)
111 #define GST_OBJECT_PARENT(obj)          (((GstObject *)(obj))->parent)
112
113 #define GST_OBJECT_DESTROYED(obj)       (GST_FLAG_IS_SET (obj, GST_DESTROYED))
114 #define GST_OBJECT_FLOATING(obj)        (GST_FLAG_IS_SET (obj, GST_FLOATING))
115
116 /* CR1: object locking - GObject 2.0 doesn't have threadsafe locking */
117 #define GST_LOCK(obj)                   (g_mutex_lock(GST_OBJECT_CAST(obj)->lock))
118 #define GST_TRYLOCK(obj)                (g_mutex_trylock(GST_OBJECT_CAST(obj)->lock))
119 #define GST_UNLOCK(obj)                 (g_mutex_unlock(GST_OBJECT_CAST(obj)->lock))
120 #define GST_GET_LOCK(obj)               (GST_OBJECT_CAST(obj)->lock)
121
122
123 /* normal GObject stuff */
124 GType           gst_object_get_type             (void);
125
126 /* name routines */
127 void            gst_object_set_name             (GstObject *object, const gchar *name);
128 G_CONST_RETURN gchar*
129                 gst_object_get_name             (GstObject *object);
130
131 /* parentage routines */
132 void            gst_object_set_parent           (GstObject *object, GstObject *parent);
133 GstObject*      gst_object_get_parent           (GstObject *object);
134 void            gst_object_unparent             (GstObject *object);
135
136 void            gst_object_default_deep_notify  (GObject *object, GstObject *orig, 
137                                                  GParamSpec *pspec, gchar **excluded_props);
138
139 gboolean        gst_object_check_uniqueness     (GList *list, const gchar *name);
140
141 #ifndef GST_DISABLE_LOADSAVE_REGISTRY
142 xmlNodePtr      gst_object_save_thyself         (GstObject *object, xmlNodePtr parent);
143 void            gst_object_restore_thyself      (GstObject *object, xmlNodePtr self);
144 #else
145 #pragma GCC poison gst_object_save_thyself
146 #pragma GCC poison gst_object_restore_thyself
147 #endif
148
149 /* refcounting + life cycle */
150 GstObject *     gst_object_ref                  (GstObject *object);
151 void            gst_object_unref                (GstObject *object);
152 void            gst_object_sink                 (GstObject *object);
153
154 /* replace object pointer */
155 void            gst_object_replace              (GstObject **oldobj, GstObject *newobj);
156
157 /* printing out the 'path' of the object */
158 gchar *         gst_object_get_path_string      (GstObject *object);
159
160 guint           gst_class_signal_connect        (GstObjectClass *klass,
161                                                  const gchar    *name,
162                                                  gpointer        func,
163                                                  gpointer        func_data);
164
165 #ifndef GST_DISABLE_LOADSAVE_REGISTRY
166 void            gst_class_signal_emit_by_name   (GstObject      *object,
167                                                  const gchar    *name,
168                                                  xmlNodePtr      self);
169 #else
170 #pragma GCC poison gst_class_signal_emit_by_name
171 #endif
172
173
174 G_END_DECLS
175
176 #endif /* __GST_OBJECT_H__ */
177