1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
2 * GObject introspection: Registered Type implementation
4 * Copyright (C) 2005 Matthias Clasen
5 * Copyright (C) 2008,2009 Red Hat, Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
27 #include <girepository.h>
28 #include "girepository-private.h"
29 #include "gitypelib-internal.h"
32 * SECTION:giregisteredtypeinfo
33 * @Short_description: Struct representing a struct with a GType
34 * @Title: GIRegisteredTypeInfo
36 * GIRegisteredTypeInfo represents an entity with a GType associated. Could
37 * be either a #GIEnumInfo, #GIInterfaceInfo, #GIObjectInfo, #GIStructInfo or a
40 * A registered type info struct has a name and a type function.
41 * To get the name call g_registered_type_info_get_type_name().
42 * Most users want to call g_registered_type_info_get_g_type() and don't worry
43 * about the rest of the details.
45 * <refsect1 id="gi-giregisteredtypeinfo.struct-hierarchy" role="struct_hierarchy">
46 * <title role="struct_hierarchy.title">Struct hierarchy</title>
48 * <link linkend="gi-GIBaseInfo">GIBaseInfo</link>
49 * +----GIRegisteredTypeInfo
50 * +----<link linkend="gi-GIEnumInfo">GIEnumInfo</link>
51 * +----<link linkend="gi-GIInterfaceInfo">GIInterfaceInfo</link>
52 * +----<link linkend="gi-GIObjectInfo">GIObjectInfo</link>
53 * +----<link linkend="gi-GIStructInfo">GIStructInfo</link>
54 * +----<link linkend="gi-GIUnionInfo">GIUnionInfo</link>
60 * g_registered_type_info_get_type_name:
61 * @info: a #GIRegisteredTypeInfo
63 * Obtain the type name of the struct within the GObject type system.
64 * This type can be passed to g_type_name() to get a #GType.
66 * Returns: the type name
69 g_registered_type_info_get_type_name (GIRegisteredTypeInfo *info)
71 GIRealInfo *rinfo = (GIRealInfo *)info;
72 RegisteredTypeBlob *blob;
74 g_return_val_if_fail (info != NULL, NULL);
75 g_return_val_if_fail (GI_IS_REGISTERED_TYPE_INFO (info), NULL);
77 blob = (RegisteredTypeBlob *)&rinfo->typelib->data[rinfo->offset];
80 return g_typelib_get_string (rinfo->typelib, blob->gtype_name);
86 * g_registered_type_info_get_type_init:
87 * @info: a #GIRegisteredTypeInfo
89 * Obtain the type init function for @info. The type init function is the
90 * function which will register the GType within the GObject type system.
91 * Usually this is not called by langauge bindings or applications, use
92 * g_registered_type_info_get_g_type() directly instead.
94 * Returns: the symbol name of the type init function, suitable for
95 * passing into g_module_symbol().
98 g_registered_type_info_get_type_init (GIRegisteredTypeInfo *info)
100 GIRealInfo *rinfo = (GIRealInfo *)info;
101 RegisteredTypeBlob *blob;
103 g_return_val_if_fail (info != NULL, NULL);
104 g_return_val_if_fail (GI_IS_REGISTERED_TYPE_INFO (info), NULL);
106 blob = (RegisteredTypeBlob *)&rinfo->typelib->data[rinfo->offset];
108 if (blob->gtype_init)
109 return g_typelib_get_string (rinfo->typelib, blob->gtype_init);
115 * g_registered_type_info_get_g_type:
116 * @info: a #GIRegisteredTypeInfo
118 * Obtain the #GType for this registered type or G_TYPE_NONE which a special meaning.
119 * It means that either there is no type information associated with this @info or
120 * that the shared library which provides the type_init function for this
121 * @info cannot be called.
123 * Returns: the #GType.
126 g_registered_type_info_get_g_type (GIRegisteredTypeInfo *info)
128 const char *type_init;
129 GType (* get_type_func) (void);
130 GIRealInfo *rinfo = (GIRealInfo*)info;
132 g_return_val_if_fail (info != NULL, G_TYPE_INVALID);
133 g_return_val_if_fail (GI_IS_REGISTERED_TYPE_INFO (info), G_TYPE_INVALID);
135 type_init = g_registered_type_info_get_type_init (info);
137 if (type_init == NULL)
139 else if (!strcmp (type_init, "intern"))
140 /* The special string "intern" is used for some types exposed by libgobject
141 (that therefore should be always available) */
142 return g_type_from_name (g_registered_type_info_get_type_name (info));
144 get_type_func = NULL;
145 if (!g_typelib_symbol (rinfo->typelib,
147 (void**) &get_type_func))
150 return (* get_type_func) ();