17
17
* Boston, MA 02111-1307, USA.
20
22
#include <stdlib.h>
22
24
#include "gtypeplugin.h"
23
25
#include "gtypemodule.h"
24
26
#include "gobjectalias.h"
31
* @short_description: Type loading modules
32
* @see_also:<variablelist>
34
* <term>#GTypePlugin</term>
35
* <listitem><para>The abstract type loader interface.</para></listitem>
38
* <term>#GModule</term>
39
* <listitem><para>Portable mechanism for dynamically loaded modules.</para></listitem>
44
* #GTypeModule provides a simple implementation of the #GTypePlugin
45
* interface. The model of #GTypeModule is a dynamically loaded module
46
* which implements some number of types and interface
47
* implementations. When the module is loaded, it registers its types
48
* and interfaces using g_type_module_register_type() and
49
* g_type_module_add_interface(). As long as any instances of these
50
* types and interface implementations are in use, the module is kept
51
* loaded. When the types and interfaces are gone, the module may be
52
* unloaded. If the types and interfaces become used again, the module
53
* will be reloaded. Note that the last unref can not happen in module
54
* code, since that would lead to the caller's code being unloaded before
55
* g_object_unref() returns to it.
57
* Keeping track of whether the module should be loaded or not is done by
58
* using a use count - it starts at zero, and whenever it is greater than
59
* zero, the module is loaded. The use count is maintained internally by
60
* the type system, but also can be explicitly controlled by
61
* g_type_module_use() and g_type_module_unuse(). Typically, when loading
62
* a module for the first type, g_type_module_use() will be used to load
63
* it so that it can initialize its types. At some later point, when the
64
* module no longer needs to be loaded except for the type
65
* implementations it contains, g_type_module_unuse() is called.
67
* #GTypeModule does not actually provide any implementation of module
68
* loading and unloading. To create a particular module type you must
69
* derive from #GTypeModule and implement the load and unload functions
70
* in #GTypeModuleClass.
26
74
typedef struct _ModuleTypeInfo ModuleTypeInfo;
27
75
typedef struct _ModuleInterfaceInfo ModuleInterfaceInfo;
131
179
return type_module_type;
183
* g_type_module_set_name:
184
* @module: a #GTypeModule.
185
* @name: a human-readable name to use in error messages.
187
* Sets the name for a #GTypeModule
135
190
g_type_module_set_name (GTypeModule *module,
136
191
const gchar *name)
237
* @module: a #GTypeModule
239
* Increases the use count of a #GTypeModule by one. If the
240
* use count was zero before, the plugin will be loaded.
241
* If loading the plugin fails, the use count is reset to
244
* Returns: %FALSE if the plugin needed to be loaded and
245
* loading the plugin failed.
181
248
g_type_module_use (GTypeModule *module)
284
* g_type_module_unuse:
285
* @module: a #GTypeModule
287
* Decreases the use count of a #GTypeModule by one. If the
288
* result is zero, the module will be unloaded. (However, the
289
* #GTypeModule will not be freed, and types associated with the
290
* #GTypeModule are not unregistered. Once a #GTypeModule is
291
* initialized, it must exist forever.)
216
294
g_type_module_unuse (GTypeModule *module)
277
355
*info = module_interface_info->info;
359
* g_type_module_register_type:
360
* @module: a #GTypeModule
361
* @parent_type: the type for the parent class
362
* @type_name: name for the type
363
* @type_info: type information structure
364
* @flags: flags field providing details about the type
366
* Looks up or registers a type that is implemented with a particular
367
* type plugin. If a type with name @type_name was previously registered,
368
* the #GType identifier for the type is returned, otherwise the type
369
* is newly registered, and the resulting #GType identifier returned.
371
* When reregistering a type (typically because a module is unloaded
372
* then reloaded, and reinitialized), @module and @parent_type must
373
* be the same as they were previously.
375
* As long as any instances of the type exist, the type plugin will
378
* Returns: the new or existing type ID
281
381
g_type_module_register_type (GTypeModule *module,
282
382
GType parent_type,
340
440
return module_type_info->type;
444
* g_type_module_add_interface:
445
* @module: a #GTypeModule
446
* @instance_type: type to which to add the interface.
447
* @interface_type: interface type to add
448
* @interface_info: type information structure
450
* Registers an additional interface for a type, whose interface lives
451
* in the given type plugin. If the interface was already registered
452
* for the type in this plugin, nothing will be done.
454
* As long as any instances of the type exist, the type plugin will
344
458
g_type_module_add_interface (GTypeModule *module,
345
459
GType instance_type,
389
503
module_interface_info->info = *interface_info;
507
* g_type_module_register_enum:
508
* @module: a #GTypeModule
509
* @name: name for the type
510
* @const_static_values: an array of #GEnumValue structs for the
511
* possible enumeration values. The array is
512
* terminated by a struct with all members being
515
* Looks up or registers an enumeration that is implemented with a particular
516
* type plugin. If a type with name @type_name was previously registered,
517
* the #GType identifier for the type is returned, otherwise the type
518
* is newly registered, and the resulting #GType identifier returned.
520
* As long as any instances of the type exist, the type plugin will
525
* Returns: the new or existing type ID
393
528
g_type_module_register_enum (GTypeModule *module,
394
529
const gchar *name,
407
542
G_TYPE_ENUM, name, &enum_type_info, 0);
546
* g_type_module_register_flags:
547
* @module: a #GTypeModule
548
* @name: name for the type
549
* @const_static_values: an array of #GFlagsValue structs for the
550
* possible flags values. The array is
551
* terminated by a struct with all members being
554
* Looks up or registers a flags type that is implemented with a particular
555
* type plugin. If a type with name @type_name was previously registered,
556
* the #GType identifier for the type is returned, otherwise the type
557
* is newly registered, and the resulting #GType identifier returned.
559
* As long as any instances of the type exist, the type plugin will
564
* Returns: the new or existing type ID
411
567
g_type_module_register_flags (GTypeModule *module,
412
568
const gchar *name,