This is a megapatch with the following changes:
[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 <gtk/gtk.h>
28 #include <gst/gsttrace.h>
29 #include <parser.h>
30
31 #ifdef HAVE_CONFIG_H
32 #include "config.h"
33 #endif
34
35 #ifdef HAVE_ATOMIC_H
36 #include <asm/atomic.h>
37 #endif
38
39 // FIXME
40 #include "gstlog.h"
41
42 #ifdef __cplusplus
43 extern "C" {
44 #endif /* __cplusplus */
45
46
47 #define GST_TYPE_OBJECT \
48   (gst_object_get_type())
49 #define GST_OBJECT(obj) \
50   (GTK_CHECK_CAST((obj),GST_TYPE_OBJECT,GstObject))
51 #define GST_OBJECT_CLASS(klass) \
52   (GTK_CHECK_CLASS_CAST((klass),GST_TYPE_OBJECT,GstObjectClass))
53 #define GST_IS_OBJECT(obj) \
54   (GTK_CHECK_TYPE((obj),GST_TYPE_OBJECT))
55 #define GST_IS_OBJECT_CLASS(obj) \
56   (GTK_CHECK_CLASS_TYPE((klass),GST_TYPE_OBJECT))
57
58 typedef struct _GstObject GstObject;
59 typedef struct _GstObjectClass GstObjectClass;
60
61 #define GST_OBJECT_FLAG_LAST 4
62
63 struct _GstObject {
64   GtkObject object;
65
66   gchar *name;
67   /* have to have a refcount for the object */
68 #ifdef HAVE_ATOMIC_H
69   atomic_t refcount;
70 #else
71   int refcount;
72 #endif
73
74   /* locking for all sorts of things (like the refcount) */
75   GMutex *lock;
76
77   /* this objects parent */
78   GstObject *parent;
79 };
80
81 struct _GstObjectClass {
82   GtkObjectClass parent_class;
83
84   gchar *path_string_separator;
85
86   /* signals */
87   void          (*parent_set)           (GstObject *object, GstObject *parent);
88
89   /* functions go here */
90   xmlNodePtr    (*save_thyself)         (GstObject *object, xmlNodePtr parent);
91   void          (*restore_thyself)      (GstObject *object, xmlNodePtr self);
92 };
93
94 #define GST_OBJECT_NAME(obj)            (const gchar*)(((GstObject *)(obj))->name)
95 #define GST_OBJECT_PARENT(obj)          (((GstObject *)(obj))->parent)
96
97
98 #define GST_FLAGS(obj)                  GTK_OBJECT_FLAGS(obj)
99 #define GST_FLAG_IS_SET(obj,flag)       (GST_FLAGS (obj) & (1<<(flag)))
100 #define GST_FLAG_SET(obj,flag)          G_STMT_START{ (GST_FLAGS (obj) |= (1<<(flag))); }G_STMT_END
101 #define GST_FLAG_UNSET(obj,flag)        G_STMT_START{ (GST_FLAGS (obj) &= ~(1<<(flag))); }G_STMT_END
102
103 /* object locking */
104 #define GST_LOCK(obj)           (g_mutex_lock(GST_OBJECT(obj)->lock))
105 #define GST_TRYLOCK(obj)        (g_mutex_trylock(GST_OBJECT(obj)->lock))
106 #define GST_UNLOCK(obj)         (g_mutex_unlock(GST_OBJECT(obj)->lock))
107 #define GST_GET_LOCK(obj)       (GST_OBJECT(obj)->lock)
108
109
110 /* normal GtkObject stuff */
111 GtkType         gst_object_get_type             (void);
112 GstObject*      gst_object_new                  (void);
113
114 /* name routines */
115 void            gst_object_set_name             (GstObject *object, const gchar *name);
116 const gchar*    gst_object_get_name             (GstObject *object);
117
118 /* parentage routines */
119 void            gst_object_set_parent           (GstObject *object,GstObject *parent);
120 GstObject*      gst_object_get_parent           (GstObject *object);
121 void            gst_object_unparent             (GstObject *object);
122
123 xmlNodePtr      gst_object_save_thyself         (GstObject *object, xmlNodePtr parent);
124
125 /* refcounting */
126 #define         gst_object_ref(object)          gtk_object_ref(GTK_OBJECT(object));
127 #define         gst_object_unref(object)        gtk_object_unref(GTK_OBJECT(object));
128 #define         gst_object_sink(object)         gtk_object_sink(GTK_OBJECT(object));
129
130 /* destroying an object */
131 #define         gst_object_destroy(object)      gtk_object_destroy(GTK_OBJECT(object))
132
133 /* printing out the 'path' of the object */
134 gchar *         gst_object_get_path_string      (GstObject *object);
135
136
137 #ifdef __cplusplus
138 }
139 #endif /* __cplusplus */
140
141
142 #endif /* __GST_OBJECT_H__ */
143