Introspection API



Trying to attack the introspection problem from the api side.
Here is an initial api proposal for an interface repository. 
I imagine this would be implemented on top of metadata blobs
which are mmapped readonly, thus the various *Def objects can
be very lightweight, essentially just a pointer to the metadata
plus an offset.

Does this look reasonable ? (except for the names, which are 
			     completely ad hoc)
Does it cover what is needed by language bindings ?
Are there better ways to do this ?


Comments would be appreciated,

Matthias



/*
 * Should be a singleton, all metadata blobs of loaded libraries will be registered
 * with the repository.
 */
typedef struct _GInterfaceRepository GInterfaceRepository;

/* Types of objects registered in the repository
 */
typedef struct _GRegisteredInterface GRegisteredInterface;
typedef struct _GFunctionDef GFunctionDef;
typedef struct _GMethodDef GMethodDef;
typedef struct _GConstructorDef GConstructorDef;
typedef struct _GFunctionTypeDef GFunctionTypeDef;
typedef struct _GTypeDef GTypeDef;
typedef struct _GParamDef GParamDef;
typedef struct _GRegisteredGTypeDef GRegisteredGTypeDef;
typedef struct _GEnumDef GEnumDef;
typedef struct _GFlagsDef GFlagsDef;
typedef struct _GInterfaceDef GInterfaceDef;
typedef struct _GObjectDef GObjectDef;
typedef struct _GBoxedDef GBoxedDef;
typedef struct _GStructDef GStructDef;
typedef struct _GValueDef GValueDef;
typedef struct _GFieldDef GFieldDef;
typedef struct _GPropertyDef GPropertyDef;
typedef struct _GSignalDef GSignalDef;
typedef struct _GVFuncDef GVFuncDef;

/*
inheritance hierarchy:

GRegisteredInterface
  GFunctionDef
     GMethodDef
     GConstructorDef
  GFunctionTypeDef
  GTypeDef
  GParamDef
  GRegisteredGTypeDef
    GEnumDef
    GFlagsDef
    GInterfaceDef
    GObjectDef
    GBoxedDef
  GStructDef
  GValueDef
  GFieldDef
  GPropertyDef
  GSignalDef
  GVFuncDef
*/

/* look up a registered interface by namespace, name and type. 
   (namespace and type may be NULL) 
 */ 
GRegisteredInterface * g_interface_repository_lookup           (GInterfaceRepository *repository,
								const gchar          *namespace,
								const gchar          *name,
								gint                  type);
GRegisteredInterface * g_interface_repository_find_by_gtype    (GInterfaceRepositort *repository,
								GType                 type_id);

gint                   g_interface_repository_get_n_interfaces (GInterfaceRepository *repository,
								const gchar          *namespace,
								const gchar          *name,
								gint                  type);
GRegisteredInterface * g_interface_repository_get_interface    (GInterfaceRepository *repository,
								const gchar          *namespace,
								const gchar          *name,
								gint                  type,
								gint                  position);

/* GRegisteredInterface functions */
gboolean               g_registered_interface_is_deprecated    (GRegisteredInterface *interface);
const gchar *          g_registered_interface_get_name         (GRegisteredInterface *interface);
const gchar *          g_registered_interface_get_namespace    (GRegisteredInterface *interface);


/* GFunctionDef functions */
const gchar *          g_function_def_get_symbol_name          (GFunctionDef         *function_def);
GFunctionTypeDef *     g_function_def_get_function_type        (GFunctionDef         *function_def);

/* GFunctionTypeDef functions */
typedef enum
{
  FULL_OWNERSHIP_TRANSFER,
  SHALLOW_OWNERSHIP_TRANSFER,
  NO_OWNERSHIP_TRANSFER
} Transfer;

GTypeDef *             g_function_type_def_get_return_type     (GFunctionTypeDef     *function_type_def);
Transfer               g_function_type_def_get_return_transfer (GFunctionTypeDef     *function_type_def);
gint     *             g_function_type_def_get_n_parameters    (GFunctionTypeDef     *function_type_def);
GParamDef *            g_function_type_def_get_param_def       (GFunctionTypeDef     *function_type_def,
								gint                  n);

