3 /* gras/datadesc.h - Describing the data you want to exchange */
5 /* Authors: Martin Quinson */
6 /* Copyright (C) 2003 the OURAGAN project. */
8 /* This program is free software; you can redistribute it and/or modify it
9 under the terms of the license (GNU LGPL) which comes with this package. */
11 #ifndef GRAS_DATADESC_H
12 #define GRAS_DATADESC_H
14 #include <stddef.h> /* offsetof() */
15 #include <sys/types.h> /* size_t */
19 /*! C++ users need love */
22 # define BEGIN_DECL extern "C" {
28 /*! C++ users need love */
36 /* End of cruft for C++ */
41 typedef struct s_gras_datadesc_type gras_datadesc_type_t;
43 /***********************************************
44 **** Search and retrieve declared datatype ****
45 ***********************************************/
46 long int gras_datadesc_get_id_from_name(const char *name);
48 gras_error_t gras_datadesc_by_name(const char *name,
49 gras_datadesc_type_t **type);
50 gras_error_t gras_datadesc_by_id (long int code,
51 gras_datadesc_type_t **type);
52 #define gras_datadesc_by_code(a,b) gras_datadesc_by_id(a,b)
54 /*********************************************
55 **** DataDesc callback persistent states ****
56 *********************************************/
57 typedef struct s_gras_dd_cbps gras_dd_cbps_t;
60 gras_dd_cbps_pop (gras_dd_cbps_t *ps,
62 gras_datadesc_type_t **ddt);
64 gras_dd_cbps_push(gras_dd_cbps_t *ps,
67 gras_datadesc_type_t *ddt);
69 gras_dd_cbps_set (gras_dd_cbps_t *ps,
72 gras_datadesc_type_t *ddt);
75 gras_dd_cbps_get (gras_dd_cbps_t *ps,
77 gras_datadesc_type_t **ddt);
80 gras_dd_cbps_block_begin(gras_dd_cbps_t *ps);
82 gras_dd_cbps_block_end(gras_dd_cbps_t *ps);
85 /******************************************
86 **** Declare datadescription manually ****
87 ******************************************/
89 typedef void (*gras_datadesc_type_cb_void_t)(void *vars,
90 gras_datadesc_type_t *p_type,
92 typedef int (*gras_datadesc_type_cb_int_t)(void *vars,
93 gras_datadesc_type_t *p_type,
98 /* Create a new type and register it on the local machine */
99 #define gras_datadesc_declare_struct( name, code) \
100 gras_datadesc_declare_struct_cb(name, NULL, NULL, code)
102 #define gras_datadesc_declare_struct_add_name( struct_code,field_name,field_type_name) \
103 gras_datadesc_declare_struct_add_name_cb(struct_code,field_name,field_type_name, NULL, NULL)
105 #define gras_datadesc_declare_struct_add_code( struct_code,field_name,field_type_code) \
106 gras_datadesc_declare_struct_add_code_cb(struct_code,field_name,field_type_code, NULL, NULL)
109 gras_datadesc_declare_struct_cb(const char *name,
110 gras_datadesc_type_cb_void_t pre_cb,
111 gras_datadesc_type_cb_void_t post_cb,
114 gras_datadesc_declare_struct_add_name_cb(long int struct_code,
115 const char *field_name,
116 const char *field_type_name,
117 gras_datadesc_type_cb_void_t pre_cb,
118 gras_datadesc_type_cb_void_t post_cb);
121 gras_datadesc_declare_struct_add_code_cb(long int struct_code,
122 const char *field_name,
124 gras_datadesc_type_cb_void_t pre_cb,
125 gras_datadesc_type_cb_void_t post_cb);
127 #define gras_datadesc_declare_union( name, code) \
128 gras_datadesc_declare_union_cb(name, NULL, NULL, code)
130 #define gras_datadesc_declare_union_add_name( union_code,field_name,field_type_name) \
131 gras_datadesc_declare_union_add_name_cb(union_code,field_name,field_type_name, NULL, NULL)
133 #define gras_datadesc_declare_union_add_code( union_code,field_name,field_type_code) \
134 gras_datadesc_declare_union_add_code_cb(union_code,field_name,field_type_code, NULL, NULL)
137 gras_datadesc_declare_union_cb(const char *name,
138 gras_datadesc_type_cb_int_t field_count,
139 gras_datadesc_type_cb_void_t post,
142 gras_datadesc_declare_union_add_name_cb(long int union_code,
143 const char *field_name,
144 const char *field_type_name,
145 gras_datadesc_type_cb_void_t pre_cb,
146 gras_datadesc_type_cb_void_t post_cb);
148 gras_datadesc_declare_union_add_code_cb(long int union_code,
149 const char *field_name,
151 gras_datadesc_type_cb_void_t pre_cb,
152 gras_datadesc_type_cb_void_t post_cb);
154 #define gras_datadesc_declare_ref(name,ref_type, code) \
155 gras_datadesc_declare_ref_cb(name, ref_type, NULL, NULL, code)
156 #define gras_datadesc_declare_ref_disc(name,discriminant, code) \
157 gras_datadesc_declare_ref_cb(name, NULL, discriminant, NULL, code)
160 gras_datadesc_declare_ref_cb(const char *name,
161 gras_datadesc_type_t *referenced_type,
162 gras_datadesc_type_cb_int_t discriminant,
163 gras_datadesc_type_cb_void_t post,
166 #define gras_datadesc_declare_array(name,elm_type, size, code) \
167 gras_datadesc_declare_array_cb(name, elm_type, size, NULL, NULL, code)
168 #define gras_datadesc_declare_array_dyn(name,elm_type, dynamic_size, code) \
169 gras_datadesc_declare_array_cb(name, elm_type, -1, dynamic_size, NULL, code)
172 gras_datadesc_declare_array_cb(const char *name,
173 gras_datadesc_type_t *element_type,
175 gras_datadesc_type_cb_int_t dynamic_size,
176 gras_datadesc_type_cb_void_t post,
179 /*******************************
180 **** About data convertion ****
181 *******************************/
182 int gras_arch_selfid(void); /* ID of this arch */
184 /****************************
185 **** Parse C statements ****
186 ****************************/
188 gras_datadesc_parse(const char *name,
189 const char *Cdefinition,
191 #define GRAS_DEFINE_TYPE(name,def) \
192 static const char * _gras_this_type_symbol_does_not_exist__##name=#def; def
194 #define gras_type_symbol_parse(bag,name) \
195 _gs_type_parse(bag, _gs_this_type_symbol_does_not_exist__##name)
197 #define gs_type_get_by_symbol(bag,name) \
198 (bag->bag_ops->get_type_by_name(bag, NULL, #name) ? \
199 bag->bag_ops->get_type_by_name(bag, NULL, #name) : \
200 gras_type_symbol_parse(bag, name) \
203 /*****************************
204 **** NWS datadescription ****
205 *****************************/
208 * Basic types we can embeed in DataDescriptors.
211 {CHAR_TYPE, DOUBLE_TYPE, FLOAT_TYPE, INT_TYPE, LONG_TYPE, SHORT_TYPE,
212 UNSIGNED_INT_TYPE, UNSIGNED_LONG_TYPE, UNSIGNED_SHORT_TYPE, STRUCT_TYPE}
214 #define SIMPLE_TYPE_COUNT 9
216 /*! \brief Describe a collection of data.
218 ** A description of a collection of #type# data. #repetitions# is used only
219 ** for arrays; it contains the number of elements. #offset# is used only for
220 ** struct members in host format; it contains the offset of the member from the
221 ** beginning of the struct, taking into account internal padding added by the
222 ** compiler for alignment purposes. #members#, #length#, and #tailPadding# are
223 ** used only for STRUCT_TYPE data; the #length#-long array #members# describes
224 ** the members of the nested struct, and #tailPadding# indicates how many
225 ** padding bytes the compiler adds to the end of the structure.
228 typedef struct DataDescriptorStruct {
232 /*@null@*/ struct DataDescriptorStruct *members;
236 /** DataDescriptor for an array */
237 #define SIMPLE_DATA(type,repetitions) \
238 {type, repetitions, 0, NULL, 0, 0}
239 /** DataDescriptor for an structure member */
240 #define SIMPLE_MEMBER(type,repetitions,offset) \
241 {type, repetitions, offset, NULL, 0, 0}
242 /** DataDescriptor for padding bytes */
243 #define PAD_BYTES(structType,lastMember,memberType,repetitions) \
244 sizeof(structType) - offsetof(structType, lastMember) - \
245 sizeof(memberType) * repetitions
248 gras_datadesc_from_nws(const char *name,
249 const DataDescriptor *desc,
256 #endif /* GRAS_DATADESC_H */