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);
54 /***********************************************
55 **** Search and retrieve declared datatype ****
56 ***********************************************/
57 gras_datadesc_type_t *gras_datadesc_by_name(const char *name);
59 /******************************************
60 **** Declare datadescription yourself ****
61 ******************************************/
64 gras_datadesc_struct(const char *name,
65 gras_datadesc_type_t **dst);
67 gras_datadesc_struct_append(gras_datadesc_type_t *struct_type,
69 gras_datadesc_type_t *field_type);
71 gras_datadesc_struct_close(gras_datadesc_type_t *struct_type);
73 gras_datadesc_union(const char *name,
74 gras_datadesc_type_cb_int_t selector,
75 gras_datadesc_type_t **dst);
77 gras_datadesc_union_append(gras_datadesc_type_t *union_type,
79 gras_datadesc_type_t *field_type);
81 gras_datadesc_union_close(gras_datadesc_type_t *union_type);
83 gras_datadesc_ref(const char *name,
84 gras_datadesc_type_t *referenced_type,
85 gras_datadesc_type_t **dst);
87 gras_datadesc_ref_generic(const char *name,
88 gras_datadesc_type_cb_int_t discriminant,
89 gras_datadesc_type_t **dst);
91 gras_datadesc_array_fixed(const char *name,
92 gras_datadesc_type_t *element_type,
94 gras_datadesc_type_t **dst);
96 gras_datadesc_array_dyn(const char *name,
97 gras_datadesc_type_t *element_type,
98 gras_datadesc_type_cb_int_t dynamic_size,
99 gras_datadesc_type_t **dst);
101 gras_datadesc_ref_pop_arr(gras_datadesc_type_t *element_type,
102 gras_datadesc_type_t **dst);
104 /*********************************
105 * Change stuff within datadescs *
106 *********************************/
108 void gras_datadesc_cb_send (gras_datadesc_type_t *type,
109 gras_datadesc_type_cb_void_t pre);
110 void gras_datadesc_cb_recv(gras_datadesc_type_t *type,
111 gras_datadesc_type_cb_void_t post);
113 /******************************
114 * Get stuff within datadescs *
115 ******************************/
116 char * gras_datadesc_get_name(gras_datadesc_type_t *ddt);
117 int gras_datadesc_get_id(gras_datadesc_type_t *ddt);
119 /********************************************************
120 * Advanced data describing: callback persistent states *
121 ********************************************************/
122 /* simple one: push/pop sizes of arrays */
124 gras_cbps_i_push(gras_cbps_t *ps, int val);
126 gras_cbps_i_pop(gras_cbps_t *ps);
127 int gras_datadesc_cb_pop(gras_cbps_t *vars, void *data);
129 /* complex one: complete variable environment support */
131 gras_cbps_v_pop (gras_cbps_t *ps,
133 gras_datadesc_type_t **ddt,
136 gras_cbps_v_push(gras_cbps_t *ps,
139 gras_datadesc_type_t *ddt);
141 gras_cbps_v_set (gras_cbps_t *ps,
144 gras_datadesc_type_t *ddt);
147 gras_cbps_v_get (gras_cbps_t *ps,
149 gras_datadesc_type_t **ddt);
152 gras_cbps_block_begin(gras_cbps_t *ps);
154 gras_cbps_block_end(gras_cbps_t *ps);
159 /*******************************
160 **** About data convertion ****
161 *******************************/
162 int gras_arch_selfid(void); /* ID of this arch */
164 /****************************
165 **** Parse C statements ****
166 ****************************/
167 gras_datadesc_type_t *
168 gras_datadesc_parse(const char *name,
169 const char *Cdefinition);
170 #define GRAS_DEFINE_TYPE(name,def) \
171 static const char * _gras_this_type_symbol_does_not_exist__##name=#def; def
173 #define gras_datadesc_by_symbol(name) \
174 (gras_datadesc_by_name(#name) ? \
175 gras_datadesc_by_name(#name) : \
176 gras_datadesc_parse(#name, \
177 _gras_this_type_symbol_does_not_exist__##name) \
180 /*****************************
181 **** NWS datadescription ****
182 *****************************/
185 * Basic types we can embeed in DataDescriptors.
188 {CHAR_TYPE, DOUBLE_TYPE, FLOAT_TYPE, INT_TYPE, LONG_TYPE, SHORT_TYPE,
189 UNSIGNED_INT_TYPE, UNSIGNED_LONG_TYPE, UNSIGNED_SHORT_TYPE, STRUCT_TYPE}
191 #define SIMPLE_TYPE_COUNT 9
193 /*! \brief Describe a collection of data.
195 ** A description of a collection of #type# data. #repetitions# is used only
196 ** for arrays; it contains the number of elements. #offset# is used only for
197 ** struct members in host format; it contains the offset of the member from the
198 ** beginning of the struct, taking into account internal padding added by the
199 ** compiler for alignment purposes. #members#, #length#, and #tailPadding# are
200 ** used only for STRUCT_TYPE data; the #length#-long array #members# describes
201 ** the members of the nested struct, and #tailPadding# indicates how many
202 ** padding bytes the compiler adds to the end of the structure.
205 typedef struct DataDescriptorStruct {
209 /*@null@*/ struct DataDescriptorStruct *members;
213 /** DataDescriptor for an array */
214 #define SIMPLE_DATA(type,repetitions) \
215 {type, repetitions, 0, NULL, 0, 0}
216 /** DataDescriptor for an structure member */
217 #define SIMPLE_MEMBER(type,repetitions,offset) \
218 {type, repetitions, offset, NULL, 0, 0}
219 /** DataDescriptor for padding bytes */
220 #define PAD_BYTES(structType,lastMember,memberType,repetitions) \
221 sizeof(structType) - offsetof(structType, lastMember) - \
222 sizeof(memberType) * repetitions
225 gras_datadesc_import_nws(const char *name,
226 const DataDescriptor *desc,
228 gras_datadesc_type_t **dst);
232 #endif /* GRAS_DATADESC_H */