Rename metadata to typelib in variable names, comments and apis.
[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 size;
61   guint32 namespace;
62   guint32 shared_library;
63
64   guint16 entry_blob_size;
65   guint16 function_blob_size;
66   guint16 callback_blob_size;
67   guint16 signal_blob_size;
68   guint16 vfunc_blob_size;
69   guint16 arg_blob_size;
70   guint16 property_blob_size;
71   guint16 field_blob_size;
72   guint16 value_blob_size;
73   guint16 annotation_blob_size;
74   guint16 constant_blob_size;
75   guint16 error_domain_blob_size;
76
77   guint16 signature_blob_size;
78   guint16 enum_blob_size;
79   guint16 struct_blob_size;
80   guint16 object_blob_size;
81   guint16 interface_blob_size;
82   guint16 union_blob_size;
83   
84   guint16 padding[7];
85 } Header;
86
87 typedef struct
88 {
89   guint16 blob_type;
90
91   guint   local    : 1;
92   guint   reserved :15;
93
94   guint32 name;
95   guint32 offset;
96 } DirEntry;
97
98
99 #define TYPE_POINTER_MASK 1 << 7
100 #define TYPE_TAG_MASK         63
101
102 typedef enum 
103 {
104   TYPE_TAG_VOID      =  0,
105   TYPE_TAG_BOOLEAN   =  1,
106   TYPE_TAG_INT8      =  2,
107   TYPE_TAG_UINT8     =  3,
108   TYPE_TAG_INT16     =  4,
109   TYPE_TAG_UINT16    =  5,  
110   TYPE_TAG_INT32     =  6,
111   TYPE_TAG_UINT32    =  7,
112   TYPE_TAG_INT64     =  8,
113   TYPE_TAG_UINT64    =  9,
114   TYPE_TAG_INT       = 10,
115   TYPE_TAG_UINT      = 11,
116   TYPE_TAG_LONG      = 12,
117   TYPE_TAG_ULONG     = 13,
118   TYPE_TAG_SSIZE     = 14,
119   TYPE_TAG_SIZE      = 15,
120   TYPE_TAG_FLOAT     = 16,
121   TYPE_TAG_DOUBLE    = 17,
122   TYPE_TAG_UTF8      = 18,
123   TYPE_TAG_FILENAME  = 19,
124   TYPE_TAG_ARRAY     = 20,
125   TYPE_TAG_INTERFACE = 21,
126   TYPE_TAG_LIST      = 22,
127   TYPE_TAG_SLIST     = 23,
128   TYPE_TAG_HASH      = 24,
129   TYPE_TAG_ERROR     = 25,
130   TYPE_TAG_STRING    = 26,
131   TYPE_TAG_SEQUENCE  = 27,
132   TYPE_TAG_ANY       = 28
133 } TypeTag;
134
135 typedef union
136 {
137   struct 
138   {
139     guint reserved   : 8;
140     guint reserved2  :16;
141     guint pointer    : 1;
142     guint reserved3  : 2;
143     guint tag        : 5;    
144   };
145   guint32    offset;
146 } SimpleTypeBlob;
147
148
149 typedef struct
150 {
151   guint32        name;
152
153   guint          in                           : 1;
154   guint          out                          : 1;
155   guint          dipper                       : 1;
156   guint          null_ok                      : 1;
157   guint          optional                     : 1;
158   guint          transfer_ownership           : 1;
159   guint          transfer_container_ownership : 1;
160   guint          return_value                 : 1;
161   guint          reserved                     :24;
162
163   SimpleTypeBlob arg_type;
164 } ArgBlob;
165
166 typedef struct 
167 {
168   SimpleTypeBlob return_type;
169
170   guint          may_return_null              : 1;
171   guint          caller_owns_return_value     : 1;
172   guint          caller_owns_return_container : 1;
173   guint          reserved                     :13;
174
175   guint16        n_arguments;
176
177   ArgBlob        arguments[];
178 } SignatureBlob;
179
180 typedef struct
181 {
182   guint16 blob_type;  /* 1 */
183
184   guint   deprecated     : 1;
185   guint   reserved       :15;
186
187   guint32 name;
188 } CommonBlob;
189
190 typedef struct 
191 {
192   guint16 blob_type;  /* 1 */
193
194   guint   deprecated     : 1;
195   guint   setter         : 1; 
196   guint   getter         : 1;
197   guint   constructor    : 1;
198   guint   wraps_vfunc    : 1;
199   guint   reserved       : 1;
200   guint   index          :10;
201
202   guint32 name;
203   guint32 symbol;
204   guint32 signature;
205 } FunctionBlob;
206
207 typedef struct 
208 {
209   guint16 blob_type;  /* 2 */
210
211   guint   deprecated     : 1;
212   guint   reserved       :15;
213
214   guint32 name;
215   guint32 signature;
216 } CallbackBlob;
217
218 typedef struct 
219 {
220   guint pointer    :1;
221   guint reserved   :2;
222   guint tag        :5;    
223   guint8     reserved2;
224   guint16    interface;  
225 } InterfaceTypeBlob;
226
227 typedef struct
228 {
229   guint pointer    :1;
230   guint reserved   :2;
231   guint tag        :5;    
232
233   guint          zero_terminated :1;
234   guint          has_length      :1;
235   guint          reserved2       :6;
236
237   guint16        length;
238
239   SimpleTypeBlob type;
240 } ArrayTypeBlob;
241
242 typedef struct
243 {
244   guint pointer    :1;
245   guint reserved   :2;
246   guint tag        :5;    
247
248   guint8         reserved2;
249   guint16        n_types;
250
251   SimpleTypeBlob type[];
252 } ParamTypeBlob;
253
254 typedef struct
255 {
256   guint pointer    :1;
257   guint reserved   :2;
258   guint tag        :5;    
259
260   guint8     reserved2;
261   guint16    n_domains;
262
263   guint16    domains[];
264 }  ErrorTypeBlob;
265
266 typedef struct
267 {
268   guint16 blob_type;  /* 10 */
269
270   guint   deprecated     : 1;
271   guint   reserved       :15;
272   
273   guint32 name;
274
275   guint32 get_quark;
276   guint16 error_codes;
277   guint16 reserved2;
278 } ErrorDomainBlob;
279
280 typedef struct
281 {
282   guint   deprecated : 1;
283   guint   reserved   :31;
284   guint32 name;
285   guint32 value;
286 } ValueBlob;
287
288 typedef struct 
289 {
290   guint32        name;
291
292   guint          readable : 1; 
293   guint          writable : 1;
294   guint          reserved : 6;
295   guint8         bits;
296
297   guint16        struct_offset;      
298
299   SimpleTypeBlob type;
300 } FieldBlob;
301
302 typedef struct
303 {
304   guint16 blob_type;  
305   guint   deprecated   : 1; 
306   guint   unregistered :15;
307   guint32 name; 
308
309   guint32 gtype_name;
310   guint32 gtype_init;
311 } RegisteredTypeBlob;
312
313 typedef struct
314 {
315   guint16   blob_type;
316
317   guint     deprecated   : 1;
318   guint     unregistered : 1;
319   guint     reserved     :14;
320
321   guint32   name;
322
323   guint32   gtype_name;
324   guint32   gtype_init;
325
326   guint16   n_fields;
327   guint16   n_methods;
328
329 #if 0
330   /* variable-length parts of the blob */
331   FieldBlob    fields[];   
332   FunctionBlob methods[];
333 #endif
334 } StructBlob;
335
336 typedef struct 
337 {  
338   guint16      blob_type; 
339   guint        deprecated    : 1;
340   guint        unregistered  : 1;
341   guint        discriminated : 1;
342   guint        reserved      :13;
343   guint32      name;
344
345   guint32      gtype_name;
346   guint32      gtype_init;
347
348   guint16      n_fields;
349   guint16      n_functions;
350
351   gint32       discriminator_offset; 
352   SimpleTypeBlob discriminator_type;
353
354 #if 0
355   FieldBlob    fields[];   
356   FunctionBlob functions[];  
357   ConstantBlob discriminator_values[]
358 #endif
359 } UnionBlob;
360
361 typedef struct
362 {
363   guint16   blob_type;
364
365   guint     deprecated   : 1; 
366   guint     unregistered : 1;
367   guint     reserved     :14;
368
369   guint32   name; 
370
371   guint32   gtype_name;
372   guint32   gtype_init;
373
374   guint16   n_values;
375   guint16   reserved2;
376
377   ValueBlob values[];    
378 } EnumBlob;
379
380 typedef struct
381 {
382   guint32        name;
383
384   guint          deprecated     : 1;
385   guint          readable       : 1;
386   guint          writable       : 1;
387   guint          construct      : 1;
388   guint          construct_only : 1;
389   guint          reserved       :27;
390
391   SimpleTypeBlob type;
392
393 } PropertyBlob;
394
395 typedef struct
396 {
397   guint   deprecated        : 1;
398   guint   run_first         : 1;
399   guint   run_last          : 1;
400   guint   run_cleanup       : 1;
401   guint   no_recurse        : 1;
402   guint   detailed          : 1;
403   guint   action            : 1;
404   guint   no_hooks          : 1;
405   guint   has_class_closure : 1;
406   guint   true_stops_emit   : 1;
407   guint   reserved          : 6;
408
409   guint16 class_closure;
410
411   guint32 name;
412
413   guint32 signature;
414 } SignalBlob;
415
416 typedef struct 
417 {
418   guint32 name;
419
420   guint   must_chain_up           : 1;
421   guint   must_be_implemented     : 1;
422   guint   must_not_be_implemented : 1;
423   guint   class_closure           : 1;
424   guint   reserved                :12;
425   guint16 signal;
426
427   guint16 struct_offset;
428   guint16 reserved2;
429   guint32 signature;
430 } VFuncBlob;
431
432 typedef struct
433 {
434   guint16   blob_type;  /* 7 */
435   guint     deprecated   : 1; 
436   guint     reserved     :15;
437   guint32   name; 
438
439   guint32   gtype_name;
440   guint32   gtype_init;
441
442   guint16   parent;
443
444   guint16   n_interfaces;
445   guint16   n_fields;
446   guint16   n_properties;
447   guint16   n_methods;
448   guint16   n_signals;
449   guint16   n_vfuncs;
450   guint16   n_constants;
451
452   guint16   interfaces[];
453  
454 #if 0
455   /* variable-length parts of the blob */
456   FieldBlob           fields[];
457   PropertyBlob        properties[];
458   FunctionBlob        methods[];
459   SignalBlob          signals[];
460   VFuncBlob           vfuncs[];
461   ConstantBlob        constants[];
462 #endif
463 } ObjectBlob;
464
465 typedef struct 
466 {
467   guint16 blob_type;  
468   guint   deprecated   : 1; 
469   guint   reserved     :15;
470   guint32 name; 
471
472   guint32 gtype_name;
473   guint32 gtype_init;
474
475   guint16 n_prerequisites;
476   guint16 n_properties;
477   guint16 n_methods;
478   guint16 n_signals;
479   guint16 n_vfuncs;
480   guint16 n_constants;  
481
482   guint16 prerequisites[];
483
484 #if 0 
485   /* variable-length parts of the blob */
486   PropertyBlob        properties[];
487   FunctionBlob        methods[];
488   SignalBlob          signals[];
489   VFuncBlob           vfuncs[];
490   ConstantBlob        constants[];
491 #endif
492 } InterfaceBlob;
493
494
495 typedef struct
496 {
497   guint16        blob_type;
498   guint          deprecated   : 1; 
499   guint          reserved     :15;
500   guint32        name; 
501
502   SimpleTypeBlob type;
503
504   guint32        size;
505   guint32        offset;
506 } ConstantBlob;
507
508 typedef struct
509
510   guint32 offset;
511   guint32 name;
512   guint32 value;
513 } AnnotationBlob;
514
515
516 struct _GTypelib {
517   guchar *data;
518   gsize len;
519   gboolean owns_memory;
520   GMappedFile *mfile;
521   GModule *module;
522 };
523
524 DirEntry *g_typelib_get_dir_entry (GTypelib *typelib,
525                                    guint16   index);
526
527 void      g_typelib_check_sanity (void);
528
529 #define   g_typelib_get_string(typelib,offset) ((const gchar*)&(typelib->data)[(offset)])
530
531
532 typedef enum
533 {
534   G_TYPELIB_ERROR_INVALID,
535   G_TYPELIB_ERROR_INVALID_HEADER,
536   G_TYPELIB_ERROR_INVALID_DIRECTORY,
537   G_TYPELIB_ERROR_INVALID_ENTRY,
538   G_TYPELIB_ERROR_INVALID_BLOB
539 } GTypelibError;
540
541 #define G_TYPELIB_ERROR (g_typelib_error_quark ())
542
543 GQuark g_typelib_error_quark (void);
544
545 gboolean g_typelib_validate (GTypelib  *typelib,
546                              GError    **error);
547
548
549 G_END_DECLS
550
551 #endif  /* __G_TYPELIB_H__ */
552