nexmon – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 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 | G_GNUC_UNUSED \ |
||
186 | static inline gpointer \ |
||
187 | type_name##_get_instance_private (TypeName *self) \ |
||
188 | { \ |
||
189 | return (G_STRUCT_MEMBER_P (self, TypeName##_private_offset)); \ |
||
190 | } \ |
||
191 | \ |
||
192 | GType \ |
||
193 | type_name##_get_type (void) \ |
||
194 | { \ |
||
195 | return type_name##_type_id; \ |
||
196 | } \ |
||
197 | static void \ |
||
198 | type_name##_register_type (GTypeModule *type_module) \ |
||
199 | { \ |
||
200 | GType g_define_type_id G_GNUC_UNUSED; \ |
||
201 | const GTypeInfo g_define_type_info = { \ |
||
202 | sizeof (TypeName##Class), \ |
||
203 | (GBaseInitFunc) NULL, \ |
||
204 | (GBaseFinalizeFunc) NULL, \ |
||
205 | (GClassInitFunc) type_name##_class_intern_init, \ |
||
206 | (GClassFinalizeFunc) type_name##_class_finalize, \ |
||
207 | NULL, /* class_data */ \ |
||
208 | sizeof (TypeName), \ |
||
209 | 0, /* n_preallocs */ \ |
||
210 | (GInstanceInitFunc) type_name##_init, \ |
||
211 | NULL /* value_table */ \ |
||
212 | }; \ |
||
213 | type_name##_type_id = g_type_module_register_type (type_module, \ |
||
214 | TYPE_PARENT, \ |
||
215 | #TypeName, \ |
||
216 | &g_define_type_info, \ |
||
217 | (GTypeFlags) flags); \ |
||
218 | g_define_type_id = type_name##_type_id; \ |
||
219 | { CODE ; } \ |
||
220 | } |
||
221 | |||
222 | /** |
||
223 | * G_IMPLEMENT_INTERFACE_DYNAMIC: |
||
224 | * @TYPE_IFACE: The #GType of the interface to add |
||
225 | * @iface_init: The interface init function |
||
226 | * |
||
227 | * A convenience macro to ease interface addition in the @_C_ section |
||
228 | * of G_DEFINE_DYNAMIC_TYPE_EXTENDED(). See G_DEFINE_DYNAMIC_TYPE_EXTENDED() |
||
229 | * for an example. |
||
230 | * |
||
231 | * Note that this macro can only be used together with the |
||
232 | * G_DEFINE_DYNAMIC_TYPE_EXTENDED macros, since it depends on variable |
||
233 | * names from that macro. |
||
234 | * |
||
235 | * Since: 2.24 |
||
236 | */ |
||
237 | #define G_IMPLEMENT_INTERFACE_DYNAMIC(TYPE_IFACE, iface_init) { \ |
||
238 | const GInterfaceInfo g_implement_interface_info = { \ |
||
239 | (GInterfaceInitFunc) iface_init, NULL, NULL \ |
||
240 | }; \ |
||
241 | g_type_module_add_interface (type_module, g_define_type_id, TYPE_IFACE, &g_implement_interface_info); \ |
||
242 | } |
||
243 | |||
244 | /** |
||
245 | * G_ADD_PRIVATE_DYNAMIC: |
||
246 | * @TypeName: the name of the type in CamelCase |
||
247 | * |
||
248 | * A convenience macro to ease adding private data to instances of a new dynamic |
||
249 | * type in the @_C_ section of G_DEFINE_DYNAMIC_TYPE_EXTENDED(). See |
||
250 | * G_ADD_PRIVATE() for details, it is similar but for static types. |
||
251 | * |
||
252 | * Note that this macro can only be used together with the |
||
253 | * G_DEFINE_DYNAMIC_TYPE_EXTENDED macros, since it depends on variable |
||
254 | * names from that macro. |
||
255 | * |
||
256 | * Since: 2.38 |
||
257 | */ |
||
258 | #define G_ADD_PRIVATE_DYNAMIC(TypeName) { \ |
||
259 | TypeName##_private_offset = sizeof (TypeName##Private); \ |
||
260 | } |
||
261 | |||
262 | GLIB_AVAILABLE_IN_ALL |
||
263 | GType g_type_module_get_type (void) G_GNUC_CONST; |
||
264 | GLIB_AVAILABLE_IN_ALL |
||
265 | gboolean g_type_module_use (GTypeModule *module); |
||
266 | GLIB_AVAILABLE_IN_ALL |
||
267 | void g_type_module_unuse (GTypeModule *module); |
||
268 | GLIB_AVAILABLE_IN_ALL |
||
269 | void g_type_module_set_name (GTypeModule *module, |
||
270 | const gchar *name); |
||
271 | GLIB_AVAILABLE_IN_ALL |
||
272 | GType g_type_module_register_type (GTypeModule *module, |
||
273 | GType parent_type, |
||
274 | const gchar *type_name, |
||
275 | const GTypeInfo *type_info, |
||
276 | GTypeFlags flags); |
||
277 | GLIB_AVAILABLE_IN_ALL |
||
278 | void g_type_module_add_interface (GTypeModule *module, |
||
279 | GType instance_type, |
||
280 | GType interface_type, |
||
281 | const GInterfaceInfo *interface_info); |
||
282 | GLIB_AVAILABLE_IN_ALL |
||
283 | GType g_type_module_register_enum (GTypeModule *module, |
||
284 | const gchar *name, |
||
285 | const GEnumValue *const_static_values); |
||
286 | GLIB_AVAILABLE_IN_ALL |
||
287 | GType g_type_module_register_flags (GTypeModule *module, |
||
288 | const gchar *name, |
||
289 | const GFlagsValue *const_static_values); |
||
290 | |||
291 | G_END_DECLS |
||
292 | |||
293 | #endif /* __G_TYPE_MODULE_H__ */ |