1 /* GObject - GLib Type, Object, Parameter and Signal Library
2 * Copyright (C) 2000 Red Hat, Inc.
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.
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.
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.
22 #include "gtypeplugin.h"
23 #include "gobjectalias.h"
29 * @Short_description: An interface for dynamically loadable types
31 * @See_also:#GTypeModule and g_type_register_dynamic().
33 * @Titile: GTypePlugin
35 * The GObject type system supports dynamic loading of types. The
36 * #GTypePlugin interface is used to handle the lifecycle of
37 * dynamically loaded types. It goes as follows:
41 * The type is initially introduced (usually upon loading the module
42 * the first time, or by your main application that knows what modules
43 * introduces what types), like this:
45 * new_type_id = g_type_register_dynamic (parent_type_id,
50 * where <literal>new_type_plugin</literal> is an implementation of the
51 * #GTypePlugin interface.
54 * The type's implementation is referenced, e.g. through
55 * g_type_class_ref() or through g_type_create_instance() (this is
56 * being called by g_object_new()) or through one of the above done on
57 * a type derived from <literal>new_type_id</literal>.
60 * This causes the type system to load the type's implementation by calling
61 * g_type_plugin_use() and g_type_plugin_complete_type_info() on
62 * <literal>new_type_plugin</literal>.
65 * At some point the type's implementation isn't required anymore, e.g. after
66 * g_type_class_unref() or g_type_free_instance() (called when the reference
67 * count of an instance drops to zero).
70 * This causes the type system to throw away the information retrieved from
71 * g_type_plugin_complete_type_info() and then it calls
72 * g_type_plugin_unuse() on <literal>new_type_plugin</literal>.
75 * Things may repeat from the second step.
79 * So basically, you need to implement a #GTypePlugin type that
80 * carries a use_count, once use_count goes from zero to one, you need
81 * to load the implementation to successfully handle the upcoming
82 * g_type_plugin_complete_type_info() call. Later, maybe after
83 * succeeding use/unuse calls, once use_count drops to zero, you can
84 * unload the implementation again. The type system makes sure to call
85 * g_type_plugin_use() and g_type_plugin_complete_type_info() again
86 * when the type is needed again.
88 * #GTypeModule is an implementation of #GTypePlugin that already
89 * implements most of this except for the actual module loading and
90 * unloading. It even handles multiple registered types per module.
94 /* --- functions --- */
96 g_type_plugin_get_type (void)
98 static GType type_plugin_type = 0;
100 if (!type_plugin_type)
102 static const GTypeInfo type_plugin_info = {
103 sizeof (GTypePluginClass),
104 NULL, /* base_init */
105 NULL, /* base_finalize */
108 type_plugin_type = g_type_register_static (G_TYPE_INTERFACE, g_intern_static_string ("GTypePlugin"), &type_plugin_info, 0);
111 return type_plugin_type;
116 * @plugin: a #GTypePlugin
118 * Calls the @use_plugin function from the #GTypePluginClass of
119 * @plugin. There should be no need to use this function outside of
120 * the GObject type system itself.
123 g_type_plugin_use (GTypePlugin *plugin)
125 GTypePluginClass *iface;
127 g_return_if_fail (G_IS_TYPE_PLUGIN (plugin));
129 iface = G_TYPE_PLUGIN_GET_CLASS (plugin);
130 iface->use_plugin (plugin);
134 * g_type_plugin_unuse:
135 * @plugin: a #GTypePlugin
137 * Calls the @unuse_plugin function from the #GTypePluginClass of
138 * @plugin. There should be no need to use this function outside of
139 * the GObject type system itself.
142 g_type_plugin_unuse (GTypePlugin *plugin)
144 GTypePluginClass *iface;
146 g_return_if_fail (G_IS_TYPE_PLUGIN (plugin));
148 iface = G_TYPE_PLUGIN_GET_CLASS (plugin);
149 iface->unuse_plugin (plugin);
153 * g_type_plugin_complete_type_info:
154 * @plugin: a #GTypePlugin
155 * @g_type: the #GType whose info is completed
156 * @info: the #GTypeInfo struct to fill in
157 * @value_table: the #GTypeValueTable to fill in
159 * Calls the @complete_type_info function from the #GTypePluginClass of @plugin.
160 * There should be no need to use this function outside of the GObject
161 * type system itself.
164 g_type_plugin_complete_type_info (GTypePlugin *plugin,
167 GTypeValueTable *value_table)
169 GTypePluginClass *iface;
171 g_return_if_fail (G_IS_TYPE_PLUGIN (plugin));
172 g_return_if_fail (info != NULL);
173 g_return_if_fail (value_table != NULL);
175 iface = G_TYPE_PLUGIN_GET_CLASS (plugin);
176 iface->complete_type_info (plugin,
183 * g_type_plugin_complete_interface_info:
184 * @plugin: the #GTypePlugin
185 * @instance_type: the #GType of an instantiable type to which the interface
187 * @interface_type: the #GType of the interface whose info is completed
188 * @info: the #GInterfaceInfo to fill in
190 * Calls the @complete_interface_info function from the
191 * #GTypePluginClass of @plugin. There should be no need to use this
192 * function outside of the GObject type system itself.
195 g_type_plugin_complete_interface_info (GTypePlugin *plugin,
197 GType interface_type,
198 GInterfaceInfo *info)
200 GTypePluginClass *iface;
202 g_return_if_fail (G_IS_TYPE_PLUGIN (plugin));
203 g_return_if_fail (info != NULL);
205 iface = G_TYPE_PLUGIN_GET_CLASS (plugin);
206 iface->complete_interface_info (plugin,
212 #define __G_TYPE_PLUGIN_C__
213 #include "gobjectaliasdef.c"