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 */
18 #include "xbt/misc.h" /* BEGIN_DECL */
23 * gras_datadesc_type_t:
25 * Opaque type describing a type description you don't want to open.
27 typedef struct s_gras_datadesc_type gras_datadesc_type_t;
29 typedef struct s_gras_cbps gras_cbps_t;
31 /* callbacks prototypes */
32 typedef void (*gras_datadesc_type_cb_void_t)(gras_cbps_t *vars, void *data);
33 typedef int (*gras_datadesc_type_cb_int_t)(gras_cbps_t *vars, void *data);
34 typedef gras_datadesc_type_t *(*gras_datadesc_selector_t)(gras_cbps_t *vars, void *data);
36 /***********************************************
37 **** Search and retrieve declared datatype ****
38 ***********************************************/
39 gras_datadesc_type_t *gras_datadesc_by_name(const char *name);
41 /******************************************
42 **** Declare datadescription yourself ****
43 ******************************************/
45 gras_datadesc_type_t *
46 gras_datadesc_struct(const char *name);
49 gras_datadesc_struct_append(gras_datadesc_type_t *struct_type,
51 gras_datadesc_type_t *field_type);
53 gras_datadesc_struct_close(gras_datadesc_type_t *struct_type);
55 gras_datadesc_type_t *
56 gras_datadesc_union(const char *name,
57 gras_datadesc_type_cb_int_t selector);
59 gras_datadesc_union_append(gras_datadesc_type_t *union_type,
61 gras_datadesc_type_t *field_type);
63 gras_datadesc_union_close(gras_datadesc_type_t *union_type);
65 gras_datadesc_type_t *
66 gras_datadesc_ref(const char *name,
67 gras_datadesc_type_t *referenced_type);
68 gras_datadesc_type_t *
69 gras_datadesc_ref_generic(const char *name,
70 gras_datadesc_selector_t selector);
72 gras_datadesc_type_t *
73 gras_datadesc_array_fixed(const char *name,
74 gras_datadesc_type_t *element_type,
76 gras_datadesc_type_t *
77 gras_datadesc_array_dyn(const char *name,
78 gras_datadesc_type_t *element_type,
79 gras_datadesc_type_cb_int_t dynamic_size);
81 gras_datadesc_type_t *
82 gras_datadesc_ref_pop_arr(gras_datadesc_type_t *element_type);
84 /*********************************
85 * Change stuff within datadescs *
86 *********************************/
88 void gras_datadesc_cycle_set(gras_datadesc_type_t *type);
89 void gras_datadesc_cycle_unset(gras_datadesc_type_t *type);
91 void gras_datadesc_cb_send (gras_datadesc_type_t *type,
92 gras_datadesc_type_cb_void_t pre);
93 void gras_datadesc_cb_recv(gras_datadesc_type_t *type,
94 gras_datadesc_type_cb_void_t post);
95 void gras_datadesc_cb_field_send (gras_datadesc_type_t *type,
96 const char *field_name,
97 gras_datadesc_type_cb_void_t pre);
98 void gras_datadesc_cb_field_recv(gras_datadesc_type_t *type,
99 const char *field_name,
100 gras_datadesc_type_cb_void_t post);
101 void gras_datadesc_cb_field_push (gras_datadesc_type_t *type,
102 const char *field_name);
104 /******************************
105 * Get stuff within datadescs *
106 ******************************/
107 char * gras_datadesc_get_name(gras_datadesc_type_t *ddt);
108 int gras_datadesc_get_id(gras_datadesc_type_t *ddt);
110 /********************************************************
111 * Advanced data describing: callback persistent states *
112 ********************************************************/
113 /* simple one: push/pop sizes of arrays */
115 gras_cbps_i_push(gras_cbps_t *ps, int val);
117 gras_cbps_i_pop(gras_cbps_t *ps);
119 int gras_datadesc_cb_pop(gras_cbps_t *vars, void *data);
120 void gras_datadesc_cb_push_int(gras_cbps_t *vars, void *data);
121 void gras_datadesc_cb_push_uint(gras_cbps_t *vars, void *data);
122 void gras_datadesc_cb_push_lint(gras_cbps_t *vars, void *data);
123 void gras_datadesc_cb_push_ulint(gras_cbps_t *vars, void *data);
127 /* complex one: complete variable environment support */
129 gras_cbps_v_pop (gras_cbps_t *ps,
131 gras_datadesc_type_t **ddt,
134 gras_cbps_v_push(gras_cbps_t *ps,
137 gras_datadesc_type_t *ddt);
139 gras_cbps_v_set (gras_cbps_t *ps,
142 gras_datadesc_type_t *ddt);
145 gras_cbps_v_get (gras_cbps_t *ps,
147 gras_datadesc_type_t **ddt);
150 gras_cbps_block_begin(gras_cbps_t *ps);
152 gras_cbps_block_end(gras_cbps_t *ps);
157 /*******************************
158 **** About data convertion ****
159 *******************************/
160 int gras_arch_selfid(void); /* ID of this arch */
162 /****************************
163 **** Parse C statements ****
164 ****************************/
165 gras_datadesc_type_t *
166 gras_datadesc_parse(const char *name,
167 const char *Cdefinition);
168 #define GRAS_DEFINE_TYPE(name,def) \
169 static const char * _gras_this_type_symbol_does_not_exist__##name=#def; def
170 #define GRAS_ANNOTE(key,val)
172 #define gras_datadesc_by_symbol(name) \
173 (gras_datadesc_by_name(#name) ? \
174 gras_datadesc_by_name(#name) : \
175 gras_datadesc_parse(#name, \
176 _gras_this_type_symbol_does_not_exist__##name) \
179 /*****************************
180 **** NWS datadescription ****
181 *****************************/
184 * Basic types we can embeed in DataDescriptors.
187 {CHAR_TYPE, DOUBLE_TYPE, FLOAT_TYPE, INT_TYPE, LONG_TYPE, SHORT_TYPE,
188 UNSIGNED_INT_TYPE, UNSIGNED_LONG_TYPE, UNSIGNED_SHORT_TYPE, STRUCT_TYPE}
190 #define SIMPLE_TYPE_COUNT 9
192 /*! \brief Describe a collection of data.
194 ** A description of a collection of #type# data. #repetitions# is used only
195 ** for arrays; it contains the number of elements. #offset# is used only for
196 ** struct members in host format; it contains the offset of the member from the
197 ** beginning of the struct, taking into account internal padding added by the
198 ** compiler for alignment purposes. #members#, #length#, and #tailPadding# are
199 ** used only for STRUCT_TYPE data; the #length#-long array #members# describes
200 ** the members of the nested struct, and #tailPadding# indicates how many
201 ** padding bytes the compiler adds to the end of the structure.
204 typedef struct DataDescriptorStruct {
208 /*@null@*/ struct DataDescriptorStruct *members;
212 /** DataDescriptor for an array */
213 #define SIMPLE_DATA(type,repetitions) \
214 {type, repetitions, 0, NULL, 0, 0}
215 /** DataDescriptor for an structure member */
216 #define SIMPLE_MEMBER(type,repetitions,offset) \
217 {type, repetitions, offset, NULL, 0, 0}
218 /** DataDescriptor for padding bytes */
219 #define PAD_BYTES(structType,lastMember,memberType,repetitions) \
220 sizeof(structType) - offsetof(structType, lastMember) - \
221 sizeof(memberType) * repetitions
224 gras_datadesc_import_nws(const char *name,
225 const DataDescriptor *desc,
227 gras_datadesc_type_t **dst);
231 #endif /* GRAS_DATADESC_H */