remove trailing whitespace from newly added gtk-doc comments and
[platform/upstream/glib.git] / gobject / gtypeplugin.c
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
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.
18  */
19
20 #include "config.h"
21
22 #include "gtypeplugin.h"
23 #include "gobjectalias.h"
24
25
26 /**
27  * SECTION:gtypeplugin
28  *
29  * @Short_description: An interface for dynamically loadable types
30  *
31  * @See_also:#GTypeModule and g_type_register_dynamic().
32  *
33  * @Titile: GTypePlugin
34  *
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:
38  *
39  * <orderedlist>
40  * <listitem><para>
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:
44  *   |[
45  *   new_type_id = g_type_register_dynamic (parent_type_id,
46  *                                                 "TypeName",
47  *                                                 new_type_plugin,
48  *                                                 type_flags);
49  *   ]|
50  *   where <literal>new_type_plugin</literal> is an implementation of the
51  *   #GTypePlugin interface.
52  * </para></listitem>
53  * <listitem><para>
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>.
58  * </para></listitem>
59  * <listitem><para>
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>.
63  * </para></listitem>
64  * <listitem><para>
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).
68  * </para></listitem>
69  * <listitem><para>
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>.
73  * </para></listitem>
74  * <listitem><para>
75  *    Things may repeat from the second step.
76  * </para></listitem>
77  * </orderedlist>
78  *
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.
87  *
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.
91  */
92
93
94 /* --- functions --- */
95 GType
96 g_type_plugin_get_type (void)
97 {
98   static GType type_plugin_type = 0;
99   
100   if (!type_plugin_type)
101     {
102       static const GTypeInfo type_plugin_info = {
103         sizeof (GTypePluginClass),
104         NULL,           /* base_init */
105         NULL,           /* base_finalize */
106       };
107       
108       type_plugin_type = g_type_register_static (G_TYPE_INTERFACE, g_intern_static_string ("GTypePlugin"), &type_plugin_info, 0);
109     }
110   
111   return type_plugin_type;
112 }
113
114 /**
115  * g_type_plugin_use:
116  * @plugin: a #GTypePlugin
117  *
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.
121  */
122 void
123 g_type_plugin_use (GTypePlugin *plugin)
124 {
125   GTypePluginClass *iface;
126   
127   g_return_if_fail (G_IS_TYPE_PLUGIN (plugin));
128   
129   iface = G_TYPE_PLUGIN_GET_CLASS (plugin);
130   iface->use_plugin (plugin);
131 }
132
133 /**
134  * g_type_plugin_unuse:
135  * @plugin: a #GTypePlugin
136  *
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.
140  */
141 void
142 g_type_plugin_unuse (GTypePlugin *plugin)
143 {
144   GTypePluginClass *iface;
145   
146   g_return_if_fail (G_IS_TYPE_PLUGIN (plugin));
147   
148   iface = G_TYPE_PLUGIN_GET_CLASS (plugin);
149   iface->unuse_plugin (plugin);
150 }
151
152 /**
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
158  * 
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.
162  */
163 void
164 g_type_plugin_complete_type_info (GTypePlugin     *plugin,
165                                   GType            g_type,
166                                   GTypeInfo       *info,
167                                   GTypeValueTable *value_table)
168 {
169   GTypePluginClass *iface;
170   
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);
174   
175   iface = G_TYPE_PLUGIN_GET_CLASS (plugin);
176   iface->complete_type_info (plugin,
177                              g_type,
178                              info,
179                              value_table);
180 }
181
182 /**
183  * g_type_plugin_complete_interface_info:
184  * @plugin: the #GTypePlugin
185  * @instance_type: the #GType of an instantiable type to which the interface
186  *  is added
187  * @interface_type: the #GType of the interface whose info is completed
188  * @info: the #GInterfaceInfo to fill in
189  *
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.
193  */
194 void
195 g_type_plugin_complete_interface_info (GTypePlugin    *plugin,
196                                        GType           instance_type,
197                                        GType           interface_type,
198                                        GInterfaceInfo *info)
199 {
200   GTypePluginClass *iface;
201   
202   g_return_if_fail (G_IS_TYPE_PLUGIN (plugin));
203   g_return_if_fail (info != NULL);
204   
205   iface = G_TYPE_PLUGIN_GET_CLASS (plugin);
206   iface->complete_interface_info (plugin,
207                                   instance_type,
208                                   interface_type,
209                                   info);
210 }
211
212 #define __G_TYPE_PLUGIN_C__
213 #include "gobjectaliasdef.c"