2012-02-03 19:42:56 +01:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
|
|
|
|
* GObject introspection: Registered Type implementation
|
2010-06-07 00:28:35 +02:00
|
|
|
*
|
|
|
|
* Copyright (C) 2005 Matthias Clasen
|
|
|
|
* Copyright (C) 2008,2009 Red Hat, Inc.
|
|
|
|
*
|
2023-10-25 18:10:10 +02:00
|
|
|
* SPDX-License-Identifier: LGPL-2.1-or-later
|
|
|
|
*
|
2010-06-07 00:28:35 +02:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2014-07-04 12:27:41 +02:00
|
|
|
#include "config.h"
|
|
|
|
|
2010-06-07 00:52:12 +02:00
|
|
|
#include <string.h>
|
|
|
|
|
2010-06-07 00:28:35 +02:00
|
|
|
#include <glib.h>
|
|
|
|
|
2023-10-25 18:45:42 +02:00
|
|
|
#include <girepository/girepository.h>
|
2010-06-07 00:28:35 +02:00
|
|
|
#include "girepository-private.h"
|
|
|
|
#include "gitypelib-internal.h"
|
2023-10-25 19:11:38 +02:00
|
|
|
#include "giregisteredtypeinfo.h"
|
2010-06-07 00:28:35 +02:00
|
|
|
|
2010-06-07 04:04:15 +02:00
|
|
|
/**
|
|
|
|
* SECTION:giregisteredtypeinfo
|
2013-10-10 22:21:18 +02:00
|
|
|
* @title: GIRegisteredTypeInfo
|
|
|
|
* @short_description: Struct representing a struct with a GType
|
2010-06-07 04:04:15 +02:00
|
|
|
*
|
2022-02-13 15:20:51 +01:00
|
|
|
* GIRegisteredTypeInfo represents an entity with a GType associated.
|
|
|
|
*
|
|
|
|
* Could be either a #GIEnumInfo, #GIInterfaceInfo, #GIObjectInfo,
|
|
|
|
* #GIStructInfo or a #GIUnionInfo.
|
2010-06-07 04:04:15 +02:00
|
|
|
*
|
|
|
|
* A registered type info struct has a name and a type function.
|
2022-02-13 15:20:51 +01:00
|
|
|
*
|
2023-11-08 15:17:52 +01:00
|
|
|
* To get the name call gi_registered_type_info_get_type_name().
|
|
|
|
* Most users want to call gi_registered_type_info_get_g_type() and don't worry
|
2010-06-07 04:04:15 +02:00
|
|
|
* about the rest of the details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2023-11-08 15:17:52 +01:00
|
|
|
* gi_registered_type_info_get_type_name:
|
2010-06-07 04:04:15 +02:00
|
|
|
* @info: a #GIRegisteredTypeInfo
|
|
|
|
*
|
|
|
|
* Obtain the type name of the struct within the GObject type system.
|
|
|
|
* This type can be passed to g_type_name() to get a #GType.
|
|
|
|
*
|
|
|
|
* Returns: the type name
|
|
|
|
*/
|
2010-06-07 00:28:35 +02:00
|
|
|
const gchar *
|
2023-11-08 15:17:52 +01:00
|
|
|
gi_registered_type_info_get_type_name (GIRegisteredTypeInfo *info)
|
2010-06-07 00:28:35 +02:00
|
|
|
{
|
|
|
|
GIRealInfo *rinfo = (GIRealInfo *)info;
|
2010-06-07 04:04:15 +02:00
|
|
|
RegisteredTypeBlob *blob;
|
|
|
|
|
|
|
|
g_return_val_if_fail (info != NULL, NULL);
|
|
|
|
g_return_val_if_fail (GI_IS_REGISTERED_TYPE_INFO (info), NULL);
|
|
|
|
|
|
|
|
blob = (RegisteredTypeBlob *)&rinfo->typelib->data[rinfo->offset];
|
2010-06-07 00:28:35 +02:00
|
|
|
|
|
|
|
if (blob->gtype_name)
|
2023-11-08 15:17:52 +01:00
|
|
|
return gi_typelib_get_string (rinfo->typelib, blob->gtype_name);
|
2010-06-07 00:28:35 +02:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-06-07 04:04:15 +02:00
|
|
|
/**
|
2023-11-08 15:17:52 +01:00
|
|
|
* gi_registered_type_info_get_type_init:
|
2010-06-07 04:04:15 +02:00
|
|
|
* @info: a #GIRegisteredTypeInfo
|
|
|
|
*
|
|
|
|
* Obtain the type init function for @info. The type init function is the
|
|
|
|
* function which will register the GType within the GObject type system.
|
|
|
|
* Usually this is not called by langauge bindings or applications, use
|
2023-11-08 15:17:52 +01:00
|
|
|
* gi_registered_type_info_get_g_type() directly instead.
|
2010-06-07 04:04:15 +02:00
|
|
|
*
|
|
|
|
* Returns: the symbol name of the type init function, suitable for
|
|
|
|
* passing into g_module_symbol().
|
|
|
|
*/
|
2010-06-07 00:28:35 +02:00
|
|
|
const gchar *
|
2023-11-08 15:17:52 +01:00
|
|
|
gi_registered_type_info_get_type_init (GIRegisteredTypeInfo *info)
|
2010-06-07 00:28:35 +02:00
|
|
|
{
|
|
|
|
GIRealInfo *rinfo = (GIRealInfo *)info;
|
2010-06-07 04:04:15 +02:00
|
|
|
RegisteredTypeBlob *blob;
|
|
|
|
|
|
|
|
g_return_val_if_fail (info != NULL, NULL);
|
|
|
|
g_return_val_if_fail (GI_IS_REGISTERED_TYPE_INFO (info), NULL);
|
|
|
|
|
|
|
|
blob = (RegisteredTypeBlob *)&rinfo->typelib->data[rinfo->offset];
|
2010-06-07 00:28:35 +02:00
|
|
|
|
|
|
|
if (blob->gtype_init)
|
2023-11-08 15:17:52 +01:00
|
|
|
return gi_typelib_get_string (rinfo->typelib, blob->gtype_init);
|
2010-06-07 00:28:35 +02:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-06-07 04:04:15 +02:00
|
|
|
/**
|
2023-11-08 15:17:52 +01:00
|
|
|
* gi_registered_type_info_get_g_type:
|
2010-06-07 04:04:15 +02:00
|
|
|
* @info: a #GIRegisteredTypeInfo
|
|
|
|
*
|
2010-10-06 17:51:44 +02:00
|
|
|
* Obtain the #GType for this registered type or G_TYPE_NONE which a special meaning.
|
|
|
|
* It means that either there is no type information associated with this @info or
|
|
|
|
* that the shared library which provides the type_init function for this
|
|
|
|
* @info cannot be called.
|
2010-06-07 04:04:15 +02:00
|
|
|
*
|
|
|
|
* Returns: the #GType.
|
|
|
|
*/
|
2010-06-07 00:28:35 +02:00
|
|
|
GType
|
2023-11-08 15:17:52 +01:00
|
|
|
gi_registered_type_info_get_g_type (GIRegisteredTypeInfo *info)
|
2010-06-07 00:28:35 +02:00
|
|
|
{
|
|
|
|
const char *type_init;
|
|
|
|
GType (* get_type_func) (void);
|
|
|
|
GIRealInfo *rinfo = (GIRealInfo*)info;
|
|
|
|
|
2010-06-07 04:04:15 +02:00
|
|
|
g_return_val_if_fail (info != NULL, G_TYPE_INVALID);
|
|
|
|
g_return_val_if_fail (GI_IS_REGISTERED_TYPE_INFO (info), G_TYPE_INVALID);
|
|
|
|
|
2023-11-08 15:17:52 +01:00
|
|
|
type_init = gi_registered_type_info_get_type_init (info);
|
2010-06-07 00:28:35 +02:00
|
|
|
|
|
|
|
if (type_init == NULL)
|
|
|
|
return G_TYPE_NONE;
|
|
|
|
else if (!strcmp (type_init, "intern"))
|
2011-05-25 19:26:49 +02:00
|
|
|
/* The special string "intern" is used for some types exposed by libgobject
|
|
|
|
(that therefore should be always available) */
|
2023-11-08 15:17:52 +01:00
|
|
|
return g_type_from_name (gi_registered_type_info_get_type_name (info));
|
2010-06-07 00:28:35 +02:00
|
|
|
|
|
|
|
get_type_func = NULL;
|
2023-11-08 15:17:52 +01:00
|
|
|
if (!gi_typelib_symbol (rinfo->typelib,
|
|
|
|
type_init,
|
|
|
|
(void**) &get_type_func))
|
2010-06-07 00:28:35 +02:00
|
|
|
return G_TYPE_NONE;
|
|
|
|
|
|
|
|
return (* get_type_func) ();
|
|
|
|
}
|
|
|
|
|