Synopsis#include <glib-object.h> GTypeModule; GTypeModuleClass; gboolean g_type_module_use (GTypeModule *module); void g_type_module_unuse (GTypeModule *module); void g_type_module_set_name (GTypeModule *module, const gchar *name); GType g_type_module_register_type (GTypeModule *module, GType parent_type, const gchar *type_name, const GTypeInfo *type_info, GTypeFlags flags); void g_type_module_add_interface (GTypeModule *module, GType instance_type, GType interface_type, const GInterfaceInfo *interface_info); GType g_type_module_register_enum (GTypeModule *module, const gchar *name, const GEnumValue *const_static_values); GType g_type_module_register_flags (GTypeModule *module, const gchar *name, const GFlagsValue *const_static_values); #define G_DEFINE_DYNAMIC_TYPE (TN, t_n, T_P) #define G_DEFINE_DYNAMIC_TYPE_EXTENDED (TypeName, type_name, TYPE_PARENT, flags, CODE) Description
GTypeModule provides a simple implementation of the GTypePlugin
interface. The model of GTypeModule is a dynamically loaded module
which implements some number of types and interface
implementations. When the module is loaded, it registers its types
and interfaces using
Keeping track of whether the module should be loaded or not is done by
using a use count - it starts at zero, and whenever it is greater than
zero, the module is loaded. The use count is maintained internally by
the type system, but also can be explicitly controlled by
GTypeModule does not actually provide any implementation of module loading and unloading. To create a particular module type you must derive from GTypeModule and implement the load and unload functions in GTypeModuleClass.
DetailsGTypeModuletypedef struct { gchar *name; } GTypeModule;
The members of the GTypeModule structure should not
be accessed directly, except for the
GTypeModuleClasstypedef struct { GObjectClass parent_class; gboolean (* load) (GTypeModule *module); void (* unload) (GTypeModule *module); } GTypeModuleClass;
In order to implement dynamic loading of types based on GTypeModule,
the
g_type_module_use ()gboolean g_type_module_use (GTypeModule *module); Increases the use count of a GTypeModule by one. If the use count was zero before, the plugin will be loaded.
g_type_module_unuse ()void g_type_module_unuse (GTypeModule *module); Decreases the use count of a GTypeModule by one. If the result is zero, the module will be unloaded. (However, the GTypeModule will not be freed, and types associated with the GTypeModule are not unregistered. Once a GTypeModule is initialized, it must exist forever.)
g_type_module_set_name ()void g_type_module_set_name (GTypeModule *module, const gchar *name); Sets the name for a GTypeModule
g_type_module_register_type ()GType g_type_module_register_type (GTypeModule *module, GType parent_type, const gchar *type_name, const GTypeInfo *type_info, GTypeFlags flags);
Looks up or registers a type that is implemented with a particular
type plugin. If a type with name
When reregistering a type (typically because a module is unloaded
then reloaded, and reinitialized), As long as any instances of the type exist, the type plugin will not be unloaded.
g_type_module_add_interface ()void g_type_module_add_interface (GTypeModule *module, GType instance_type, GType interface_type, const GInterfaceInfo *interface_info); Registers an additional interface for a type, whose interface lives in the given type plugin. If the interface was already registered for the type in this plugin, nothing will be done. As long as any instances of the type exist, the type plugin will not be unloaded.
g_type_module_register_enum ()GType g_type_module_register_enum (GTypeModule *module, const gchar *name, const GEnumValue *const_static_values);
Looks up or registers an enumeration that is implemented with a particular
type plugin. If a type with name As long as any instances of the type exist, the type plugin will not be unloaded.
Since 2.6 g_type_module_register_flags ()GType g_type_module_register_flags (GTypeModule *module, const gchar *name, const GFlagsValue *const_static_values);
Looks up or registers a flags type that is implemented with a particular
type plugin. If a type with name As long as any instances of the type exist, the type plugin will not be unloaded.
Since 2.6 G_DEFINE_DYNAMIC_TYPE()#define G_DEFINE_DYNAMIC_TYPE(TN, t_n, T_P) G_DEFINE_DYNAMIC_TYPE_EXTENDED (TN, t_n, T_P, 0, {})
A convenience macro for dynamic type implementations, which declares a
class initialization function, an instance initialization function (see
GTypeInfo for information about these) and a static variable named
Since 2.14 G_DEFINE_DYNAMIC_TYPE_EXTENDED()#define G_DEFINE_DYNAMIC_TYPE_EXTENDED(TypeName, type_name, TYPE_PARENT, flags, CODE)
A more general version of
G_DEFINE_DYNAMIC_TYPE_EXTENDED (GtkGadget, gtk_gadget, GTK_TYPE_THING, 0, G_IMPLEMENT_INTERFACE (TYPE_GIZMO, gtk_gadget_gizmo_init)); expands to static void gtk_gadget_init (GtkGadget *self); static void gtk_gadget_class_init (GtkGadgetClass *klass); static void gtk_gadget_class_finalize (GtkGadgetClass *klass); static gpointer gtk_gadget_parent_class = NULL; static GType gtk_gadget_type_id = 0; static void gtk_gadget_class_intern_init (gpointer klass) { gtk_gadget_parent_class = g_type_class_peek_parent (klass); gtk_gadget_class_init ((GtkGadgetClass*) klass); } GType gtk_gadget_get_type (void) { return gtk_gadget_type_id; } static void gtk_gadget_register_type (GTypeModule *type_module) { const GTypeInfo g_define_type_info = { sizeof (GtkGadgetClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gtk_gadget_class_intern_init, (GClassFinalizeFunc) gtk_gadget_class_finalize, NULL, // class_data sizeof (GtkGadget), 0, // n_preallocs (GInstanceInitFunc) gtk_gadget_init, NULL // value_table }; gtk_gadget_type_id = g_type_module_register_type (type_module, GTK_TYPE_THING, GtkGadget, &g_define_type_info, (GTypeFlags) flags); { const GInterfaceInfo g_implement_interface_info = { (GInterfaceInitFunc) gtk_gadget_gizmo_init }; g_type_add_interface_static (g_define_type_id, TYPE_GIZMO, &g_implement_interface_info); } }
Since 2.14 |