3 /* gras/datadesc.h - Describing the data you want to exchange */
5 /* Authors: Martin Quinson */
6 /* Copyright (C) 2003, 2004 Martin Quinson. */
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++ */
42 * gras_datadesc_type_t:
44 * Opaque type describing a type description you don't want to open.
46 typedef struct s_gras_datadesc_type gras_datadesc_type_t;
48 typedef struct s_gras_cbps gras_cbps_t;
50 /* callbacks prototypes */
51 typedef void (*gras_datadesc_type_cb_void_t)(gras_cbps_t *vars, void *data);
52 typedef int (*gras_datadesc_type_cb_int_t)(gras_cbps_t *vars, void *data);
53 typedef gras_datadesc_type_t *(*gras_datadesc_selector_t)(gras_cbps_t *vars, void *data);
55 /***********************************************
56 **** Search and retrieve declared datatype ****
57 ***********************************************/
58 gras_datadesc_type_t *gras_datadesc_by_name(const char *name);
60 /******************************************
61 **** Declare datadescription yourself ****
62 ******************************************/
65 gras_datadesc_struct(const char *name,
66 gras_datadesc_type_t **dst);
68 gras_datadesc_struct_append(gras_datadesc_type_t *struct_type,
70 gras_datadesc_type_t *field_type);
72 gras_datadesc_struct_close(gras_datadesc_type_t *struct_type);
74 gras_datadesc_union(const char *name,
75 gras_datadesc_type_cb_int_t selector,
76 gras_datadesc_type_t **dst);
78 gras_datadesc_union_append(gras_datadesc_type_t *union_type,
80 gras_datadesc_type_t *field_type);
82 gras_datadesc_union_close(gras_datadesc_type_t *union_type);
84 gras_datadesc_ref(const char *name,
85 gras_datadesc_type_t *referenced_type,
86 gras_datadesc_type_t **dst);
88 gras_datadesc_ref_generic(const char *name,
89 gras_datadesc_selector_t selector,
90 gras_datadesc_type_t **dst);
92 gras_datadesc_array_fixed(const char *name,
93 gras_datadesc_type_t *element_type,
95 gras_datadesc_type_t **dst);
97 gras_datadesc_array_dyn(const char *name,
98 gras_datadesc_type_t *element_type,
99 gras_datadesc_type_cb_int_t dynamic_size,
100 gras_datadesc_type_t **dst);
102 gras_datadesc_ref_pop_arr(gras_datadesc_type_t *element_type,
103 gras_datadesc_type_t **dst);
105 /*********************************
106 * Change stuff within datadescs *
107 *********************************/
109 void gras_datadesc_cb_send (gras_datadesc_type_t *type,
110 gras_datadesc_type_cb_void_t pre);
111 void gras_datadesc_cb_recv(gras_datadesc_type_t *type,
112 gras_datadesc_type_cb_void_t post);
113 void gras_datadesc_cb_field_send (gras_datadesc_type_t *type,
114 const char *field_name,
115 gras_datadesc_type_cb_void_t pre);
116 void gras_datadesc_cb_field_recv(gras_datadesc_type_t *type,
117 const char *field_name,
118 gras_datadesc_type_cb_void_t post);
119 void gras_datadesc_cb_field_push (gras_datadesc_type_t *type,
120 const char *field_name);
122 /******************************
123 * Get stuff within datadescs *
124 ******************************/
125 char * gras_datadesc_get_name(gras_datadesc_type_t *ddt);
126 int gras_datadesc_get_id(gras_datadesc_type_t *ddt);
128 /********************************************************
129 * Advanced data describing: callback persistent states *
130 ********************************************************/
131 /* simple one: push/pop sizes of arrays */
133 gras_cbps_i_push(gras_cbps_t *ps, int val);
135 gras_cbps_i_pop(gras_cbps_t *ps);
137 int gras_datadesc_cb_pop(gras_cbps_t *vars, void *data);
138 void gras_datadesc_cb_push_int(gras_cbps_t *vars, void *data);
139 void gras_datadesc_cb_push_uint(gras_cbps_t *vars, void *data);
140 void gras_datadesc_cb_push_lint(gras_cbps_t *vars, void *data);
141 void gras_datadesc_cb_push_ulint(gras_cbps_t *vars, void *data);
145 /* complex one: complete variable environment support */
147 gras_cbps_v_pop (gras_cbps_t *ps,
149 gras_datadesc_type_t **ddt,
152 gras_cbps_v_push(gras_cbps_t *ps,
155 gras_datadesc_type_t *ddt);
157 gras_cbps_v_set (gras_cbps_t *ps,
160 gras_datadesc_type_t *ddt);
163 gras_cbps_v_get (gras_cbps_t *ps,
165 gras_datadesc_type_t **ddt);
168 gras_cbps_block_begin(gras_cbps_t *ps);
170 gras_cbps_block_end(gras_cbps_t *ps);
175 /*******************************
176 **** About data convertion ****
177 *******************************/
178 int gras_arch_selfid(void); /* ID of this arch */
180 /****************************
181 **** Parse C statements ****
182 ****************************/
183 gras_datadesc_type_t *
184 gras_datadesc_parse(const char *name,
185 const char *Cdefinition);
186 #define GRAS_DEFINE_TYPE(name,def) \
187 static const char * _gras_this_type_symbol_does_not_exist__##name=#def; def
188 #define GRAS_ANNOTE(key,val)
190 #define gras_datadesc_by_symbol(name) \
191 (gras_datadesc_by_name(#name) ? \
192 gras_datadesc_by_name(#name) : \
193 gras_datadesc_parse(#name, \
194 _gras_this_type_symbol_does_not_exist__##name) \
197 /*****************************
198 **** NWS datadescription ****
199 *****************************/
202 * Basic types we can embeed in DataDescriptors.
205 {CHAR_TYPE, DOUBLE_TYPE, FLOAT_TYPE, INT_TYPE, LONG_TYPE, SHORT_TYPE,
206 UNSIGNED_INT_TYPE, UNSIGNED_LONG_TYPE, UNSIGNED_SHORT_TYPE, STRUCT_TYPE}
208 #define SIMPLE_TYPE_COUNT 9
210 /*! \brief Describe a collection of data.
212 ** A description of a collection of #type# data. #repetitions# is used only
213 ** for arrays; it contains the number of elements. #offset# is used only for
214 ** struct members in host format; it contains the offset of the member from the
215 ** beginning of the struct, taking into account internal padding added by the
216 ** compiler for alignment purposes. #members#, #length#, and #tailPadding# are
217 ** used only for STRUCT_TYPE data; the #length#-long array #members# describes
218 ** the members of the nested struct, and #tailPadding# indicates how many
219 ** padding bytes the compiler adds to the end of the structure.
222 typedef struct DataDescriptorStruct {
226 /*@null@*/ struct DataDescriptorStruct *members;
230 /** DataDescriptor for an array */
231 #define SIMPLE_DATA(type,repetitions) \
232 {type, repetitions, 0, NULL, 0, 0}
233 /** DataDescriptor for an structure member */
234 #define SIMPLE_MEMBER(type,repetitions,offset) \
235 {type, repetitions, offset, NULL, 0, 0}
236 /** DataDescriptor for padding bytes */
237 #define PAD_BYTES(structType,lastMember,memberType,repetitions) \
238 sizeof(structType) - offsetof(structType, lastMember) - \
239 sizeof(memberType) * repetitions
242 gras_datadesc_import_nws(const char *name,
243 const DataDescriptor *desc,
245 gras_datadesc_type_t **dst);
249 #endif /* GRAS_DATADESC_H */