/* GParamDef function */
typedef enum 
{
  IN,
  OUT,
  INOUT
} Direction;

Direction              g_param_def_get_direction               (GParamDef            *param_def);
gboolean               g_param_def_is_result                   (GParamDef            *param_def);
Transfer               g_param_def_get_transfer                (GParamDef            *param_def);
GTypeDef *             g_param_def_get_type                    (GParamDef            *param_def);

/* GTypeDef functions */
gboolean               g_type_def_is_pointer                   (GTypeDef             *type_def);
Tag                    g_type_def_get_tag                      (GTypeDef             *type_def);
GTypeDef *             g_type_def_get_parameter_type           (GTypeDef             *type_def,
								gint                  n);
GRegisteredInterface * g_type_def_get_interface                (GTypeDef             *type_def);

/* GRegisteredGType functions */
const gchar *          g_registered_gtype_def_get_type_name     (GRegisteredGTypeDef *gtype_def);
const gchar *          g_registered_gtype_def_get_type_init     (GRegisteredGTypeDef *gtype_def);

/* GEnumDef functions */
gint                   g_enum_def_get_n_values                 (GEnumDef             *enum_def);
GValueDef  *           g_enum_def_get_value                    (GEnumDef             *enum_def,
								gint                  n);
/* GFlagsDef functions */
gint                   g_flags_def_get_n_values                (GFlagsDef            *flags_def);
GValueDef  *           g_flags_def_get_value                   (GFlagsDef            *flags_def,
								gint                  n);

/* GValueDef functions */ 
const gchar *          g_value_def_get_short_name              (GValueDef            *value_def);
glong                  g_value_def_get_value                   (GValueDef            *value_def);

/* GFieldDef functions */
gboolean               g_field_def_is_readable                 (GFieldDef            *field_def);
gboolean               g_field_def_is_writable                 (GFieldDef            *field_def);
gint                   g_field_def_get_size                    (GFieldDef            *field_def);
GTypeDef *             g_field_def_get_type                    (GFieldDef            *field_def);

/* GStructDef functions */
gint                   g_struct_def_get_n_fields               (GStructDef           *struct_def);
GFieldDef    *         g_struct_def_get_field                  (GStructDef           *struct_def,
								gint                  n);
gint                   g_struct_def_get_n_methods              (GStructDef           *struct_def);
GFunctionDef *         g_struct_def_get_field                  (GStructDef           *struct_def,
								gint                  n);

/* GBoxedDef functions */
gint                   g_boxed_def_get_n_fields                (GBoxedDef            *boxed_def);
GFieldDef    *         g_boxed_def_get_field                   (GBoxedDef            *boxed_def,
								gint                  n);
gint                   g_boxed_def_get_n_methods               (GBoxedDef            *boxed_def);
GFunctionDef *         g_boxed_def_get_field                   (GBoxedDef            *boxed_def,
								gint                  n);

/* GInterfaceDef functions */
gint                   g_interface_def_get_n_prerequisites     (GInterfaceDef        *interface_def);
GRegisteredInterface * g_interface_get_prerequisite            (GInterfaceDef        *interface_def,
								gint                  n);
gint                   g_interface_def_get_n_methods           (GInterfaceDef        *interface_def);
GMethodDef *           g_interface_def_get_method              (GInterfaceDef        *interface_def,
								gint                  n);
gint                   g_interface_def_get_n_properties        (GInterfaceDef        *interface_def);
GPropertyDef *         g_interface_def_get_property            (GInterfaceDef        *interface_def,
								gint                  n);
gint                   g_interface_def_get_n_signals           (GInterfaceDef        *interface_def);
GSignalDef *           g_interface_def_get_signal              (GInterfaceDef        *interface_def,
								gint                  n);
gint                   g_interface_def_get_n_vfuncs            (GInterfaceDef        *interface_def);
GVFuncDef *            g_interface_def_get_vfunc               (GInterfaceDef        *interface_def,
								gint                  n);
