[kdbus] Do not set body message if signature field is empty
[platform/upstream/glib.git] / gobject / gtypemodule.h
1 /* GObject - GLib Type, Object, Parameter and Signal Library
2  * Copyright (C) 2000 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 Public
15  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
16  */
17 #ifndef __G_TYPE_MODULE_H__
18 #define __G_TYPE_MODULE_H__
19
20 #if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION)
21 #error "Only <glib-object.h> can be included directly."
22 #endif
23
24 #include <gobject/gobject.h>
25 #include <gobject/genums.h>
26
27 G_BEGIN_DECLS
28
29 typedef struct _GTypeModule      GTypeModule;
30 typedef struct _GTypeModuleClass GTypeModuleClass;
31
32 #define G_TYPE_TYPE_MODULE              (g_type_module_get_type ())
33 #define G_TYPE_MODULE(module)           (G_TYPE_CHECK_INSTANCE_CAST ((module), G_TYPE_TYPE_MODULE, GTypeModule))
34 #define G_TYPE_MODULE_CLASS(class)      (G_TYPE_CHECK_CLASS_CAST ((class), G_TYPE_TYPE_MODULE, GTypeModuleClass))
35 #define G_IS_TYPE_MODULE(module)        (G_TYPE_CHECK_INSTANCE_TYPE ((module), G_TYPE_TYPE_MODULE))
36 #define G_IS_TYPE_MODULE_CLASS(class)   (G_TYPE_CHECK_CLASS_TYPE ((class), G_TYPE_TYPE_MODULE))
37 #define G_TYPE_MODULE_GET_CLASS(module) (G_TYPE_INSTANCE_GET_CLASS ((module), G_TYPE_TYPE_MODULE, GTypeModuleClass))
38
39 /**
40  * GTypeModule:
41  * @name: the name of the module
42  * 
43  * The members of the GTypeModule structure should not 
44  * be accessed directly, except for the @name field.
45  */
46 struct _GTypeModule 
47 {
48   GObject parent_instance;
49
50   guint use_count;
51   GSList *type_infos;
52   GSList *interface_infos;
53
54   /*< public >*/
55   gchar *name;
56 };
57
58 /**
59  * GTypeModuleClass:
60  * @parent_class: the parent class
61  * @load: loads the module and registers one or more types using
62  *  g_type_module_register_type().
63  * @unload: unloads the module
64  * 
65  * In order to implement dynamic loading of types based on #GTypeModule, 
66  * the @load and @unload functions in #GTypeModuleClass must be implemented.
67  */
68 struct _GTypeModuleClass
69 {
70   GObjectClass parent_class;
71
72   /*< public >*/
73   gboolean (* load)   (GTypeModule *module);
74   void     (* unload) (GTypeModule *module);
75
76   /*< private >*/
77   /* Padding for future expansion */
78   void (*reserved1) (void);
79   void (*reserved2) (void);
80   void (*reserved3) (void);
81   void (*reserved4) (void);
82 };
83
84 /**
85  * G_DEFINE_DYNAMIC_TYPE:
86  * @TN: The name of the new type, in Camel case.
87  * @t_n: The name of the new type, in lowercase, with words
88  *  separated by '_'.
89  * @T_P: The #GType of the parent type.
90  * 
91  * A convenience macro for dynamic type implementations, which declares a
92  * class initialization function, an instance initialization function (see 
93  * #GTypeInfo for information about these) and a static variable named 
94  * @t_n<!-- -->_parent_class pointing to the parent class. Furthermore, 
95  * it defines a `*_get_type()` and a static `*_register_type()` functions
96  * for use in your `module_init()`.
97  *
98  * See G_DEFINE_DYNAMIC_TYPE_EXTENDED() for an example.
99  * 
100  * Since: 2.14
101  */
102 #define G_DEFINE_DYNAMIC_TYPE(TN, t_n, T_P)          G_DEFINE_DYNAMIC_TYPE_EXTENDED (TN, t_n, T_P, 0, {})
103 /**
104  * G_DEFINE_DYNAMIC_TYPE_EXTENDED:
105  * @TypeName: The name of the new type, in Camel case.
106  * @type_name: The name of the new type, in lowercase, with words
107  *  separated by '_'.
108  * @TYPE_PARENT: The #GType of the parent type.
109  * @flags: #GTypeFlags to pass to g_type_module_register_type()
110  * @CODE: Custom code that gets inserted in the *_get_type() function.
111  * 
112  * A more general version of G_DEFINE_DYNAMIC_TYPE() which
113  * allows to specify #GTypeFlags and custom code.
114  * 
115  * |[
116  * G_DEFINE_DYNAMIC_TYPE_EXTENDED (GtkGadget,
117  *                                 gtk_gadget,
118  *                                 GTK_TYPE_THING,
119  *                                 0,
120  *                                 G_IMPLEMENT_INTERFACE_DYNAMIC (TYPE_GIZMO,
121  *                                                                gtk_gadget_gizmo_init));
122  * ]|
123  * expands to
124  * |[
125  * static void     gtk_gadget_init              (GtkGadget      *self);
126  * static void     gtk_gadget_class_init        (GtkGadgetClass *klass);
127  * static void     gtk_gadget_class_finalize    (GtkGadgetClass *klass);
128  * 
129  * static gpointer gtk_gadget_parent_class = NULL;
130  * static GType    gtk_gadget_type_id = 0;
131  * 
132  * static void     gtk_gadget_class_intern_init (gpointer klass)
133  * {
134  *   gtk_gadget_parent_class = g_type_class_peek_parent (klass); 
135  *   gtk_gadget_class_init ((GtkGadgetClass*) klass); 
136  * }
137  * 
138  * GType
139  * gtk_gadget_get_type (void)
140  * {
141  *   return gtk_gadget_type_id;
142  * }
143  * 
144  * static void
145  * gtk_gadget_register_type (GTypeModule *type_module)
146  * {
147  *   const GTypeInfo g_define_type_info = {
148  *     sizeof (GtkGadgetClass),
149  *     (GBaseInitFunc) NULL,
150  *     (GBaseFinalizeFunc) NULL,
151  *     (GClassInitFunc) gtk_gadget_class_intern_init,
152  *     (GClassFinalizeFunc) gtk_gadget_class_finalize,
153  *     NULL,   // class_data
154  *     sizeof (GtkGadget),
155  *     0,      // n_preallocs
156  *     (GInstanceInitFunc) gtk_gadget_init, 
157  *     NULL    // value_table
158  *   };
159  *   gtk_gadget_type_id = g_type_module_register_type (type_module,
160  *                                                     GTK_TYPE_THING,
161  *                                                     "GtkGadget",
162  *                                                     &g_define_type_info,
163  *                                                     (GTypeFlags) flags);
164  *   {
165  *     const GInterfaceInfo g_implement_interface_info = {
166  *       (GInterfaceInitFunc) gtk_gadget_gizmo_init
167  *     };
168  *     g_type_module_add_interface (type_module, g_define_type_id, TYPE_GIZMO, &g_implement_interface_info);
169  *   }
170  * }
171  * ]|
172  * 
173  * Since: 2.14
174  */
175 #define G_DEFINE_DYNAMIC_TYPE_EXTENDED(TypeName, type_name, TYPE_PARENT, flags, CODE) \
176 static void     type_name##_init              (TypeName        *self); \
177 static void     type_name##_class_init        (TypeName##Class *klass); \
178 static void     type_name##_class_finalize    (TypeName##Class *klass); \
179 static gpointer type_name##_parent_class = NULL; \
180 static GType    type_name##_type_id = 0; \
181 static gint     TypeName##_private_offset; \
182 \
183 _G_DEFINE_TYPE_EXTENDED_CLASS_INIT(TypeName, type_name) \
184 \
185 static inline gpointer \
186 type_name##_get_instance_private (TypeName *self) \
187 { \
188   return (G_STRUCT_MEMBER_P (self, TypeName##_private_offset)); \
189 } \
190 \
191 GType \
192 type_name##_get_type (void) \
193 { \
194   return type_name##_type_id; \
195 } \
196 static void \
197 type_name##_register_type (GTypeModule *type_module) \
198 { \
199   GType g_define_type_id G_GNUC_UNUSED; \
200   const GTypeInfo g_define_type_info = { \
201     sizeof (TypeName##Class), \
202     (GBaseInitFunc) NULL, \
203     (GBaseFinalizeFunc) NULL, \
204     (GClassInitFunc) type_name##_class_intern_init, \
205     (GClassFinalizeFunc) type_name##_class_finalize, \
206     NULL,   /* class_data */ \
207     sizeof (TypeName), \
208     0,      /* n_preallocs */ \
209     (GInstanceInitFunc) type_name##_init, \
210     NULL    /* value_table */ \
211   }; \
212   type_name##_type_id = g_type_module_register_type (type_module, \
213                                                      TYPE_PARENT, \
214                                                      #TypeName, \
215                                                      &g_define_type_info, \
216                                                      (GTypeFlags) flags); \
217   g_define_type_id = type_name##_type_id; \
218   { CODE ; } \
219 }
220
221 /**
222  * G_IMPLEMENT_INTERFACE_DYNAMIC:
223  * @TYPE_IFACE: The #GType of the interface to add
224  * @iface_init: The interface init function
225  *
226  * A convenience macro to ease interface addition in the @_C_ section
227  * of G_DEFINE_DYNAMIC_TYPE_EXTENDED(). See G_DEFINE_DYNAMIC_TYPE_EXTENDED()
228  * for an example.
229  *
230  * Note that this macro can only be used together with the
231  * G_DEFINE_DYNAMIC_TYPE_EXTENDED macros, since it depends on variable
232  * names from that macro.
233  *
234  * Since: 2.24
235  */
236 #define G_IMPLEMENT_INTERFACE_DYNAMIC(TYPE_IFACE, iface_init)       { \
237   const GInterfaceInfo g_implement_interface_info = { \
238     (GInterfaceInitFunc) iface_init, NULL, NULL      \
239   }; \
240   g_type_module_add_interface (type_module, g_define_type_id, TYPE_IFACE, &g_implement_interface_info); \
241 }
242
243 #define G_ADD_PRIVATE_DYNAMIC(TypeName)         { \
244   TypeName##_private_offset = sizeof (TypeName##Private); \
245 }
246
247 GLIB_AVAILABLE_IN_ALL
248 GType    g_type_module_get_type       (void) G_GNUC_CONST;
249 GLIB_AVAILABLE_IN_ALL
250 gboolean g_type_module_use            (GTypeModule          *module);
251 GLIB_AVAILABLE_IN_ALL
252 void     g_type_module_unuse          (GTypeModule          *module);
253 GLIB_AVAILABLE_IN_ALL
254 void     g_type_module_set_name       (GTypeModule          *module,
255                                        const gchar          *name);
256 GLIB_AVAILABLE_IN_ALL
257 GType    g_type_module_register_type  (GTypeModule          *module,
258                                        GType                 parent_type,
259                                        const gchar          *type_name,
260                                        const GTypeInfo      *type_info,
261                                        GTypeFlags            flags);
262 GLIB_AVAILABLE_IN_ALL
263 void     g_type_module_add_interface  (GTypeModule          *module,
264                                        GType                 instance_type,
265                                        GType                 interface_type,
266                                        const GInterfaceInfo *interface_info);
267 GLIB_AVAILABLE_IN_ALL
268 GType    g_type_module_register_enum  (GTypeModule          *module,
269                                        const gchar          *name,
270                                        const GEnumValue     *const_static_values);
271 GLIB_AVAILABLE_IN_ALL
272 GType    g_type_module_register_flags (GTypeModule          *module,
273                                        const gchar          *name,
274                                        const GFlagsValue    *const_static_values);
275
276 G_END_DECLS
277
278 #endif /* __G_TYPE_MODULE_H__ */