changed prototype of g_boxed_type_register_static() to contain an optional
[platform/upstream/glib.git] / gobject / gobject.h
1 /* GObject - GLib Type, Object, Parameter and Signal Library
2  * Copyright (C) 1998-1999, 2000-2001 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_VALUE_HOLDS_OBJECT(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_OBJECT))
45
46
47 /* --- typedefs & structures --- */
48 typedef struct _GObject                  GObject;
49 typedef struct _GObjectClass             GObjectClass;
50 typedef struct _GObjectConstructParam    GObjectConstructParam;
51 typedef void (*GObjectGetPropertyFunc)  (GObject      *object,
52                                          guint         property_id,
53                                          GValue       *value,
54                                          GParamSpec   *pspec);
55 typedef void (*GObjectSetPropertyFunc)  (GObject      *object,
56                                          guint         property_id,
57                                          const GValue *value,
58                                          GParamSpec   *pspec);
59 typedef void (*GObjectFinalizeFunc)     (GObject      *object);
60 struct  _GObject
61 {
62   GTypeInstance g_type_instance;
63   
64   /*< private >*/
65   guint         ref_count;
66   GData        *qdata;
67 };
68 struct  _GObjectClass
69 {
70   GTypeClass   g_type_class;
71
72   /* private, these fields might vanish */
73   guint        n_property_specs;
74   GParamSpec **property_specs;
75   GSList      *construct_properties;
76
77   /* public overridable methods */
78   GObject*   (*constructor)     (GType                  type,
79                                  guint                  n_construct_properties,
80                                  GObjectConstructParam *construct_properties);
81   void       (*set_property)            (GObject        *object,
82                                          guint           property_id,
83                                          const GValue   *value,
84                                          GParamSpec     *pspec);
85   void       (*get_property)            (GObject        *object,
86                                          guint           property_id,
87                                          GValue         *value,
88                                          GParamSpec     *pspec);
89   void       (*shutdown)                (GObject        *object);
90   void       (*finalize)                (GObject        *object);
91
92   /*< private >*/
93   void       (*dispatch_properties_changed) (GObject      *object,
94                                              guint         n_pspecs,
95                                              GParamSpec  **pspecs);
96
97   /* signals */
98   void       (*properties_changed)      (GObject        *object,
99                                          guint           n_pspecs,
100                                          GParamSpec    **pspecs);
101   void       (*notify)                  (GObject        *object,
102                                          GParamSpec     *pspec);
103 };
104 struct _GObjectConstructParam
105 {
106   GParamSpec  *pspec;
107   GValue      *value;
108 };
109
110
111 /* --- prototypes --- */
112 void        g_object_class_install_property   (GObjectClass   *oclass,
113                                                guint           property_id,
114                                                GParamSpec     *pspec);
115 GParamSpec* g_object_class_find_property      (GObjectClass   *oclass,
116                                                const gchar    *property_name);
117 gpointer    g_object_new                      (GType           object_type,
118                                                const gchar    *first_property_name,
119                                                ...);
120 gpointer    g_object_new_valist               (GType           object_type,
121                                                const gchar    *first_property_name,
122                                                va_list         var_args);
123 gpointer    g_object_set                      (gpointer        object,
124                                                const gchar    *first_property_name,
125                                                ...);
126 void        g_object_get                      (gpointer        object,
127                                                const gchar    *first_property_name,
128                                                ...);
129 gpointer    g_object_connect                  (gpointer        object,
130                                                const gchar    *signal_spec,
131                                                ...);
132 gpointer    g_object_disconnect               (gpointer        object,
133                                                const gchar    *signal_spec,
134                                                ...);
135 void        g_object_set_valist               (GObject        *object,
136                                                const gchar    *first_property_name,
137                                                va_list         var_args);
138 void        g_object_get_valist               (GObject        *object,
139                                                const gchar    *first_property_name,
140                                                va_list         var_args);
141 void        g_object_set_property             (GObject        *object,
142                                                const gchar    *property_name,
143                                                const GValue   *value);
144 void        g_object_get_property             (GObject        *object,
145                                                const gchar    *property_name,
146                                                GValue         *value);
147 void        g_object_freeze_notify            (GObject        *object);
148 void        g_object_notify                   (GObject        *object,
149                                                const gchar    *property_name);
150 void        g_object_thaw_notify              (GObject        *object);
151 gpointer    g_object_ref                      (gpointer        object);
152 void        g_object_unref                    (gpointer        object);
153 gpointer    g_object_get_qdata                (GObject        *object,
154                                                GQuark          quark);
155 void        g_object_set_qdata                (GObject        *object,
156                                                GQuark          quark,
157                                                gpointer        data);
158 void        g_object_set_qdata_full           (GObject        *object,
159                                                GQuark          quark,
160                                                gpointer        data,
161                                                GDestroyNotify  destroy);
162 gpointer    g_object_steal_qdata              (GObject        *object,
163                                                GQuark          quark);
164 gpointer    g_object_get_data                 (GObject        *object,
165                                                const gchar    *key);
166 void        g_object_set_data                 (GObject        *object,
167                                                const gchar    *key,
168                                                gpointer        data);
169 void        g_object_set_data_full            (GObject        *object,
170                                                const gchar    *key,
171                                                gpointer        data,
172                                                GDestroyNotify  destroy);
173 gpointer    g_object_steal_data               (GObject        *object,
174                                                const gchar    *key);
175 void        g_object_watch_closure            (GObject        *object,
176                                                GClosure       *closure);
177 GClosure*   g_cclosure_new_object             (GCallback       callback_func,
178                                                gpointer        object);
179 GClosure*   g_cclosure_new_object_swap        (GCallback       callback_func,
180                                                gpointer        object);
181 GClosure*   g_closure_new_object              (guint           sizeof_closure,
182                                                GObject        *object);
183 void        g_value_set_object                (GValue         *value,
184                                                GObject        *v_object);
185 gpointer    g_value_get_object                (const GValue   *value);
186 GObject*    g_value_dup_object                (const GValue   *value);
187 guint       g_signal_connect_object           (gpointer        instance,
188                                                const gchar    *detailed_signal,
189                                                GCallback       c_handler,
190                                                gpointer        gobject,
191                                                gboolean        swapped,
192                                                gboolean        after);
193
194
195 /* --- implementation macros --- */
196 #define G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec) \
197 G_STMT_START { \
198   GObject *_object = (GObject*) (object); \
199   GParamSpec *_pspec = (GParamSpec*) (pspec); \
200   guint _property_id = (property_id); \
201   g_warning ("%s: invalid property id %u for \"%s\" of type `%s' in `%s'", \
202              G_STRLOC, \
203              _property_id, \
204              _pspec->name, \
205              g_type_name (G_PARAM_SPEC_TYPE (_pspec)), \
206              G_OBJECT_TYPE_NAME (_object)); \
207 } G_STMT_END
208
209
210
211 #ifdef __cplusplus
212 }
213 #endif /* __cplusplus */
214
215 #endif /* __G_OBJECT_H__ */