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