updated .h files with // fixes
[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 #ifdef USE_GLIB2
30 #include <glib-object.h>        /* note that this gets wrapped in __GST_OBJECT_H__ */
31 #include <gst/gstmarshal.h>
32 #else
33 #include <gst/gobject2gtk.h>
34 #endif
35
36 #ifdef HAVE_ATOMIC_H
37 #include <asm/atomic.h>
38 #endif
39
40 #include <gst/gsttrace.h>
41 #include <gst/gsttypes.h>
42
43 /* FIXME */
44 #include "gstlog.h"
45
46 #ifdef __cplusplus
47 extern "C" {
48 #endif /* __cplusplus */
49
50 extern GType _gst_object_type;
51
52 #define GST_TYPE_OBJECT                 (_gst_object_type)
53 # define GST_IS_OBJECT(obj)             (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_OBJECT))
54 # define GST_IS_OBJECT_CLASS(obj)       (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_OBJECT))
55
56 #define GST_OBJECT_FAST(obj)            ((GstObject*)(obj))
57 #define GST_OBJECT_CLASS_FAST(klass)    ((GstObjectClass*)(klass))
58
59 #ifdef GST_TYPE_PARANOID
60 # define GST_OBJECT(obj)                (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_OBJECT, GstObject))
61 # define GST_OBJECT_CLASS(klass)        (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_OBJECT, GstObjectClass))
62 #else
63 # define GST_OBJECT                     GST_OBJECT_FAST
64 # define GST_OBJECT_CLASS               GST_OBJECT_CLASS_FAST
65 #endif
66
67 /*typedef struct _GstObject GstObject; */ 
68 /*typedef struct _GstObjectClass GstObjectClass; */
69
70 typedef enum
71 {
72   GST_DESTROYED   = 0,
73   GST_FLOATING,
74
75   GST_OBJECT_FLAG_LAST   = 4,
76 } GstObjectFlags;
77
78 struct _GstObject {
79   GObject       object;
80
81   gchar         *name;
82   /* have to have a refcount for the object */
83 #ifdef HAVE_ATOMIC_H
84   atomic_t      refcount;
85 #else
86   gint          refcount;
87 #endif
88
89   /* locking for all sorts of things (like the refcount) */
90   GMutex        *lock;
91   /* this objects parent */
92   GstObject     *parent;
93
94   guint32       flags;
95 };
96
97 struct _GstObjectClass {
98   GObjectClass  parent_class;
99
100   gchar         *path_string_separator;
101   GObject       *signal_object;
102
103   /* signals */
104   void          (*parent_set)           (GstObject *object, GstObject *parent);
105 #ifndef GST_DISABLE_LOADSAVE_REGISTRY
106   void          (*object_saved)         (GstObject *object, xmlNodePtr parent);
107 #endif
108
109   /* functions go here */
110   void          (*destroy)              (GstObject *object);
111
112 #ifndef GST_DISABLE_LOADSAVE_REGISTRY
113   xmlNodePtr    (*save_thyself)         (GstObject *object, xmlNodePtr parent);
114   void          (*restore_thyself)      (GstObject *object, xmlNodePtr self);
115 #endif
116 };
117
118 #define GST_FLAGS(obj)                  (GST_OBJECT (obj)->flags)
119 #define GST_FLAG_IS_SET(obj,flag)       (GST_FLAGS (obj) & (1<<(flag)))
120 #define GST_FLAG_SET(obj,flag)          G_STMT_START{ (GST_FLAGS (obj) |= (1<<(flag))); }G_STMT_END
121 #define GST_FLAG_UNSET(obj,flag)        G_STMT_START{ (GST_FLAGS (obj) &= ~(1<<(flag))); }G_STMT_END
122
123 #define GST_OBJECT_NAME(obj)            (const gchar*)(((GstObject *)(obj))->name)
124 #define GST_OBJECT_PARENT(obj)          (((GstObject *)(obj))->parent)
125
126 #define GST_OBJECT_DESTROYED(obj)       (GST_FLAG_IS_SET (obj, GST_DESTROYED))
127 #define GST_OBJECT_FLOATING(obj)        (GST_FLAG_IS_SET (obj, GST_FLOATING))
128
129 /* object locking */
130 #define GST_LOCK(obj)           (g_mutex_lock(GST_OBJECT(obj)->lock))
131 #define GST_TRYLOCK(obj)        (g_mutex_trylock(GST_OBJECT(obj)->lock))
132 #define GST_UNLOCK(obj)         (g_mutex_unlock(GST_OBJECT(obj)->lock))
133 #define GST_GET_LOCK(obj)       (GST_OBJECT(obj)->lock)
134
135
136 /* normal GObject stuff */
137 GType           gst_object_get_type             (void);
138
139 /* name routines */
140 void            gst_object_set_name             (GstObject *object, const gchar *name);
141 const gchar*    gst_object_get_name             (GstObject *object);
142
143 /* parentage routines */
144 void            gst_object_set_parent           (GstObject *object, GstObject *parent);
145 GstObject*      gst_object_get_parent           (GstObject *object);
146 void            gst_object_unparent             (GstObject *object);
147
148 gboolean        gst_object_check_uniqueness     (GList *list, const gchar *name);
149
150 #ifndef GST_DISABLE_LOADSAVE_REGISTRY
151 xmlNodePtr      gst_object_save_thyself         (GstObject *object, xmlNodePtr parent);
152 void            gst_object_restore_thyself      (GstObject *object, xmlNodePtr parent);
153 #else
154 #pragma GCC poison gst_object_save_thyself
155 #pragma GCC poison gst_object_restore_thyself
156 #endif
157
158 /* refcounting */
159 GstObject *     gst_object_ref                  (GstObject *object);
160 void            gst_object_unref                (GstObject *object);
161 void            gst_object_sink                 (GstObject *object);
162 /* destroying an object */
163 void            gst_object_destroy              (GstObject *object);
164
165 /* printing out the 'path' of the object */
166 gchar *         gst_object_get_path_string      (GstObject *object);
167
168 guint           gst_class_signal_connect        (GstObjectClass *klass,
169                                                  const gchar    *name,
170                                                  gpointer       func,
171                                                  gpointer       func_data);
172
173 #ifndef GST_DISABLE_LOADSAVE_REGISTRY
174 void            gst_class_signal_emit_by_name   (GstObject      *object,
175                                                  const gchar    *name,
176                                                  xmlNodePtr self);
177 #else
178 #pragma GCC poison gst_class_signal_emit_by_name
179 #endif
180
181
182 #ifdef __cplusplus
183 }
184 #endif /* __cplusplus */
185
186
187 #endif /* __GST_OBJECT_H__ */
188