Add g_key_file_save_to_file()
[glib.git] / gobject / gtypeplugin.c
blob192f6f9901cc162338c592a3f422e5be2489c8a0
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.
20 #include "config.h"
22 #include "gtypeplugin.h"
25 /**
26 * SECTION:gtypeplugin
27 * @short_description: An interface for dynamically loadable types
28 * @see_also: #GTypeModule and g_type_register_dynamic().
29 * @title: GTypePlugin
31 * The GObject type system supports dynamic loading of types. The
32 * #GTypePlugin interface is used to handle the lifecycle of
33 * dynamically loaded types. It goes as follows:
35 * <orderedlist>
36 * <listitem><para>
37 * The type is initially introduced (usually upon loading the module
38 * the first time, or by your main application that knows what modules
39 * introduces what types), like this:
40 * |[
41 * new_type_id = g_type_register_dynamic (parent_type_id,
42 * "TypeName",
43 * new_type_plugin,
44 * type_flags);
45 * ]|
46 * where <literal>new_type_plugin</literal> is an implementation of the
47 * #GTypePlugin interface.
48 * </para></listitem>
49 * <listitem><para>
50 * The type's implementation is referenced, e.g. through
51 * g_type_class_ref() or through g_type_create_instance() (this is
52 * being called by g_object_new()) or through one of the above done on
53 * a type derived from <literal>new_type_id</literal>.
54 * </para></listitem>
55 * <listitem><para>
56 * This causes the type system to load the type's implementation by calling
57 * g_type_plugin_use() and g_type_plugin_complete_type_info() on
58 * <literal>new_type_plugin</literal>.
59 * </para></listitem>
60 * <listitem><para>
61 * At some point the type's implementation isn't required anymore, e.g. after
62 * g_type_class_unref() or g_type_free_instance() (called when the reference
63 * count of an instance drops to zero).
64 * </para></listitem>
65 * <listitem><para>
66 * This causes the type system to throw away the information retrieved from
67 * g_type_plugin_complete_type_info() and then it calls
68 * g_type_plugin_unuse() on <literal>new_type_plugin</literal>.
69 * </para></listitem>
70 * <listitem><para>
71 * Things may repeat from the second step.
72 * </para></listitem>
73 * </orderedlist>
75 * So basically, you need to implement a #GTypePlugin type that
76 * carries a use_count, once use_count goes from zero to one, you need
77 * to load the implementation to successfully handle the upcoming
78 * g_type_plugin_complete_type_info() call. Later, maybe after
79 * succeeding use/unuse calls, once use_count drops to zero, you can
80 * unload the implementation again. The type system makes sure to call
81 * g_type_plugin_use() and g_type_plugin_complete_type_info() again
82 * when the type is needed again.
84 * #GTypeModule is an implementation of #GTypePlugin that already
85 * implements most of this except for the actual module loading and
86 * unloading. It even handles multiple registered types per module.
90 /* --- functions --- */
91 GType
92 g_type_plugin_get_type (void)
94 static GType type_plugin_type = 0;
96 if (!type_plugin_type)
98 const GTypeInfo type_plugin_info = {
99 sizeof (GTypePluginClass),
100 NULL, /* base_init */
101 NULL, /* base_finalize */
104 type_plugin_type = g_type_register_static (G_TYPE_INTERFACE, g_intern_static_string ("GTypePlugin"), &type_plugin_info, 0);
107 return type_plugin_type;
111 * g_type_plugin_use:
112 * @plugin: a #GTypePlugin
114 * Calls the @use_plugin function from the #GTypePluginClass of
115 * @plugin. There should be no need to use this function outside of
116 * the GObject type system itself.
118 void
119 g_type_plugin_use (GTypePlugin *plugin)
121 GTypePluginClass *iface;
123 g_return_if_fail (G_IS_TYPE_PLUGIN (plugin));
125 iface = G_TYPE_PLUGIN_GET_CLASS (plugin);
126 iface->use_plugin (plugin);
130 * g_type_plugin_unuse:
131 * @plugin: a #GTypePlugin
133 * Calls the @unuse_plugin function from the #GTypePluginClass of
134 * @plugin. There should be no need to use this function outside of
135 * the GObject type system itself.
137 void
138 g_type_plugin_unuse (GTypePlugin *plugin)
140 GTypePluginClass *iface;
142 g_return_if_fail (G_IS_TYPE_PLUGIN (plugin));
144 iface = G_TYPE_PLUGIN_GET_CLASS (plugin);
145 iface->unuse_plugin (plugin);
149 * g_type_plugin_complete_type_info:
150 * @plugin: a #GTypePlugin
151 * @g_type: the #GType whose info is completed
152 * @info: the #GTypeInfo struct to fill in
153 * @value_table: the #GTypeValueTable to fill in
155 * Calls the @complete_type_info function from the #GTypePluginClass of @plugin.
156 * There should be no need to use this function outside of the GObject
157 * type system itself.
159 void
160 g_type_plugin_complete_type_info (GTypePlugin *plugin,
161 GType g_type,
162 GTypeInfo *info,
163 GTypeValueTable *value_table)
165 GTypePluginClass *iface;
167 g_return_if_fail (G_IS_TYPE_PLUGIN (plugin));
168 g_return_if_fail (info != NULL);
169 g_return_if_fail (value_table != NULL);
171 iface = G_TYPE_PLUGIN_GET_CLASS (plugin);
172 iface->complete_type_info (plugin,
173 g_type,
174 info,
175 value_table);
179 * g_type_plugin_complete_interface_info:
180 * @plugin: the #GTypePlugin
181 * @instance_type: the #GType of an instantiable type to which the interface
182 * is added
183 * @interface_type: the #GType of the interface whose info is completed
184 * @info: the #GInterfaceInfo to fill in
186 * Calls the @complete_interface_info function from the
187 * #GTypePluginClass of @plugin. There should be no need to use this
188 * function outside of the GObject type system itself.
190 void
191 g_type_plugin_complete_interface_info (GTypePlugin *plugin,
192 GType instance_type,
193 GType interface_type,
194 GInterfaceInfo *info)
196 GTypePluginClass *iface;
198 g_return_if_fail (G_IS_TYPE_PLUGIN (plugin));
199 g_return_if_fail (info != NULL);
201 iface = G_TYPE_PLUGIN_GET_CLASS (plugin);
202 iface->complete_interface_info (plugin,
203 instance_type,
204 interface_type,
205 info);