Bug 555294: Add support for multiple shared libraries per typelib.
[gnome.gobject-introspection] / girepository / gtypelib.h
1 /* GObject introspection: struct definitions for the binary
2  * typelib format, validation
3  *
4  * Copyright (C) 2005 Matthias Clasen
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21
22 #ifndef __G_TYPELIB_H__
23 #define __G_TYPELIB_H__
24
25 #include <gmodule.h>
26 #include "girepository.h"
27
28 G_BEGIN_DECLS
29
30 #define G_IR_MAGIC "GOBJ\nMETADATA\r\n\032"
31
32 enum 
33 {
34   BLOB_TYPE_INVALID,
35   BLOB_TYPE_FUNCTION,
36   BLOB_TYPE_CALLBACK,
37   BLOB_TYPE_STRUCT,
38   BLOB_TYPE_BOXED,
39   BLOB_TYPE_ENUM,
40   BLOB_TYPE_FLAGS,
41   BLOB_TYPE_OBJECT,
42   BLOB_TYPE_INTERFACE,
43   BLOB_TYPE_CONSTANT,
44   BLOB_TYPE_ERROR_DOMAIN,
45   BLOB_TYPE_UNION
46 };
47
48 typedef struct
49 {
50   gchar   magic[16];
51   guint8  major_version;
52   guint8  minor_version;
53   guint16 reserved;
54   guint16 n_entries;
55   guint16 n_local_entries;
56   guint32 directory;
57   guint32 n_annotations;
58   guint32 annotations;
59
60   guint32 dependencies;
61
62   guint32 size;
63   guint32 namespace;
64   guint32 shared_library;
65
66   guint16 entry_blob_size;
67   guint16 function_blob_size;
68   guint16 callback_blob_size;
69   guint16 signal_blob_size;
70   guint16 vfunc_blob_size;
71   guint16 arg_blob_size;
72   guint16 property_blob_size;
73   guint16 field_blob_size;
74   guint16 value_blob_size;
75   guint16 annotation_blob_size;
76   guint16 constant_blob_size;
77   guint16 error_domain_blob_size;
78
79   guint16 signature_blob_size;
80   guint16 enum_blob_size;
81   guint16 struct_blob_size;
82   guint16 object_blob_size;
83   guint16 interface_blob_size;
84   guint16 union_blob_size;
85   
86   guint16 padding[7];
87 } Header;
88
89 typedef struct
90 {
91   guint16 blob_type;
92
93   guint16 local    : 1;
94   guint16 reserved :15;
95
96   guint32 name;
97   guint32 offset;
98 } DirEntry;
99
100
101 typedef union
102 {
103   struct 
104   {
105     guint reserved   : 8;
106     guint reserved2  :16;
107     guint pointer    : 1;
108     guint reserved3  : 2;
109     guint tag        : 5;    
110   };
111   guint32    offset;
112 } SimpleTypeBlob;
113
114
115 typedef struct
116 {
117   guint32        name;
118
119   guint          in                           : 1;
120   guint          out                          : 1;
121   guint          dipper                       : 1;
122   guint          null_ok                      : 1;
123   guint          optional                     : 1;
124   guint          transfer_ownership           : 1;
125   guint          transfer_container_ownership : 1;
126   guint          return_value                 : 1;
127   guint          reserved                     :24;
128
129   SimpleTypeBlob arg_type;
130 } ArgBlob;
131
132 typedef struct 
133 {
134   SimpleTypeBlob return_type;
135
136   guint16        may_return_null              : 1;
137   guint16        caller_owns_return_value     : 1;
138   guint16        caller_owns_return_container : 1;
139   guint16        reserved                     :13;
140
141   guint16        n_arguments;
142
143   ArgBlob        arguments[];
144 } SignatureBlob;
145
146 typedef struct
147 {
148   guint16 blob_type;  /* 1 */
149
150   guint16 deprecated : 1;
151   guint16 reserved   :15;
152
153   guint32 name;
154 } CommonBlob;
155
156 typedef struct 
157 {
158   guint16 blob_type;  /* 1 */
159
160   guint16 deprecated  : 1;
161   guint16 setter      : 1; 
162   guint16 getter      : 1;
163   guint16 constructor : 1;
164   guint16 wraps_vfunc : 1;
165   guint16 reserved    : 1;
166   guint16 index       :10;
167
168   guint32 name;
169   guint32 symbol;
170   guint32 signature;
171 } FunctionBlob;
172
173 typedef struct 
174 {
175   guint16 blob_type;  /* 2 */
176
177   guint16 deprecated : 1;
178   guint16 reserved   :15;
179
180   guint32 name;
181   guint32 signature;
182 } CallbackBlob;
183
184 typedef struct 
185 {
186   guint8  pointer  :1;
187   guint8  reserved :2;
188   guint8  tag      :5;    
189   guint8  reserved2;
190   guint16 interface;  
191 } InterfaceTypeBlob;
192
193 typedef struct
194 {
195   guint16 pointer         :1;
196   guint16 reserved        :2;
197   guint16 tag             :5;    
198
199   guint16 zero_terminated :1;
200   guint16 has_length      :1;
201   guint16 reserved2       :6;
202
203   guint16 length;
204
205   SimpleTypeBlob type;
206 } ArrayTypeBlob;
207
208 typedef struct
209 {
210   guint8         pointer  :1;
211   guint8         reserved :2;
212   guint8         tag      :5;    
213
214   guint8         reserved2;
215   guint16        n_types;
216
217   SimpleTypeBlob type[];
218 } ParamTypeBlob;
219
220 typedef struct
221 {
222   guint8  pointer  :1;
223   guint8  reserved :2;
224   guint8  tag      :5;    
225
226   guint8  reserved2;
227   guint16 n_domains;
228
229   guint16 domains[];
230 }  ErrorTypeBlob;
231
232 typedef struct
233 {
234   guint16 blob_type;  /* 10 */
235
236   guint16 deprecated : 1;
237   guint16 reserved   :15;
238   
239   guint32 name;
240
241   guint32 get_quark;
242   guint16 error_codes;
243   guint16 reserved2;
244 } ErrorDomainBlob;
245
246 typedef struct
247 {
248   guint32 deprecated : 1;
249   guint32 reserved   :31;
250   guint32 name;
251   guint32 value;
252 } ValueBlob;
253
254 typedef struct 
255 {
256   guint32        name;
257
258   guint8         readable :1; 
259   guint8         writable :1;
260   guint8         reserved :6;
261   guint8         bits;
262
263   guint16        struct_offset;      
264
265   SimpleTypeBlob type;
266 } FieldBlob;
267
268 typedef struct
269 {
270   guint16 blob_type;  
271   guint16 deprecated   : 1; 
272   guint16 unregistered :15;
273   guint32 name; 
274
275   guint32 gtype_name;
276   guint32 gtype_init;
277 } RegisteredTypeBlob;
278
279 typedef struct
280 {
281   guint16   blob_type;
282
283   guint16   deprecated   : 1;
284   guint16   unregistered : 1;
285   guint16   reserved     :14;
286
287   guint32   name;
288
289   guint32   gtype_name;
290   guint32   gtype_init;
291
292   guint16   n_fields;
293   guint16   n_methods;
294
295 #if 0
296   /* variable-length parts of the blob */
297   FieldBlob    fields[];   
298   FunctionBlob methods[];
299 #endif
300 } StructBlob;
301
302 typedef struct 
303 {  
304   guint16      blob_type; 
305   guint16      deprecated    : 1;
306   guint16      unregistered  : 1;
307   guint16      discriminated : 1;
308   guint16      reserved      :13;
309   guint32      name;
310
311   guint32      gtype_name;
312   guint32      gtype_init;
313
314   guint16      n_fields;
315   guint16      n_functions;
316
317   gint32       discriminator_offset; 
318   SimpleTypeBlob discriminator_type;
319
320 #if 0
321   FieldBlob    fields[];   
322   FunctionBlob functions[];  
323   ConstantBlob discriminator_values[]
324 #endif
325 } UnionBlob;
326
327 typedef struct
328 {
329   guint16   blob_type;
330
331   guint16   deprecated   : 1; 
332   guint16   unregistered : 1;
333   guint16   reserved     :14;
334
335   guint32   name; 
336
337   guint32   gtype_name;
338   guint32   gtype_init;
339
340   guint16   n_values;
341   guint16   reserved2;
342
343   ValueBlob values[];    
344 } EnumBlob;
345
346 typedef struct
347 {
348   guint32        name;
349
350   guint32        deprecated     : 1;
351   guint32        readable       : 1;
352   guint32        writable       : 1;
353   guint32        construct      : 1;
354   guint32        construct_only : 1;
355   guint32        reserved       :27;
356
357   SimpleTypeBlob type;
358
359 } PropertyBlob;
360
361 typedef struct
362 {
363   guint16 deprecated        : 1;
364   guint16 run_first         : 1;
365   guint16 run_last          : 1;
366   guint16 run_cleanup       : 1;
367   guint16 no_recurse        : 1;
368   guint16 detailed          : 1;
369   guint16 action            : 1;
370   guint16 no_hooks          : 1;
371   guint16 has_class_closure : 1;
372   guint16 true_stops_emit   : 1;
373   guint16 reserved          : 6;
374
375   guint16 class_closure;
376
377   guint32 name;
378
379   guint32 signature;
380 } SignalBlob;
381
382 typedef struct 
383 {
384   guint32 name;
385
386   guint16 must_chain_up           : 1;
387   guint16 must_be_implemented     : 1;
388   guint16 must_not_be_implemented : 1;
389   guint16 class_closure           : 1;
390   guint16 reserved                :12;
391   guint16 signal;
392
393   guint16 struct_offset;
394   guint16 reserved2;
395   guint32 signature;
396 } VFuncBlob;
397
398 typedef struct
399 {
400   guint16   blob_type;  /* 7 */
401   guint16   deprecated   : 1; 
402   guint16   reserved     :15;
403   guint32   name; 
404
405   guint32   gtype_name;
406   guint32   gtype_init;
407
408   guint16   parent;
409
410   guint16   n_interfaces;
411   guint16   n_fields;
412   guint16   n_properties;
413   guint16   n_methods;
414   guint16   n_signals;
415   guint16   n_vfuncs;
416   guint16   n_constants;
417
418   guint16   interfaces[];
419  
420 #if 0
421   /* variable-length parts of the blob */
422   FieldBlob           fields[];
423   PropertyBlob        properties[];
424   FunctionBlob        methods[];
425   SignalBlob          signals[];
426   VFuncBlob           vfuncs[];
427   ConstantBlob        constants[];
428 #endif
429 } ObjectBlob;
430
431 typedef struct 
432 {
433   guint16 blob_type;  
434   guint16 deprecated   : 1; 
435   guint16 reserved     :15;
436   guint32 name; 
437
438   guint32 gtype_name;
439   guint32 gtype_init;
440
441   guint16 n_prerequisites;
442   guint16 n_properties;
443   guint16 n_methods;
444   guint16 n_signals;
445   guint16 n_vfuncs;
446   guint16 n_constants;  
447
448   guint16 prerequisites[];
449
450 #if 0 
451   /* variable-length parts of the blob */
452   PropertyBlob        properties[];
453   FunctionBlob        methods[];
454   SignalBlob          signals[];
455   VFuncBlob           vfuncs[];
456   ConstantBlob        constants[];
457 #endif
458 } InterfaceBlob;
459
460
461 typedef struct
462 {
463   guint16        blob_type;
464   guint16        deprecated   : 1; 
465   guint16        reserved     :15;
466   guint32        name; 
467
468   SimpleTypeBlob type;
469
470   guint32        size;
471   guint32        offset;
472 } ConstantBlob;
473
474 typedef struct
475
476   guint32 offset;
477   guint32 name;
478   guint32 value;
479 } AnnotationBlob;
480
481
482 struct _GTypelib {
483   guchar *data;
484   gsize len;
485   gboolean owns_memory;
486   GMappedFile *mfile;
487   GList *modules;
488 };
489
490 DirEntry *g_typelib_get_dir_entry (GTypelib *typelib,
491                                    guint16   index);
492
493 void      g_typelib_check_sanity (void);
494
495 #define   g_typelib_get_string(typelib,offset) ((const gchar*)&(typelib->data)[(offset)])
496
497
498 typedef enum
499 {
500   G_TYPELIB_ERROR_INVALID,
501   G_TYPELIB_ERROR_INVALID_HEADER,
502   G_TYPELIB_ERROR_INVALID_DIRECTORY,
503   G_TYPELIB_ERROR_INVALID_ENTRY,
504   G_TYPELIB_ERROR_INVALID_BLOB
505 } GTypelibError;
506
507 #define G_TYPELIB_ERROR (g_typelib_error_quark ())
508
509 GQuark g_typelib_error_quark (void);
510
511 gboolean g_typelib_validate (GTypelib  *typelib,
512                              GError    **error);
513
514
515 G_END_DECLS
516
517 #endif  /* __G_TYPELIB_H__ */
518