~ubuntu-branches/debian/squeeze/glib2.0/squeeze

« back to all changes in this revision

Viewing changes to gobject/gtypemodule.c

  • Committer: Bazaar Package Importer
  • Author(s): Gustavo Noronha Silva
  • Date: 2009-02-15 13:00:43 UTC
  • mfrom: (1.3.1 upstream) (69.1.10 intrepid)
  • Revision ID: james.westby@ubuntu.com-20090215130043-q47fbt3owmt42m2f
Tags: 2.18.4-2
* Release to unstable
* debian/rules:
- bump SHVER, since we are already forcing a 2.18.0 dependecy on the
  symbols introduced in the development versions
* debian/control.in:
- added Homepage and Vcs-* control fields

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 * Boston, MA 02111-1307, USA.
18
18
 */
19
19
 
 
20
#include "config.h"
 
21
 
20
22
#include <stdlib.h>
21
23
 
22
24
#include "gtypeplugin.h"
23
25
#include "gtypemodule.h"
24
26
#include "gobjectalias.h"
25
27
 
 
28
 
 
29
/**
 
30
 * SECTION:gtypemodule
 
31
 * @short_description: Type loading modules
 
32
 * @see_also:<variablelist>
 
33
 * <varlistentry>
 
34
 * <term>#GTypePlugin</term>
 
35
 * <listitem><para>The abstract type loader interface.</para></listitem>
 
36
 * </varlistentry>
 
37
 * <varlistentry>
 
38
 * <term>#GModule</term>
 
39
 * <listitem><para>Portable mechanism for dynamically loaded modules.</para></listitem>
 
40
 * </varlistentry>
 
41
 * </variablelist>
 
42
 * @title: GTypeModule
 
43
 *
 
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.
 
56
 *
 
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.
 
66
 *
 
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.
 
71
 */
 
72
 
 
73
 
26
74
typedef struct _ModuleTypeInfo ModuleTypeInfo;
27
75
typedef struct _ModuleInterfaceInfo ModuleInterfaceInfo;
28
76
 
131
179
  return type_module_type;
132
180
}
133
181
 
 
182
/**
 
183
 * g_type_module_set_name:
 
184
 * @module: a #GTypeModule.
 
185
 * @name: a human-readable name to use in error messages.
 
186
 * 
 
187
 * Sets the name for a #GTypeModule 
 
188
 */
134
189
void
135
190
g_type_module_set_name (GTypeModule  *module,
136
191
                        const gchar  *name)
177
232
  return NULL;
178
233
}
179
234
 
 
235
/**
 
236
 * g_type_module_use:
 
237
 * @module: a #GTypeModule
 
238
 * 
 
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 
 
242
 * its prior value. 
 
243
 * 
 
244
 * Returns: %FALSE if the plugin needed to be loaded and
 
245
 *  loading the plugin failed.
 
246
 */
180
247
gboolean
181
248
g_type_module_use (GTypeModule *module)
182
249
{
202
269
              g_warning ("plugin '%s' failed to register type '%s'\n",
203
270
                         module->name ? module->name : "(unknown)",
204
271
                         g_type_name (type_info->type));
 
272
              module->use_count--;
205
273
              return FALSE;
206
274
            }
207
275
          
212
280
  return TRUE;
213
281
}
214
282
 
 
283
/**
 
284
 * g_type_module_unuse:
 
285
 * @module: a #GTypeModule
 
286
 *
 
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.)
 
292
 */
215
293
void
216
294
g_type_module_unuse (GTypeModule *module)
217
295
{
277
355
  *info = module_interface_info->info;
278
356
}
279
357
 
 
358
/**
 
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
 
365
 *
 
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.
 
370
 *
 
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.
 
374
 *
 
375
 * As long as any instances of the type exist, the type plugin will
 
376
 * not be unloaded.
 
377
 *
 
378
 * Returns: the new or existing type ID
 
379
 */
280
380
GType
281
381
g_type_module_register_type (GTypeModule     *module,
282
382
                             GType            parent_type,
340
440
  return module_type_info->type;
341
441
}
342
442
 
 
443
/**
 
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
 
449
 *
 
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.
 
453
 *
 
454
 * As long as any instances of the type exist, the type plugin will
 
455
 * not be unloaded.
 
456
 */
343
457
void
344
458
g_type_module_add_interface (GTypeModule          *module,
345
459
                             GType                 instance_type,
389
503
  module_interface_info->info = *interface_info;
390
504
}
391
505
 
 
506
/**
 
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
 
513
 *                       0.
 
514
 *
 
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.
 
519
 *
 
520
 * As long as any instances of the type exist, the type plugin will
 
521
 * not be unloaded.
 
522
 *
 
523
 * Since: 2.6
 
524
 *
 
525
 * Returns: the new or existing type ID
 
526
 */
392
527
GType
393
528
g_type_module_register_enum (GTypeModule      *module,
394
529
                             const gchar      *name,
407
542
                                      G_TYPE_ENUM, name, &enum_type_info, 0);
408
543
}
409
544
 
 
545
/**
 
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
 
552
 *                       0.
 
553
 *
 
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.
 
558
 *
 
559
 * As long as any instances of the type exist, the type plugin will
 
560
 * not be unloaded.
 
561
 *
 
562
 * Since: 2.6
 
563
 *
 
564
 * Returns: the new or existing type ID
 
565
 */
410
566
GType
411
567
g_type_module_register_flags (GTypeModule      *module,
412
568
                             const gchar       *name,