Make some changes to the way that GMainContext works:
[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 struct  _GObject
58 {
59   GTypeInstance g_type_instance;
60   
61   /*< private >*/
62   guint         ref_count;
63   GData        *qdata;
64 };
65 struct  _GObjectClass
66 {
67   GTypeClass   g_type_class;
68
69   /*< private >*/
70   GSList      *construct_properties;
71
72   /* public overridable methods */
73   GObject*   (*constructor)     (GType                  type,
74                                  guint                  n_construct_properties,
75                                  GObjectConstructParam *construct_properties);
76   void       (*set_property)            (GObject        *object,
77                                          guint           property_id,
78                                          const GValue   *value,
79                                          GParamSpec     *pspec);
80   void       (*get_property)            (GObject        *object,
81                                          guint           property_id,
82                                          GValue         *value,
83                                          GParamSpec     *pspec);
84   void       (*shutdown)                (GObject        *object);
85   void       (*finalize)                (GObject        *object);
86
87   /* seldomly overidden */
88   void       (*dispatch_properties_changed) (GObject      *object,
89                                              guint         n_pspecs,
90                                              GParamSpec  **pspecs);
91
92   /* signals */
93   void       (*notify)                  (GObject        *object,
94                                          GParamSpec     *pspec);
95 };
96 struct _GObjectConstructParam
97 {
98   GParamSpec *pspec;
99   GValue     *value;
100 };
101
102
103 /* --- prototypes --- */
104 void        g_object_class_install_property   (GObjectClass   *oclass,
105                                                guint           property_id,
106                                                GParamSpec     *pspec);
107 GParamSpec* g_object_class_find_property      (GObjectClass   *oclass,
108                                                const gchar    *property_name);
109 GParamSpec**g_object_class_list_properties    (GObjectClass   *oclass,
110                                                guint          *n_properties);
111 gpointer    g_object_new                      (GType           object_type,
112                                                const gchar    *first_property_name,
113                                                ...);
114 gpointer    g_object_newv                     (GType           object_type,
115                                                guint           n_parameters,
116                                                GParameter     *parameters);
117 gpointer    g_object_new_valist               (GType           object_type,
118                                                const gchar    *first_property_name,
119                                                va_list         var_args);
120 gpointer    g_object_set                      (gpointer        object,
121                                                const gchar    *first_property_name,
122                                                ...);
123 void        g_object_get                      (gpointer        object,
124                                                const gchar    *first_property_name,
125                                                ...);
126 gpointer    g_object_connect                  (gpointer        object,
127                                                const gchar    *signal_spec,
128                                                ...);
129 gpointer    g_object_disconnect               (gpointer        object,
130                                                const gchar    *signal_spec,
131                                                ...);
132 void        g_object_set_valist               (GObject        *object,
133                                                const gchar    *first_property_name,
134                                                va_list         var_args);
135 void        g_object_get_valist               (GObject        *object,
136                                                const gchar    *first_property_name,
137                                                va_list         var_args);
138 void        g_object_set_property             (GObject        *object,
139                                                const gchar    *property_name,
140                                                const GValue   *value);
141 void        g_object_get_property             (GObject        *object,
142                                                const gchar    *property_name,
143                                                GValue         *value);
144 void        g_object_freeze_notify            (GObject        *object);
145 void        g_object_notify                   (GObject        *object,
146                                                const gchar    *property_name);
147 void        g_object_thaw_notify              (GObject        *object);
148 gpointer    g_object_ref                      (gpointer        object);
149 void        g_object_unref                    (gpointer        object);
150 gpointer    g_object_get_qdata                (GObject        *object,
151                                                GQuark          quark);
152 void        g_object_set_qdata                (GObject        *object,
153                                                GQuark          quark,
154                                                gpointer        data);
155 void        g_object_set_qdata_full           (GObject        *object,
156                                                GQuark          quark,
157                                                gpointer        data,
158                                                GDestroyNotify  destroy);
159 gpointer    g_object_steal_qdata              (GObject        *object,
160                                                GQuark          quark);
161 gpointer    g_object_get_data                 (GObject        *object,
162                                                const gchar    *key);
163 void        g_object_set_data                 (GObject        *object,
164                                                const gchar    *key,
165                                                gpointer        data);
166 void        g_object_set_data_full            (GObject        *object,
167                                                const gchar    *key,
168                                                gpointer        data,
169                                                GDestroyNotify  destroy);
170 gpointer    g_object_steal_data               (GObject        *object,
171                                                const gchar    *key);
172 void        g_object_watch_closure            (GObject        *object,
173                                                GClosure       *closure);
174 GClosure*   g_cclosure_new_object             (GCallback       callback_func,
175                                                gpointer        object);
176 GClosure*   g_cclosure_new_object_swap        (GCallback       callback_func,
177                                                gpointer        object);
178 GClosure*   g_closure_new_object              (guint           sizeof_closure,
179                                                GObject        *object);
180 void        g_value_set_object                (GValue         *value,
181                                                gpointer        v_object);
182 gpointer    g_value_get_object                (const GValue   *value);
183 GObject*    g_value_dup_object                (const GValue   *value);
184 guint       g_signal_connect_object           (gpointer        instance,
185                                                const gchar    *detailed_signal,
186                                                GCallback       c_handler,
187                                                gpointer        gobject,
188                                                GConnectFlags   connect_flags);
189
190
191 /* --- implementation macros --- */
192 #define G_OBJECT_WARN_INVALID_PSPEC(object, pname, property_id, pspec) \
193 G_STMT_START { \
194   GObject *_object = (GObject*) (object); \
195   GParamSpec *_pspec = (GParamSpec*) (pspec); \
196   guint _property_id = (property_id); \
197   g_warning ("%s: invalid %s id %u for \"%s\" of type `%s' in `%s'", \
198              G_STRLOC, \
199              (pname), \
200              _property_id, \
201              _pspec->name, \
202              g_type_name (G_PARAM_SPEC_TYPE (_pspec)), \
203              G_OBJECT_TYPE_NAME (_object)); \
204 } G_STMT_END
205 #define G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec) \
206     G_OBJECT_WARN_INVALID_PSPEC ((object), "property id", (property_id), (pspec))
207
208 G_END_DECLS
209
210 #endif /* __G_OBJECT_H__ */