mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-10 11:26:16 +01:00
333 lines
10 KiB
C
333 lines
10 KiB
C
/* GObject introspection: Object implementation
|
|
*
|
|
* Copyright (C) 2005 Matthias Clasen
|
|
* Copyright (C) 2008,2009 Red Hat, Inc.
|
|
*
|
|
* 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.
|
|
*/
|
|
|
|
#include <glib.h>
|
|
|
|
#include <girepository.h>
|
|
#include "girepository-private.h"
|
|
#include "gitypelib-internal.h"
|
|
|
|
/* GIObjectInfo functions */
|
|
GIObjectInfo *
|
|
g_object_info_get_parent (GIObjectInfo *info)
|
|
{
|
|
GIRealInfo *rinfo = (GIRealInfo *)info;
|
|
ObjectBlob *blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
|
|
|
|
if (blob->parent)
|
|
return (GIObjectInfo *) _g_info_from_entry (rinfo->repository,
|
|
rinfo->typelib, blob->parent);
|
|
else
|
|
return NULL;
|
|
}
|
|
|
|
gboolean
|
|
g_object_info_get_abstract (GIObjectInfo *info)
|
|
{
|
|
GIRealInfo *rinfo = (GIRealInfo *)info;
|
|
ObjectBlob *blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
|
|
return blob->abstract != 0;
|
|
}
|
|
|
|
const gchar *
|
|
g_object_info_get_type_name (GIObjectInfo *info)
|
|
{
|
|
GIRealInfo *rinfo = (GIRealInfo *)info;
|
|
ObjectBlob *blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
|
|
|
|
return g_typelib_get_string (rinfo->typelib, blob->gtype_name);
|
|
}
|
|
|
|
const gchar *
|
|
g_object_info_get_type_init (GIObjectInfo *info)
|
|
{
|
|
GIRealInfo *rinfo = (GIRealInfo *)info;
|
|
ObjectBlob *blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
|
|
|
|
return g_typelib_get_string (rinfo->typelib, blob->gtype_init);
|
|
}
|
|
|
|
gint
|
|
g_object_info_get_n_interfaces (GIObjectInfo *info)
|
|
{
|
|
GIRealInfo *rinfo = (GIRealInfo *)info;
|
|
ObjectBlob *blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
|
|
|
|
return blob->n_interfaces;
|
|
}
|
|
|
|
GIInterfaceInfo *
|
|
g_object_info_get_interface (GIObjectInfo *info,
|
|
gint n)
|
|
{
|
|
GIRealInfo *rinfo = (GIRealInfo *)info;
|
|
ObjectBlob *blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
|
|
|
|
return (GIInterfaceInfo *) _g_info_from_entry (rinfo->repository,
|
|
rinfo->typelib, blob->interfaces[n]);
|
|
}
|
|
|
|
gint
|
|
g_object_info_get_n_fields (GIObjectInfo *info)
|
|
{
|
|
GIRealInfo *rinfo = (GIRealInfo *)info;
|
|
ObjectBlob *blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
|
|
|
|
return blob->n_fields;
|
|
}
|
|
|
|
GIFieldInfo *
|
|
g_object_info_get_field (GIObjectInfo *info,
|
|
gint n)
|
|
{
|
|
gint offset;
|
|
GIRealInfo *rinfo = (GIRealInfo *)info;
|
|
Header *header = (Header *)rinfo->typelib->data;
|
|
ObjectBlob *blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
|
|
|
|
offset = rinfo->offset + header->object_blob_size
|
|
+ (blob->n_interfaces + blob->n_interfaces % 2) * 2
|
|
+ n * header->field_blob_size;
|
|
|
|
return (GIFieldInfo *) g_info_new (GI_INFO_TYPE_FIELD, (GIBaseInfo*)info, rinfo->typelib, offset);
|
|
}
|
|
|
|
gint
|
|
g_object_info_get_n_properties (GIObjectInfo *info)
|
|
{
|
|
GIRealInfo *rinfo = (GIRealInfo *)info;
|
|
ObjectBlob *blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
|
|
|
|
return blob->n_properties;
|
|
}
|
|
|
|
GIPropertyInfo *
|
|
g_object_info_get_property (GIObjectInfo *info,
|
|
gint n)
|
|
{
|
|
gint offset;
|
|
GIRealInfo *rinfo = (GIRealInfo *)info;
|
|
Header *header = (Header *)rinfo->typelib->data;
|
|
ObjectBlob *blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
|
|
|
|
offset = rinfo->offset + header->object_blob_size
|
|
+ (blob->n_interfaces + blob->n_interfaces % 2) * 2
|
|
+ blob->n_fields * header->field_blob_size
|
|
+ n * header->property_blob_size;
|
|
|
|
return (GIPropertyInfo *) g_info_new (GI_INFO_TYPE_PROPERTY, (GIBaseInfo*)info,
|
|
rinfo->typelib, offset);
|
|
}
|
|
|
|
gint
|
|
g_object_info_get_n_methods (GIObjectInfo *info)
|
|
{
|
|
GIRealInfo *rinfo = (GIRealInfo *)info;
|
|
ObjectBlob *blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
|
|
|
|
return blob->n_methods;
|
|
}
|
|
|
|
GIFunctionInfo *
|
|
g_object_info_get_method (GIObjectInfo *info,
|
|
gint n)
|
|
{
|
|
gint offset;
|
|
GIRealInfo *rinfo = (GIRealInfo *)info;
|
|
Header *header = (Header *)rinfo->typelib->data;
|
|
ObjectBlob *blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
|
|
|
|
offset = rinfo->offset + header->object_blob_size
|
|
+ (blob->n_interfaces + blob->n_interfaces % 2) * 2
|
|
+ blob->n_fields * header->field_blob_size
|
|
+ blob->n_properties * header->property_blob_size
|
|
+ n * header->function_blob_size;
|
|
|
|
return (GIFunctionInfo *) g_info_new (GI_INFO_TYPE_FUNCTION, (GIBaseInfo*)info,
|
|
rinfo->typelib, offset);
|
|
}
|
|
|
|
GIFunctionInfo *
|
|
g_object_info_find_method (GIObjectInfo *info,
|
|
const gchar *name)
|
|
{
|
|
gint offset;
|
|
GIRealInfo *rinfo = (GIRealInfo *)info;
|
|
Header *header = (Header *)rinfo->typelib->data;
|
|
ObjectBlob *blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
|
|
|
|
offset = rinfo->offset + header->object_blob_size
|
|
+ (blob->n_interfaces + blob->n_interfaces % 2) * 2
|
|
+ blob->n_fields * header->field_blob_size +
|
|
+ blob->n_properties * header->property_blob_size;
|
|
|
|
return _g_base_info_find_method ((GIBaseInfo*)info, offset, blob->n_methods, name);
|
|
}
|
|
|
|
gint
|
|
g_object_info_get_n_signals (GIObjectInfo *info)
|
|
{
|
|
GIRealInfo *rinfo = (GIRealInfo *)info;
|
|
ObjectBlob *blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
|
|
|
|
return blob->n_signals;
|
|
}
|
|
|
|
GISignalInfo *
|
|
g_object_info_get_signal (GIObjectInfo *info,
|
|
gint n)
|
|
{
|
|
gint offset;
|
|
GIRealInfo *rinfo = (GIRealInfo *)info;
|
|
Header *header = (Header *)rinfo->typelib->data;
|
|
ObjectBlob *blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
|
|
|
|
offset = rinfo->offset + header->object_blob_size
|
|
+ (blob->n_interfaces + blob->n_interfaces % 2) * 2
|
|
+ blob->n_fields * header->field_blob_size
|
|
+ blob->n_properties * header->property_blob_size
|
|
+ blob->n_methods * header->function_blob_size
|
|
+ n * header->signal_blob_size;
|
|
|
|
return (GISignalInfo *) g_info_new (GI_INFO_TYPE_SIGNAL, (GIBaseInfo*)info,
|
|
rinfo->typelib, offset);
|
|
}
|
|
|
|
gint
|
|
g_object_info_get_n_vfuncs (GIObjectInfo *info)
|
|
{
|
|
GIRealInfo *rinfo = (GIRealInfo *)info;
|
|
ObjectBlob *blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
|
|
|
|
return blob->n_vfuncs;
|
|
}
|
|
|
|
GIVFuncInfo *
|
|
g_object_info_get_vfunc (GIObjectInfo *info,
|
|
gint n)
|
|
{
|
|
gint offset;
|
|
GIRealInfo *rinfo = (GIRealInfo *)info;
|
|
Header *header = (Header *)rinfo->typelib->data;
|
|
ObjectBlob *blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
|
|
|
|
offset = rinfo->offset + header->object_blob_size
|
|
+ (blob->n_interfaces + blob->n_interfaces % 2) * 2
|
|
+ blob->n_fields * header->field_blob_size
|
|
+ blob->n_properties * header->property_blob_size
|
|
+ blob->n_methods * header->function_blob_size
|
|
+ blob->n_signals * header->signal_blob_size
|
|
+ n * header->vfunc_blob_size;
|
|
|
|
return (GIVFuncInfo *) g_info_new (GI_INFO_TYPE_VFUNC, (GIBaseInfo*)info,
|
|
rinfo->typelib, offset);
|
|
}
|
|
|
|
/**
|
|
* g_object_info_find_vfunc:
|
|
* @info: a #GIObjectInfo
|
|
* @name: The name of a virtual function to find.
|
|
*
|
|
* Locate a virtual function slot with name @name. Note that the namespace
|
|
* for virtuals is distinct from that of methods; there may or may not be
|
|
* a concrete method associated for a virtual. If there is one, it may
|
|
* be retrieved using g_vfunc_info_get_invoker(), otherwise %NULL will be
|
|
* returned.
|
|
* See the documentation for g_vfunc_info_get_invoker() for more
|
|
* information on invoking virtuals.
|
|
*
|
|
* Returns: (transfer full): the #GIVFuncInfo, or %NULL. Free it with
|
|
* g_base_info_unref() when done.
|
|
*/
|
|
GIVFuncInfo *
|
|
g_object_info_find_vfunc (GIObjectInfo *info,
|
|
const gchar *name)
|
|
{
|
|
gint offset;
|
|
GIRealInfo *rinfo = (GIRealInfo *)info;
|
|
Header *header = (Header *)rinfo->typelib->data;
|
|
ObjectBlob *blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
|
|
|
|
offset = rinfo->offset + header->object_blob_size
|
|
+ (blob->n_interfaces + blob->n_interfaces % 2) * 2
|
|
+ blob->n_fields * header->field_blob_size
|
|
+ blob->n_properties * header->property_blob_size
|
|
+ blob->n_methods * header->function_blob_size
|
|
+ blob->n_signals * header->signal_blob_size;
|
|
|
|
return _g_base_info_find_vfunc (rinfo, offset, blob->n_vfuncs, name);
|
|
}
|
|
|
|
gint
|
|
g_object_info_get_n_constants (GIObjectInfo *info)
|
|
{
|
|
GIRealInfo *rinfo = (GIRealInfo *)info;
|
|
ObjectBlob *blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
|
|
|
|
return blob->n_constants;
|
|
}
|
|
|
|
GIConstantInfo *
|
|
g_object_info_get_constant (GIObjectInfo *info,
|
|
gint n)
|
|
{
|
|
gint offset;
|
|
GIRealInfo *rinfo = (GIRealInfo *)info;
|
|
Header *header = (Header *)rinfo->typelib->data;
|
|
ObjectBlob *blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
|
|
|
|
offset = rinfo->offset + header->object_blob_size
|
|
+ (blob->n_interfaces + blob->n_interfaces % 2) * 2
|
|
+ blob->n_fields * header->field_blob_size
|
|
+ blob->n_properties * header->property_blob_size
|
|
+ blob->n_methods * header->function_blob_size
|
|
+ blob->n_signals * header->signal_blob_size
|
|
+ blob->n_vfuncs * header->vfunc_blob_size
|
|
+ n * header->constant_blob_size;
|
|
|
|
return (GIConstantInfo *) g_info_new (GI_INFO_TYPE_CONSTANT, (GIBaseInfo*)info,
|
|
rinfo->typelib, offset);
|
|
}
|
|
|
|
/**
|
|
* g_object_info_get_class_struct:
|
|
* @info: a #GIObjectInfo
|
|
*
|
|
* Every #GObject has two structures; an instance structure and a class
|
|
* structure. This function returns the metadata for the class structure.
|
|
*
|
|
* Returns: (transfer full): the #GIStructInfo or %NULL. Free with
|
|
* g_base_info_unref() when done.
|
|
*/
|
|
GIStructInfo *
|
|
g_object_info_get_class_struct (GIObjectInfo *info)
|
|
{
|
|
GIRealInfo *rinfo = (GIRealInfo *)info;
|
|
ObjectBlob *blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
|
|
|
|
if (blob->gtype_struct)
|
|
return (GIStructInfo *) _g_info_from_entry (rinfo->repository,
|
|
rinfo->typelib, blob->gtype_struct);
|
|
else
|
|
return NULL;
|
|
}
|
|
|