/* GObjectDef functions */
GRegisteredInterface * g_object_def_get_parent                 (GObjectDef           *object_def);
gint                   g_object_def_get_n_interfaces           (GObjectDef           *object_def);
GInterfaceDef         *g_object_def_get_interface              (GObjectDef           *object_def,
								gint                  n);
gint                   g_object_def_get_n_constructors         (GInterfaceDef        *interface_def);
GConstructorDef *      g_object_def_get_constructor            (GObjectDef           *interface_def,
								gint                  n);
gint                   g_object_def_get_n_methods              (GObjectDef           *object_def);
GMethodDef *           g_object_def_get_method                 (GObjectDef           *object_def,
								gint                  n);
gint                   g_object_def_get_n_properties           (GObjectDef           *object_def);
GPropertyDef *         g_object_def_get_property               (GObjectDef           *object_def,
								gint                  n);
gint                   g_object_def_get_n_signals              (GObjectDef           *object_def);
GSignalDef *           g_object_def_get_signal                 (GObjectDef           *object_def,
								gint                  n);
gint                   g_object_def_get_n_vfuncs               (GObjectDef           *object_def);
GVFuncDef *            g_object_def_get_vfunc                  (GObjectDef           *object_def,
								gint                  n);
gint                   g_object_def_get_n_fields               (GObjectDef           *object_def);
GFieldDef *            g_object_def_get_fields                 (GObjectDef           *object_def,
								gint                  n);

/* GMethodDef functions */
GRegisteredInterface * g_method_def_get_interface              (GMethodDef           *method_def);
gboolean               g_method_def_is_getter                  (GMethodDef           *method_def);
gboolean               g_method_def_is_setter                  (GMethodDef           *method_def);
GPropertyDef *         g_method_def_get_property               (GMethodDef           *method_def);

/* GConstructorDef functions */
GObjectDef *           g_constructor_def_get_object            (GConstructorDef      *constructor_def);

/* GPropertyDef functions */
gboolean               g_property_def_is_readable              (GPropertyDef         *property_def);
gboolean               g_property_def_is_writable              (GPropertyDef         *property_def);
gboolean               g_property_def_is_construct             (GPropertyDef         *property_def);
gboolean               g_property_def_is_construct_only        (GPropertyDef         *property_def);
GTypeDef *             g_property_def_get_type                 (GPropertyDef         *property_def);

/* GSignalDef functions */
GRegisteredInterface * g_signal_def_get_interface              (GSignalDef           *signal_def);
RunWhen                g_signal_def_get_when                   (GSignalDef           *signal_def);
gboolean               g_signal_def_no_recurse                 (GSignalDef           *signal_def);
gboolean               g_signal_def_detailed                   (GSignalDef           *signal_def);
gboolean               g_signal_def_action                     (GSignalDef           *signal_def);
gboolean               g_signal_def_no_hooks                   (GSignalDef           *signal_def);

gboolean               g_signal_def_has_class_closure          (GSignalDef           *signal_def);
GVFuncDef *            g_signal_def_class_closure              (GSignalDef           *signal_def);
GFunctionTypeDef *     g_signal_def_get_function_type          (GSignalDef           *signal_def);

/* GVFuncDef functions */
GRegisteredInterface * g_vfunc_def_get_interface               (GVFuncDef            *vfunc_def);
gboolean               g_vfunc_def_must_chain_up               (GVFuncDef            *vfunc_def);
gboolean               g_vfunc_def_must_override               (GVFuncDef            *vfunc_def);
gboolean               g_vfunc_def_cannot_override             (GVFuncDef            *vfunc_def);
gboolean               g_vfunc_def_cannot_override             (GVFuncDef            *vfunc_def);
gboolean               g_vfunc_is_class_closure                (GVFuncDef            *vfunc_def);
GSignalDef *           g_vfunc_def_get_signal                  (GVFuncDef            *vfunc_def);









[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]