new function to get the GType given a RegisteredTypeInfo
[gnome.gobject-introspection] / girepository / girepository.h
1 /* GObject introspection: Repository
2  *
3  * Copyright (C) 2005 Matthias Clasen
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21 #ifndef __G_IREPOSITORY_H__
22 #define __G_IREPOSITORY_H__
23
24 #include <glib-object.h>
25 #include <gmodule.h>
26
27 G_BEGIN_DECLS
28
29 #define G_TYPE_IREPOSITORY      (g_irepository_get_type ())
30 #define G_IREPOSITORY(obj)      (G_TYPE_CHECK_INSTANCE_CAST ((obj), G_TYPE_IREPOSITORY, GIRepository))
31
32 typedef struct _GIRepository         GIRepository; 
33 typedef struct _GIRepositoryClass    GIRepositoryClass; 
34 typedef struct _GIRepositoryPrivate  GIRepositoryPrivate; 
35 typedef struct _GIBaseInfo           GIBaseInfo;
36 typedef struct _GICallableInfo       GICallableInfo;
37 typedef struct _GIFunctionInfo       GIFunctionInfo;
38 typedef struct _GICallbackInfo       GICallbackInfo;
39 typedef struct _GIRegisteredTypeInfo GIRegisteredTypeInfo;
40 typedef struct _GIStructInfo         GIStructInfo;
41 typedef struct _GIUnionInfo          GIUnionInfo;
42 typedef struct _GIEnumInfo           GIEnumInfo;
43 typedef struct _GIObjectInfo         GIObjectInfo;
44 typedef struct _GIInterfaceInfo      GIInterfaceInfo;
45 typedef struct _GIConstantInfo       GIConstantInfo;
46 typedef struct _GIValueInfo          GIValueInfo;
47 typedef struct _GISignalInfo         GISignalInfo;
48 typedef struct _GIVFuncInfo          GIVFuncInfo;
49 typedef struct _GIPropertyInfo       GIPropertyInfo;
50 typedef struct _GIFieldInfo          GIFieldInfo;
51 typedef struct _GIArgInfo            GIArgInfo;
52 typedef struct _GITypeInfo           GITypeInfo;
53 typedef struct _GIErrorDomainInfo    GIErrorDomainInfo;
54 typedef struct _GIUnresolvedInfo     GIUnresolvedInfo;
55 typedef struct _GMetadata            GMetadata;
56
57 struct _GIRepository 
58
59   GObject parent; 
60
61   /*< private >*/
62   GIRepositoryPrivate *priv;
63 };
64
65 struct _GIRepositoryClass
66
67   GObjectClass parent; 
68 };
69
70
71 /* Repository */
72
73 GType         g_irepository_get_type      (void) G_GNUC_CONST;
74 GIRepository *g_irepository_get_default   (void);
75 const gchar * g_irepository_register      (GIRepository *repository,
76                                            GMetadata    *metadata);
77 void          g_irepository_unregister    (GIRepository *repository,
78                                            const gchar  *namespace);
79 const gchar * g_irepository_register_file (GIRepository *repository,
80                                            const gchar  *filename,
81                                            GError      **error);
82 gboolean      g_irepository_is_registered (GIRepository *repository, 
83                                            const gchar  *namespace);
84 GIBaseInfo *  g_irepository_find_by_name  (GIRepository *repository,
85                                            const gchar  *namespace,
86                                            const gchar  *name);
87 gchar      ** g_irepository_get_namespaces (GIRepository *repository);
88 GIBaseInfo *  g_irepository_find_by_gtype (GIRepository *repository,
89                                            GType         gtype);
90 gint          g_irepository_get_n_infos   (GIRepository *repository,
91                                            const gchar  *namespace);
92 GIBaseInfo *  g_irepository_get_info      (GIRepository *repository,
93                                            const gchar  *namespace,
94                                            gint          index);
95 const gchar * g_irepository_get_shared_library (GIRepository *repository,
96                                                 const gchar  *namespace);
97 /* Metadata */
98
99 GMetadata *   g_metadata_new_from_memory       (guchar       *memory,
100                                                 gsize         len);
101 GMetadata *   g_metadata_new_from_const_memory (const guchar *memory,
102                                                 gsize         len);
103 GMetadata *   g_metadata_new_from_mapped_file  (GMappedFile  *mfile);
104 void          g_metadata_free                  (GMetadata    *metadata);
105 void          g_metadata_set_module            (GMetadata    *metadata,
106                                                 GModule      *module);
107 const gchar * g_metadata_get_namespace         (GMetadata    *metadata);
108
109 typedef enum
110 {
111   G_IREPOSITORY_ERROR_METADATA_NOT_FOUND,
112   G_IREPOSITORY_ERROR_NAMESPACE_MISMATCH,
113   G_IREPOSITORY_ERROR_LIBRARY_NOT_FOUND
114 } GIRepositoryError;
115
116 #define G_IREPOSITORY_ERROR (g_irepository_error_quark ())
117
118 GQuark g_irepository_error_quark (void);
119
120
121 /* Types of objects registered in the repository */
122
123 typedef enum 
124 {
125   GI_INFO_TYPE_INVALID,
126   GI_INFO_TYPE_FUNCTION,
127   GI_INFO_TYPE_CALLBACK,
128   GI_INFO_TYPE_STRUCT,
129   GI_INFO_TYPE_BOXED,
130   GI_INFO_TYPE_ENUM,
131   GI_INFO_TYPE_FLAGS,
132   GI_INFO_TYPE_OBJECT,
133   GI_INFO_TYPE_INTERFACE,
134   GI_INFO_TYPE_CONSTANT,
135   GI_INFO_TYPE_ERROR_DOMAIN,
136   GI_INFO_TYPE_UNION,
137   GI_INFO_TYPE_VALUE,
138   GI_INFO_TYPE_SIGNAL,
139   GI_INFO_TYPE_VFUNC,
140   GI_INFO_TYPE_PROPERTY,
141   GI_INFO_TYPE_FIELD,
142   GI_INFO_TYPE_ARG,
143   GI_INFO_TYPE_TYPE,
144   GI_INFO_TYPE_UNRESOLVED
145 } GIInfoType;
146
147
148 /* GIBaseInfo */
149
150 GIBaseInfo *           g_base_info_ref              (GIBaseInfo   *info);
151 void                   g_base_info_unref            (GIBaseInfo   *info);
152 GIInfoType             g_base_info_get_type         (GIBaseInfo   *info);
153 const gchar *          g_base_info_get_name         (GIBaseInfo   *info);
154 const gchar *          g_base_info_get_namespace    (GIBaseInfo   *info);
155 gboolean               g_base_info_is_deprecated    (GIBaseInfo   *info);
156 const gchar *          g_base_info_get_annotation   (GIBaseInfo   *info,
157                                                      const gchar  *name);
158 GIBaseInfo *           g_base_info_get_container    (GIBaseInfo   *info);
159 GMetadata *            g_base_info_get_metadata     (GIBaseInfo   *info);
160
161 GIBaseInfo *           g_info_new                   (GIInfoType     type,
162                                                      GIBaseInfo    *container,
163                                                      GMetadata     *metadata, 
164                                                      guint32       offset);
165
166
167 /* GIFunctionInfo */
168
169 typedef enum
170 {
171   GI_FUNCTION_IS_METHOD      = 1 << 0,
172   GI_FUNCTION_IS_CONSTRUCTOR = 1 << 1,
173   GI_FUNCTION_IS_GETTER      = 1 << 2,
174   GI_FUNCTION_IS_SETTER      = 1 << 3,
175   GI_FUNCTION_WRAPS_VFUNC    = 1 << 4
176 } GIFunctionInfoFlags;
177
178 const gchar *           g_function_info_get_symbol     (GIFunctionInfo *info);
179 GIFunctionInfoFlags     g_function_info_get_flags      (GIFunctionInfo *info);
180 GIPropertyInfo *        g_function_info_get_property   (GIFunctionInfo *info);
181 GIVFuncInfo *           g_function_info_get_vfunc      (GIFunctionInfo *info);
182
183 typedef union 
184 {
185   gboolean v_boolean;
186   gint8    v_int8;
187   guint8   v_uint8;
188   gint16   v_int16;
189   guint16  v_uint16;
190   gint32   v_int32;
191   guint32  v_uint32;
192   gint64   v_int64;
193   guint64  v_uint64;
194   gfloat   v_float;
195   gdouble  v_double;
196   gint     v_int;
197   guint    v_uint;
198   glong    v_long;
199   gulong   v_ulong;
200   gssize   v_ssize;
201   gsize    v_size;
202   gchar *  v_string;
203   gpointer v_pointer;
204 } GArgument;
205
206 #define G_INVOKE_ERROR (g_invoke_error_quark ())
207 GQuark g_invoke_error_quark (void);
208
209 typedef enum
210 {
211   G_INVOKE_ERROR_FAILED,
212   G_INVOKE_ERROR_SYMBOL_NOT_FOUND,
213   G_INVOKE_ERROR_ARGUMENT_MISMATCH
214 } GInvokeError;
215
216 gboolean              g_function_info_invoke         (GIFunctionInfo *info, 
217                                                       const GArgument  *in_args,
218                                                       int               n_in_args,
219                                                       const GArgument  *out_args,
220                                                       int               n_out_args,
221                                                       GArgument        *return_value,
222                                                       GError          **error);
223
224
225 /* GICallableInfo */
226
227 typedef enum {
228   GI_TRANSFER_NOTHING,
229   GI_TRANSFER_CONTAINER,
230   GI_TRANSFER_EVERYTHING
231 } GITransfer;
232
233 GITypeInfo *           g_callable_info_get_return_type (GICallableInfo *info);
234 GITransfer             g_callable_info_get_caller_owns (GICallableInfo *info);
235 gboolean               g_callable_info_may_return_null (GICallableInfo *info);
236 gint                   g_callable_info_get_n_args      (GICallableInfo *info);
237 GIArgInfo *            g_callable_info_get_arg         (GICallableInfo *info,
238                                                         gint           n);
239
240 /* GIArgInfo */
241
242 typedef enum  {
243   GI_DIRECTION_IN,
244   GI_DIRECTION_OUT,
245   GI_DIRECTION_INOUT
246 } GIDirection;
247
248 GIDirection            g_arg_info_get_direction          (GIArgInfo *info);
249 gboolean               g_arg_info_is_dipper              (GIArgInfo *info);
250 gboolean               g_arg_info_is_return_value        (GIArgInfo *info);
251 gboolean               g_arg_info_is_optional            (GIArgInfo *info);
252 gboolean               g_arg_info_may_be_null            (GIArgInfo *info);
253 GITransfer             g_arg_info_get_ownership_transfer (GIArgInfo *info);
254 GITypeInfo *           g_arg_info_get_type               (GIArgInfo *info);
255
256
257 /* GITypeInfo */
258
259 typedef enum {
260   GI_TYPE_TAG_VOID      =  0,
261   GI_TYPE_TAG_BOOLEAN   =  1,
262   GI_TYPE_TAG_INT8      =  2,
263   GI_TYPE_TAG_UINT8     =  3,
264   GI_TYPE_TAG_INT16     =  4,
265   GI_TYPE_TAG_UINT16    =  5,  
266   GI_TYPE_TAG_INT32     =  6,
267   GI_TYPE_TAG_UINT32    =  7,
268   GI_TYPE_TAG_INT64     =  8,
269   GI_TYPE_TAG_UINT64    =  9,
270   GI_TYPE_TAG_INT       = 10,
271   GI_TYPE_TAG_UINT      = 11,
272   GI_TYPE_TAG_LONG      = 12,
273   GI_TYPE_TAG_ULONG     = 13,
274   GI_TYPE_TAG_SSIZE     = 14,
275   GI_TYPE_TAG_SIZE      = 15,
276   GI_TYPE_TAG_FLOAT     = 16,
277   GI_TYPE_TAG_DOUBLE    = 17,
278   GI_TYPE_TAG_UTF8      = 18,
279   GI_TYPE_TAG_FILENAME  = 19,
280   GI_TYPE_TAG_ARRAY     = 20,
281   GI_TYPE_TAG_INTERFACE = 21,
282   GI_TYPE_TAG_GLIST     = 22,
283   GI_TYPE_TAG_GSLIST    = 23,
284   GI_TYPE_TAG_GHASH     = 24,
285   GI_TYPE_TAG_ERROR     = 25
286 } GITypeTag;
287
288 gboolean               g_type_info_is_pointer          (GITypeInfo *info);
289 GITypeTag              g_type_info_get_tag             (GITypeInfo *info);
290 GITypeInfo *           g_type_info_get_param_type      (GITypeInfo *info,
291                                                         gint       n);
292 GIBaseInfo *           g_type_info_get_interface       (GITypeInfo *info);
293 gint                   g_type_info_get_array_length    (GITypeInfo *info);
294 gboolean               g_type_info_is_zero_terminated  (GITypeInfo *info);
295
296 gint                   g_type_info_get_n_error_domains (GITypeInfo *info);
297 GIErrorDomainInfo     *g_type_info_get_error_domain    (GITypeInfo *info,
298                                                         gint       n);
299
300 /* GIErrorDomainInfo */
301
302 const gchar *          g_error_domain_info_get_quark   (GIErrorDomainInfo *info);
303 GIInterfaceInfo *           g_error_domain_info_get_codes (GIErrorDomainInfo *info);
304
305
306 /* GIValueInfo */
307  
308 glong                  g_value_info_get_value      (GIValueInfo *info);
309
310
311 /* GIFieldInfo */
312
313 typedef enum
314 {
315   GI_FIELD_IS_READABLE = 1 << 0,
316   GI_FIELD_IS_WRITABLE = 1 << 1
317 } GIFieldInfoFlags;
318
319 GIFieldInfoFlags       g_field_info_get_flags      (GIFieldInfo *info);
320 gint                   g_field_info_get_size       (GIFieldInfo *info);
321 gint                   g_field_info_get_offset     (GIFieldInfo *info);
322 GITypeInfo *           g_field_info_get_type       (GIFieldInfo *info);
323
324
325 /* GIUnionInfo */
326 gint                   g_union_info_get_n_fields  (GIUnionInfo *info);
327 GIFieldInfo *          g_union_info_get_field     (GIUnionInfo *info,
328                                                    gint         n);
329 gint                   g_union_info_get_n_methods (GIUnionInfo *info);
330 GIFunctionInfo *       g_union_info_get_method    (GIUnionInfo *info,
331                                                    gint         n);
332 gboolean               g_union_info_is_discriminated (GIUnionInfo *info);
333 gint                   g_union_info_get_discriminator_offset (GIUnionInfo *info);
334 GITypeInfo *           g_union_info_get_discriminator_type (GIUnionInfo *info);
335 GIConstantInfo *       g_union_info_get_discriminator      (GIUnionInfo *info,
336                                                             gint         n);
337
338
339 /* GIStructInfo */
340 gint                   g_struct_info_get_n_fields  (GIStructInfo *info);
341 GIFieldInfo *          g_struct_info_get_field     (GIStructInfo *info,
342                                                     gint         n);
343 gint                   g_struct_info_get_n_methods (GIStructInfo *info);
344 GIFunctionInfo *       g_struct_info_get_method    (GIStructInfo *info,
345                                                     gint         n);
346 GIFunctionInfo *       g_struct_info_find_method   (GIStructInfo *info,
347                                                     const gchar *name);
348
349 /* GIRegisteredTypeInfo */
350
351 const gchar *          g_registered_type_info_get_type_name (GIRegisteredTypeInfo *info);
352 const gchar *          g_registered_type_info_get_type_init (GIRegisteredTypeInfo *info);
353 GType                  g_registered_type_info_get_g_type    (GIRegisteredTypeInfo *info);
354
355 /* GIEnumInfo */
356
357 gint                   g_enum_info_get_n_values             (GIEnumInfo      *info);
358 GIValueInfo  *         g_enum_info_get_value                (GIEnumInfo      *info,
359                                                              gint            n);
360
361 /* GIObjectInfo */
362
363 const gchar *          g_object_info_get_type_name          (GIObjectInfo    *info);
364 const gchar *          g_object_info_get_type_init          (GIObjectInfo    *info);
365 GIObjectInfo *         g_object_info_get_parent             (GIObjectInfo    *info);
366 gint                   g_object_info_get_n_interfaces       (GIObjectInfo    *info);
367 GIInterfaceInfo *      g_object_info_get_interface          (GIObjectInfo    *info,
368                                                              gint            n);
369 gint                   g_object_info_get_n_fields           (GIObjectInfo    *info);
370 GIFieldInfo *          g_object_info_get_field              (GIObjectInfo    *info,
371                                                              gint            n);
372 gint                   g_object_info_get_n_properties       (GIObjectInfo    *info);
373 GIPropertyInfo *       g_object_info_get_property           (GIObjectInfo    *info,
374                                                              gint            n);
375 gint                   g_object_info_get_n_methods          (GIObjectInfo    *info);
376 GIFunctionInfo *       g_object_info_get_method             (GIObjectInfo    *info,
377                                                              gint            n);
378 GIFunctionInfo *       g_object_info_find_method            (GIObjectInfo *info,
379                                                              const gchar *name);
380 gint                   g_object_info_get_n_signals          (GIObjectInfo    *info);
381 GISignalInfo *         g_object_info_get_signal             (GIObjectInfo    *info,
382                                                              gint            n);
383 gint                   g_object_info_get_n_vfuncs           (GIObjectInfo    *info);
384 GIVFuncInfo *          g_object_info_get_vfunc              (GIObjectInfo    *info,
385                                                              gint            n);
386 gint                   g_object_info_get_n_constants        (GIObjectInfo    *info);
387 GIConstantInfo *       g_object_info_get_constant           (GIObjectInfo    *info,
388                                                              gint            n);
389
390                                                              
391 /* GIInterfaceInfo */
392
393 gint                   g_interface_info_get_n_prerequisites (GIInterfaceInfo *info);
394 GIBaseInfo *           g_interface_info_get_prerequisite    (GIInterfaceInfo *info,
395                                                              gint        n);
396 gint                   g_interface_info_get_n_properties    (GIInterfaceInfo *info);
397 GIPropertyInfo *       g_interface_info_get_property        (GIInterfaceInfo *info,
398                                                              gint        n);
399 gint                   g_interface_info_get_n_methods       (GIInterfaceInfo *info);
400 GIFunctionInfo *       g_interface_info_get_method          (GIInterfaceInfo *info,
401                                                              gint        n);
402 GIFunctionInfo *       g_interface_info_find_method         (GIInterfaceInfo *info,
403                                                              const gchar *name);
404 gint                   g_interface_info_get_n_signals       (GIInterfaceInfo *info);
405 GISignalInfo *         g_interface_info_get_signal          (GIInterfaceInfo *info,
406                                                              gint        n);
407 gint                   g_interface_info_get_n_vfuncs        (GIInterfaceInfo *info);
408 GIVFuncInfo *          g_interface_info_get_vfunc           (GIInterfaceInfo *info,
409                                                              gint        n);
410 gint                   g_interface_info_get_n_constants     (GIInterfaceInfo *info);
411 GIConstantInfo *       g_interface_info_get_constant        (GIInterfaceInfo *info,
412                                                              gint        n);
413
414
415 /* GIPropertyInfo  */
416
417 GParamFlags             g_property_info_get_flags                (GIPropertyInfo         *info);
418 GITypeInfo *            g_property_info_get_type                 (GIPropertyInfo         *info);
419
420
421 /* GISignalInfo */
422
423 GSignalFlags            g_signal_info_get_flags                  (GISignalInfo           *info);
424 GIVFuncInfo *           g_signal_info_get_class_closure          (GISignalInfo           *info);
425 gboolean                g_signal_info_true_stops_emit            (GISignalInfo           *info);
426
427
428 /* GIVFuncInfo */
429
430 typedef enum
431 {
432   GI_VFUNC_MUST_CHAIN_UP     = 1 << 0,
433   GI_VFUNC_MUST_OVERRIDE     = 1 << 1,
434   GI_VFUNC_MUST_NOT_OVERRIDE = 1 << 2
435 } GIVFuncInfoFlags;
436
437 GIVFuncInfoFlags        g_vfunc_info_get_flags                   (GIVFuncInfo            *info);
438 gint                    g_vfunc_info_get_offset                  (GIVFuncInfo            *info);
439 GISignalInfo *          g_vfunc_info_get_signal                  (GIVFuncInfo            *info);
440
441
442 /* GIConstantInfo */
443
444 GITypeInfo *            g_constant_info_get_type                 (GIConstantInfo         *info);
445 gint                    g_constant_info_get_value                (GIConstantInfo         *info,
446                                                                   GArgument             *value);
447
448
449 G_END_DECLS
450
451 #endif  /* __G_IREPOSITORY_H__ */
452