69c718d980d8fe720e118cd48272831ed3d9212c
[platform/upstream/glib.git] / gobject / gobject.h
1 /* GObject - GLib Type, Object, Parameter and Signal Library
2  * Copyright (C) 1998, 1999, 2000 Tim Janik and Red Hat, Inc.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General
15  * Public License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19 #ifndef __G_GOBJECT_H__
20 #define __G_GOBJECT_H__
21
22 #include        <gobject/gtype.h>
23 #include        <gobject/gparam.h>
24
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif /* __cplusplus */
29
30
31 /* --- type macros --- */
32 #define G_TYPE_IS_OBJECT(type)     (G_TYPE_FUNDAMENTAL (type) == G_TYPE_OBJECT)
33 #define G_OBJECT(object)           (G_IS_OBJECT (object) ? ((GObject*) (object)) : \
34                                     G_TYPE_CHECK_INSTANCE_CAST ((object), G_TYPE_OBJECT, GObject))
35 #define G_OBJECT_CLASS(class)      (G_IS_OBJECT_CLASS (class) ? ((GObjectClass*) (class)) : \
36                                     G_TYPE_CHECK_CLASS_CAST ((class), G_TYPE_OBJECT, GObjectClass))
37 #define G_IS_OBJECT(object)        (((GObject*) (object)) != NULL && \
38                                     G_IS_OBJECT_CLASS (((GTypeInstance*) (object))->g_class))
39 #define G_IS_OBJECT_CLASS(class)   (((GTypeClass*) (class)) != NULL && \
40                                     G_TYPE_IS_OBJECT (((GTypeClass*) (class))->g_type))
41 #define G_OBJECT_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS ((object), G_TYPE_OBJECT, GObjectClass))
42 #define G_OBJECT_TYPE(object)      (G_TYPE_FROM_INSTANCE (object))
43 #define G_OBJECT_TYPE_NAME(object) (g_type_name (G_OBJECT_TYPE (object)))
44 #define G_OBJECT_CLASS_TYPE(class) (G_TYPE_FROM_CLASS (class))
45 #define G_OBJECT_CLASS_NAME(class) (g_type_name (G_OBJECT_CLASS_TYPE (class)))
46
47 #define G_NOTIFY_PRIORITY          (G_PRIORITY_HIGH_IDLE + 20)
48
49
50 /* --- typedefs & structures --- */
51 typedef struct _GObject      GObject;
52 typedef struct _GObjectClass GObjectClass;
53 typedef void (*GObjectGetParamFunc)     (GObject     *object,
54                                          guint        param_id,
55                                          GValue      *value,
56                                          GParamSpec  *pspec,
57                                          const gchar *trailer);
58 typedef void (*GObjectSetParamFunc)     (GObject     *object,
59                                          guint        param_id,
60                                          GValue      *value,
61                                          GParamSpec  *pspec,
62                                          const gchar *trailer);
63 typedef void (*GObjectFinalizeFunc)     (GObject     *object);
64 struct  _GObject
65 {
66   GTypeInstance g_type_instance;
67   
68   /*< private >*/
69   guint         ref_count;
70   GData        *qdata;
71 };
72 struct  _GObjectClass
73 {
74   GTypeClass   g_type_class;
75
76   guint        n_param_specs;
77   GParamSpec **param_specs;
78   
79   void       (*get_param)               (GObject        *object,
80                                          guint           param_id,
81                                          GValue         *value,
82                                          GParamSpec     *pspec,
83                                          const gchar    *trailer);
84   void       (*set_param)               (GObject        *object,
85                                          guint           param_id,
86                                          GValue         *value,
87                                          GParamSpec     *pspec,
88                                          const gchar    *trailer);
89   void       (*queue_param_changed)     (GObject        *object,
90                                          GParamSpec     *pspec);
91   void       (*dispatch_param_changed)  (GObject        *object,
92                                          GParamSpec     *pspec);
93   void       (*shutdown)                (GObject        *object);
94   void       (*finalize)                (GObject        *object);
95 };
96
97
98 /* --- prototypes --- */
99 void        g_object_class_install_param   (GObjectClass   *oclass,
100                                             guint           param_id,
101                                             GParamSpec     *pspec /* +1 ref */);
102 GParamSpec* g_object_class_find_param_spec (GObjectClass   *oclass,
103                                             const gchar    *param_name);
104 gpointer    g_object_new                   (GType           object_type,
105                                             const gchar    *first_param_name,
106                                             ...);
107 gpointer    g_object_new_valist            (GType           object_type,
108                                             const gchar    *first_param_name,
109                                             va_list         var_args);
110 void        g_object_set                   (GObject        *object,
111                                             const gchar    *first_param_name,
112                                             ...);
113 void        g_object_get                   (GObject        *object,
114                                             const gchar    *first_param_name,
115                                             ...);
116 void        g_object_set_valist            (GObject        *object,
117                                             const gchar    *first_param_name,
118                                             va_list         var_args);
119 void        g_object_get_valist            (GObject        *object,
120                                             const gchar    *first_param_name,
121                                             va_list         var_args);
122 void        g_object_set_param             (GObject        *object,
123                                             const gchar    *param_name,
124                                             const GValue   *value);
125 void        g_object_get_param             (GObject        *object,
126                                             const gchar    *param_name,
127                                             GValue         *value);
128 void        g_object_queue_param_changed   (GObject        *object,
129                                             const gchar    *param_name);
130 GObject*    g_object_ref                   (GObject        *object);
131 void        g_object_unref                 (GObject        *object);
132 gpointer    g_object_get_qdata             (GObject        *object,
133                                             GQuark          quark);
134 void        g_object_set_qdata             (GObject        *object,
135                                             GQuark          quark,
136                                             gpointer        data);
137 void        g_object_set_qdata_full        (GObject        *object,
138                                             GQuark          quark,
139                                             gpointer        data,
140                                             GDestroyNotify  destroy);
141 gpointer    g_object_steal_qdata           (GObject        *object,
142                                             GQuark          quark);
143
144
145 /* --- implementation macros --- */
146 #define G_WARN_INVALID_PARAM_ID(object, param_id, pspec) \
147 G_STMT_START { \
148   GObject *_object = (GObject*) (object); \
149   GParamSpec *_pspec = (GParamSpec*) (pspec); \
150   guint _param_id = (param_id); \
151   g_warning ("%s: invalid parameter id %u for \"%s\" of type `%s' in `%s'", \
152              G_STRLOC, \
153              _param_id, \
154              _pspec->name, \
155              g_type_name (G_PARAM_SPEC_TYPE (_pspec)), \
156              BSE_OBJECT_TYPE_NAME (_object)); \
157 } G_STMT_END
158
159
160
161 #ifdef __cplusplus
162 }
163 #endif /* __cplusplus */
164
165 #endif /* __G_GOBJECT_H__ */