we need signal.h for G_BREAKPOINT().
[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 #include        <gobject/gsignal.h>
27 #include        <signal.h>
28
29 G_BEGIN_DECLS
30
31 /* --- type macros --- */
32 #define G_TYPE_IS_OBJECT(type)      (G_TYPE_FUNDAMENTAL (type) == G_TYPE_OBJECT)
33 #define G_OBJECT(object)            (G_TYPE_CHECK_INSTANCE_CAST ((object), G_TYPE_OBJECT, GObject))
34 #define G_OBJECT_CLASS(class)       (G_TYPE_CHECK_CLASS_CAST ((class), G_TYPE_OBJECT, GObjectClass))
35 #define G_IS_OBJECT(object)         (G_TYPE_CHECK_INSTANCE_TYPE ((object), G_TYPE_OBJECT))
36 #define G_IS_OBJECT_CLASS(class)    (G_TYPE_CHECK_CLASS_TYPE ((class), G_TYPE_OBJECT))
37 #define G_OBJECT_GET_CLASS(object)  (G_TYPE_INSTANCE_GET_CLASS ((object), G_TYPE_OBJECT, GObjectClass))
38 #define G_OBJECT_TYPE(object)       (G_TYPE_FROM_INSTANCE (object))
39 #define G_OBJECT_TYPE_NAME(object)  (g_type_name (G_OBJECT_TYPE (object)))
40 #define G_OBJECT_CLASS_TYPE(class)  (G_TYPE_FROM_CLASS (class))
41 #define G_OBJECT_CLASS_NAME(class)  (g_type_name (G_OBJECT_CLASS_TYPE (class)))
42 #define G_VALUE_HOLDS_OBJECT(value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_OBJECT))
43
44
45 /* --- typedefs & structures --- */
46 typedef struct _GObject                  GObject;
47 typedef struct _GObjectClass             GObjectClass;
48 typedef struct _GObjectConstructParam    GObjectConstructParam;
49 typedef void (*GObjectGetPropertyFunc)  (GObject      *object,
50                                          guint         property_id,
51                                          GValue       *value,
52                                          GParamSpec   *pspec);
53 typedef void (*GObjectSetPropertyFunc)  (GObject      *object,
54                                          guint         property_id,
55                                          const GValue *value,
56                                          GParamSpec   *pspec);
57 typedef void (*GObjectFinalizeFunc)     (GObject      *object);
58 typedef void (*GWeakNotify)             (gpointer      data,
59                                          GObject      *where_the_object_was);
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 >*/
73   GSList      *construct_properties;
74
75   /* public overridable methods */
76   GObject*   (*constructor)     (GType                  type,
77                                  guint                  n_construct_properties,
78                                  GObjectConstructParam *construct_properties);
79   void       (*set_property)            (GObject        *object,
80                                          guint           property_id,
81                                          const GValue   *value,
82                                          GParamSpec     *pspec);
83   void       (*get_property)            (GObject        *object,
84                                          guint           property_id,
85                                          GValue         *value,
86                                          GParamSpec     *pspec);
87   void       (*dispose)                 (GObject        *object);
88   void       (*finalize)                (GObject        *object);
89   
90   /* seldomly overidden */
91   void       (*dispatch_properties_changed) (GObject      *object,
92                                              guint         n_pspecs,
93                                              GParamSpec  **pspecs);
94
95   /* signals */
96   void       (*notify)                  (GObject        *object,
97                                          GParamSpec     *pspec);
98 };
99 struct _GObjectConstructParam
100 {
101   GParamSpec *pspec;
102   GValue     *value;
103 };
104
105
106 /* --- prototypes --- */
107 void        g_object_class_install_property   (GObjectClass   *oclass,
108                                                guint           property_id,
109                                                GParamSpec     *pspec);
110 GParamSpec* g_object_class_find_property      (GObjectClass   *oclass,
111                                                const gchar    *property_name);
112 GParamSpec**g_object_class_list_properties    (GObjectClass   *oclass,
113                                                guint          *n_properties);
114 gpointer    g_object_new                      (GType           object_type,
115                                                const gchar    *first_property_name,
116                                                ...);
117 gpointer    g_object_newv                     (GType           object_type,
118                                                guint           n_parameters,
119                                                GParameter     *parameters);
120 GObject*    g_object_new_valist               (GType           object_type,
121                                                const gchar    *first_property_name,
122                                                va_list         var_args);
123 void        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 void        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 void        g_object_weak_ref                 (GObject        *object,
154                                                GWeakNotify     notify,
155                                                gpointer        data);
156 void        g_object_weak_unref               (GObject        *object,
157                                                GWeakNotify     notify,
158                                                gpointer        data);
159 void        g_object_add_weak_pointer         (GObject        *object, 
160                                                gpointer       *weak_pointer_location);
161 void        g_object_remove_weak_pointer      (GObject        *object, 
162                                                gpointer       *weak_pointer_location);
163 gpointer    g_object_get_qdata                (GObject        *object,
164                                                GQuark          quark);
165 void        g_object_set_qdata                (GObject        *object,
166                                                GQuark          quark,
167                                                gpointer        data);
168 void        g_object_set_qdata_full           (GObject        *object,
169                                                GQuark          quark,
170                                                gpointer        data,
171                                                GDestroyNotify  destroy);
172 gpointer    g_object_steal_qdata              (GObject        *object,
173                                                GQuark          quark);
174 gpointer    g_object_get_data                 (GObject        *object,
175                                                const gchar    *key);
176 void        g_object_set_data                 (GObject        *object,
177                                                const gchar    *key,
178                                                gpointer        data);
179 void        g_object_set_data_full            (GObject        *object,
180                                                const gchar    *key,
181                                                gpointer        data,
182                                                GDestroyNotify  destroy);
183 gpointer    g_object_steal_data               (GObject        *object,
184                                                const gchar    *key);
185 void        g_object_watch_closure            (GObject        *object,
186                                                GClosure       *closure);
187 GClosure*   g_cclosure_new_object             (GCallback       callback_func,
188                                                GObject        *object);
189 GClosure*   g_cclosure_new_object_swap        (GCallback       callback_func,
190                                                GObject        *object);
191 GClosure*   g_closure_new_object              (guint           sizeof_closure,
192                                                GObject        *object);
193 void        g_value_set_object                (GValue         *value,
194                                                gpointer        v_object);
195 gpointer    g_value_get_object                (const GValue   *value);
196 GObject*    g_value_dup_object                (const GValue   *value);
197 guint       g_signal_connect_object           (gpointer        instance,
198                                                const gchar    *detailed_signal,
199                                                GCallback       c_handler,
200                                                gpointer        gobject,
201                                                GConnectFlags   connect_flags);
202
203
204 /*< protected >*/
205 void        g_object_run_dispose              (GObject        *object);
206
207
208 /* --- implementation macros --- */
209 #define G_OBJECT_WARN_INVALID_PSPEC(object, pname, property_id, pspec) \
210 G_STMT_START { \
211   GObject *_object = (GObject*) (object); \
212   GParamSpec *_pspec = (GParamSpec*) (pspec); \
213   guint _property_id = (property_id); \
214   g_warning ("%s: invalid %s id %u for \"%s\" of type `%s' in `%s'", \
215              G_STRLOC, \
216              (pname), \
217              _property_id, \
218              _pspec->name, \
219              g_type_name (G_PARAM_SPEC_TYPE (_pspec)), \
220              G_OBJECT_TYPE_NAME (_object)); \
221 } G_STMT_END
222 #define G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec) \
223     G_OBJECT_WARN_INVALID_PSPEC ((object), "property id", (property_id), (pspec))
224
225 G_END_DECLS
226
227 #endif /* __G_OBJECT_H__ */