66b7b7158409b9afa2b8e5b69012f9877ab590cf
[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 #if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION)
20 #error "Only <glib-object.h> can be included directly."
21 #endif
22
23 #ifndef __G_OBJECT_H__
24 #define __G_OBJECT_H__
25
26 #include        <gobject/gtype.h>
27 #include        <gobject/gvalue.h>
28 #include        <gobject/gparam.h>
29 #include        <gobject/gclosure.h>
30 #include        <gobject/gsignal.h>
31 #include        <signal.h>
32
33 G_BEGIN_DECLS
34
35 /* --- type macros --- */
36 #define G_TYPE_IS_OBJECT(type)      (G_TYPE_FUNDAMENTAL (type) == G_TYPE_OBJECT)
37 #define G_OBJECT(object)            (G_TYPE_CHECK_INSTANCE_CAST ((object), G_TYPE_OBJECT, GObject))
38 #define G_OBJECT_CLASS(class)       (G_TYPE_CHECK_CLASS_CAST ((class), G_TYPE_OBJECT, GObjectClass))
39 #define G_IS_OBJECT(object)         (G_TYPE_CHECK_INSTANCE_TYPE ((object), G_TYPE_OBJECT))
40 #define G_IS_OBJECT_CLASS(class)    (G_TYPE_CHECK_CLASS_TYPE ((class), G_TYPE_OBJECT))
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 #define G_VALUE_HOLDS_OBJECT(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_OBJECT))
47
48
49 /* --- typedefs & structures --- */
50 typedef struct _GObject                  GObject;
51 typedef struct _GObjectClass             GObjectClass;
52 typedef struct _GObjectConstructParam    GObjectConstructParam;
53 typedef void (*GObjectGetPropertyFunc)  (GObject      *object,
54                                          guint         property_id,
55                                          GValue       *value,
56                                          GParamSpec   *pspec);
57 typedef void (*GObjectSetPropertyFunc)  (GObject      *object,
58                                          guint         property_id,
59                                          const GValue *value,
60                                          GParamSpec   *pspec);
61 typedef void (*GObjectFinalizeFunc)     (GObject      *object);
62 typedef void (*GWeakNotify)             (gpointer      data,
63                                          GObject      *where_the_object_was);
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   /*< private >*/
77   GSList      *construct_properties;
78
79   /* public overridable methods */
80   GObject*   (*constructor)     (GType                  type,
81                                  guint                  n_construct_properties,
82                                  GObjectConstructParam *construct_properties);
83   void       (*set_property)            (GObject        *object,
84                                          guint           property_id,
85                                          const GValue   *value,
86                                          GParamSpec     *pspec);
87   void       (*get_property)            (GObject        *object,
88                                          guint           property_id,
89                                          GValue         *value,
90                                          GParamSpec     *pspec);
91   void       (*dispose)                 (GObject        *object);
92   void       (*finalize)                (GObject        *object);
93   
94   /* seldomly overidden */
95   void       (*dispatch_properties_changed) (GObject      *object,
96                                              guint         n_pspecs,
97                                              GParamSpec  **pspecs);
98
99   /* signals */
100   void       (*notify)                  (GObject        *object,
101                                          GParamSpec     *pspec);
102 };
103 struct _GObjectConstructParam
104 {
105   GParamSpec *pspec;
106   GValue     *value;
107 };
108
109
110 /* --- prototypes --- */
111 void        g_object_class_install_property   (GObjectClass   *oclass,
112                                                guint           property_id,
113                                                GParamSpec     *pspec);
114 GParamSpec* g_object_class_find_property      (GObjectClass   *oclass,
115                                                const gchar    *property_name);
116 GParamSpec**g_object_class_list_properties    (GObjectClass   *oclass,
117                                                guint          *n_properties);
118 gpointer    g_object_new                      (GType           object_type,
119                                                const gchar    *first_property_name,
120                                                ...);
121 gpointer    g_object_newv                     (GType           object_type,
122                                                guint           n_parameters,
123                                                GParameter     *parameters);
124 GObject*    g_object_new_valist               (GType           object_type,
125                                                const gchar    *first_property_name,
126                                                va_list         var_args);
127 void        g_object_set                      (gpointer        object,
128                                                const gchar    *first_property_name,
129                                                ...);
130 void        g_object_get                      (gpointer        object,
131                                                const gchar    *first_property_name,
132                                                ...);
133 gpointer    g_object_connect                  (gpointer        object,
134                                                const gchar    *signal_spec,
135                                                ...);
136 void        g_object_disconnect               (gpointer        object,
137                                                const gchar    *signal_spec,
138                                                ...);
139 void        g_object_set_valist               (GObject        *object,
140                                                const gchar    *first_property_name,
141                                                va_list         var_args);
142 void        g_object_get_valist               (GObject        *object,
143                                                const gchar    *first_property_name,
144                                                va_list         var_args);
145 void        g_object_set_property             (GObject        *object,
146                                                const gchar    *property_name,
147                                                const GValue   *value);
148 void        g_object_get_property             (GObject        *object,
149                                                const gchar    *property_name,
150                                                GValue         *value);
151 void        g_object_freeze_notify            (GObject        *object);
152 void        g_object_notify                   (GObject        *object,
153                                                const gchar    *property_name);
154 void        g_object_thaw_notify              (GObject        *object);
155 gpointer    g_object_ref                      (gpointer        object);
156 void        g_object_unref                    (gpointer        object);
157 void        g_object_weak_ref                 (GObject        *object,
158                                                GWeakNotify     notify,
159                                                gpointer        data);
160 void        g_object_weak_unref               (GObject        *object,
161                                                GWeakNotify     notify,
162                                                gpointer        data);
163 void        g_object_add_weak_pointer         (GObject        *object, 
164                                                gpointer       *weak_pointer_location);
165 void        g_object_remove_weak_pointer      (GObject        *object, 
166                                                gpointer       *weak_pointer_location);
167 gpointer    g_object_get_qdata                (GObject        *object,
168                                                GQuark          quark);
169 void        g_object_set_qdata                (GObject        *object,
170                                                GQuark          quark,
171                                                gpointer        data);
172 void        g_object_set_qdata_full           (GObject        *object,
173                                                GQuark          quark,
174                                                gpointer        data,
175                                                GDestroyNotify  destroy);
176 gpointer    g_object_steal_qdata              (GObject        *object,
177                                                GQuark          quark);
178 gpointer    g_object_get_data                 (GObject        *object,
179                                                const gchar    *key);
180 void        g_object_set_data                 (GObject        *object,
181                                                const gchar    *key,
182                                                gpointer        data);
183 void        g_object_set_data_full            (GObject        *object,
184                                                const gchar    *key,
185                                                gpointer        data,
186                                                GDestroyNotify  destroy);
187 gpointer    g_object_steal_data               (GObject        *object,
188                                                const gchar    *key);
189 void        g_object_watch_closure            (GObject        *object,
190                                                GClosure       *closure);
191 GClosure*   g_cclosure_new_object             (GCallback       callback_func,
192                                                GObject        *object);
193 GClosure*   g_cclosure_new_object_swap        (GCallback       callback_func,
194                                                GObject        *object);
195 GClosure*   g_closure_new_object              (guint           sizeof_closure,
196                                                GObject        *object);
197 void        g_value_set_object                (GValue         *value,
198                                                gpointer        v_object);
199 gpointer    g_value_get_object                (const GValue   *value);
200 GObject*    g_value_dup_object                (const GValue   *value);
201 gulong      g_signal_connect_object           (gpointer        instance,
202                                                const gchar    *detailed_signal,
203                                                GCallback       c_handler,
204                                                gpointer        gobject,
205                                                GConnectFlags   connect_flags);
206
207
208 /*< protected >*/
209 void        g_object_run_dispose              (GObject        *object);
210
211
212 /* --- implementation macros --- */
213 #define G_OBJECT_WARN_INVALID_PSPEC(object, pname, property_id, pspec) \
214 G_STMT_START { \
215   GObject *_object = (GObject*) (object); \
216   GParamSpec *_pspec = (GParamSpec*) (pspec); \
217   guint _property_id = (property_id); \
218   g_warning ("%s: invalid %s id %u for \"%s\" of type `%s' in `%s'", \
219              G_STRLOC, \
220              (pname), \
221              _property_id, \
222              _pspec->name, \
223              g_type_name (G_PARAM_SPEC_TYPE (_pspec)), \
224              G_OBJECT_TYPE_NAME (_object)); \
225 } G_STMT_END
226 #define G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec) \
227     G_OBJECT_WARN_INVALID_PSPEC ((object), "property", (property_id), (pspec))
228
229 G_END_DECLS
230
231 #endif /* __G_OBJECT_H__ */