doh, s/BSE_OBJECT_TYPE_NAME/G_OBJECT_TYPE_NAME/; reported by Maas-Maarten
[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_OBJECT_H__
20 #define __G_OBJECT_H__
21
22 #include        <gobject/gtype.h>
23 #include        <gobject/gvalue.h>
24 #include        <gobject/gparam.h>
25 #include        <gobject/gclosure.h>
26
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif /* __cplusplus */
31
32
33 /* --- type macros --- */
34 #define G_TYPE_IS_OBJECT(type)     (G_TYPE_FUNDAMENTAL (type) == G_TYPE_OBJECT)
35 #define G_OBJECT(object)           (G_TYPE_CHECK_INSTANCE_CAST ((object), G_TYPE_OBJECT, GObject))
36 #define G_OBJECT_CLASS(class)      (G_TYPE_CHECK_CLASS_CAST ((class), G_TYPE_OBJECT, GObjectClass))
37 #define G_IS_OBJECT(object)        (G_TYPE_CHECK_INSTANCE_TYPE ((object), G_TYPE_OBJECT))
38 #define G_IS_OBJECT_CLASS(class)   (G_TYPE_CHECK_CLASS_TYPE ((class), G_TYPE_OBJECT))
39 #define G_OBJECT_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS ((object), G_TYPE_OBJECT, GObjectClass))
40 #define G_OBJECT_TYPE(object)      (G_TYPE_FROM_INSTANCE (object))
41 #define G_OBJECT_TYPE_NAME(object) (g_type_name (G_OBJECT_TYPE (object)))
42 #define G_OBJECT_CLASS_TYPE(class) (G_TYPE_FROM_CLASS (class))
43 #define G_OBJECT_CLASS_NAME(class) (g_type_name (G_OBJECT_CLASS_TYPE (class)))
44 #define G_IS_VALUE_OBJECT(value)   (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_OBJECT))
45
46 #define G_NOTIFY_PRIORITY          (G_PRIORITY_HIGH_IDLE + 20)
47
48
49 /* --- typedefs & structures --- */
50 typedef struct _GObject               GObject;
51 typedef struct _GObjectClass          GObjectClass;
52 typedef struct _GObjectConstructParam GObjectConstructParam;
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                                          const 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   GObject*   (*constructor)     (GType                  type, // FIXME!!!
80                                  guint                  n_construct_params,
81                                  GObjectConstructParam *construct_params);
82   void       (*get_param)               (GObject        *object,
83                                          guint           param_id,
84                                          GValue         *value,
85                                          GParamSpec     *pspec,
86                                          const gchar    *trailer);
87   void       (*set_param)               (GObject        *object,
88                                          guint           param_id,
89                                          const GValue   *value,
90                                          GParamSpec     *pspec,
91                                          const gchar    *trailer);
92   void       (*queue_param_changed)     (GObject        *object,
93                                          GParamSpec     *pspec);
94   void       (*dispatch_param_changed)  (GObject        *object,
95                                          GParamSpec     *pspec);
96   void       (*shutdown)                (GObject        *object);
97   void       (*finalize)                (GObject        *object);
98 };
99 struct _GObjectConstructParam
100 {
101   GParamSpec *pspec;
102   GValue     *value;
103   gchar      *trailer;
104 };
105
106
107 /* --- prototypes --- */
108 void        g_object_class_install_param   (GObjectClass   *oclass,
109                                             guint           param_id,
110                                             GParamSpec     *pspec /* +1 ref */);
111 GParamSpec* g_object_class_find_param_spec (GObjectClass   *oclass,
112                                             const gchar    *param_name);
113 gpointer    g_object_new                   (GType           object_type,
114                                             const gchar    *first_param_name,
115                                             ...);
116 gpointer    g_object_new_valist            (GType           object_type,
117                                             const gchar    *first_param_name,
118                                             va_list         var_args);
119 void        g_object_set                   (GObject        *object,
120                                             const gchar    *first_param_name,
121                                             ...);
122 void        g_object_get                   (GObject        *object,
123                                             const gchar    *first_param_name,
124                                             ...);
125 void        g_object_set_valist            (GObject        *object,
126                                             const gchar    *first_param_name,
127                                             va_list         var_args);
128 void        g_object_get_valist            (GObject        *object,
129                                             const gchar    *first_param_name,
130                                             va_list         var_args);
131 void        g_object_set_param             (GObject        *object,
132                                             const gchar    *param_name,
133                                             const GValue   *value);
134 void        g_object_get_param             (GObject        *object,
135                                             const gchar    *param_name,
136                                             GValue         *value);
137 void        g_object_queue_param_changed   (GObject        *object,
138                                             const gchar    *param_name);
139 GObject*    g_object_ref                   (GObject        *object);
140 void        g_object_unref                 (GObject        *object);
141 gpointer    g_object_get_qdata             (GObject        *object,
142                                             GQuark          quark);
143 void        g_object_set_qdata             (GObject        *object,
144                                             GQuark          quark,
145                                             gpointer        data);
146 void        g_object_set_qdata_full        (GObject        *object,
147                                             GQuark          quark,
148                                             gpointer        data,
149                                             GDestroyNotify  destroy);
150 gpointer    g_object_steal_qdata           (GObject        *object,
151                                             GQuark          quark);
152 void        g_object_watch_closure         (GObject        *object,
153                                             GClosure       *closure);
154 GClosure*   g_cclosure_new_object          (GCallback       callback_func,
155                                             gpointer        object);
156 GClosure*   g_cclosure_new_object_swap     (GCallback       callback_func,
157                                             gpointer        object);
158 GClosure*   g_closure_new_object           (guint           sizeof_closure,
159                                             GObject        *object);
160 void        g_value_set_object             (GValue         *value,
161                                             GObject        *v_object);
162 GObject*    g_value_get_object             (const GValue   *value);
163 GObject*    g_value_dup_object             (const GValue   *value);
164
165
166 /* --- implementation macros --- */
167 #define G_WARN_INVALID_PARAM_ID(object, param_id, pspec) \
168 G_STMT_START { \
169   GObject *_object = (GObject*) (object); \
170   GParamSpec *_pspec = (GParamSpec*) (pspec); \
171   guint _param_id = (param_id); \
172   g_warning ("%s: invalid parameter id %u for \"%s\" of type `%s' in `%s'", \
173              G_STRLOC, \
174              _param_id, \
175              _pspec->name, \
176              g_type_name (G_PARAM_SPEC_TYPE (_pspec)), \
177              G_OBJECT_TYPE_NAME (_object)); \
178 } G_STMT_END
179
180
181
182 #ifdef __cplusplus
183 }
184 #endif /* __cplusplus */
185
186 #endif /* __G_OBJECT_H__ */