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