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