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 "xbt/misc.h" /* BEGIN_DECL */
19 * gras_datadesc_type_t:
21 * Opaque type describing a type description you don't want to open.
23 typedef struct s_gras_datadesc_type *gras_datadesc_type_t;
25 typedef struct s_gras_cbps *gras_cbps_t;
27 /* callbacks prototypes */
28 typedef void (*gras_datadesc_type_cb_void_t)(gras_cbps_t vars, void *data);
29 typedef int (*gras_datadesc_type_cb_int_t)(gras_cbps_t vars, void *data);
30 typedef gras_datadesc_type_t (*gras_datadesc_selector_t)(gras_cbps_t vars, void *data);
32 /***********************************************
33 **** Search and retrieve declared datatype ****
34 ***********************************************/
35 gras_datadesc_type_t gras_datadesc_by_name(const char *name);
37 /******************************************
38 **** Declare datadescription yourself ****
39 ******************************************/
41 gras_datadesc_type_t gras_datadesc_struct(const char *name);
44 gras_datadesc_struct_append(gras_datadesc_type_t struct_type,
46 gras_datadesc_type_t field_type);
48 gras_datadesc_struct_close(gras_datadesc_type_t struct_type);
51 gras_datadesc_union(const char *name,
52 gras_datadesc_type_cb_int_t selector);
54 gras_datadesc_union_append(gras_datadesc_type_t union_type,
56 gras_datadesc_type_t field_type);
58 gras_datadesc_union_close(gras_datadesc_type_t union_type);
61 gras_datadesc_ref(const char *name,
62 gras_datadesc_type_t referenced_type);
64 gras_datadesc_ref_generic(const char *name,
65 gras_datadesc_selector_t selector);
68 gras_datadesc_array_fixed(const char *name,
69 gras_datadesc_type_t element_type,
72 gras_datadesc_array_dyn(const char *name,
73 gras_datadesc_type_t element_type,
74 gras_datadesc_type_cb_int_t dynamic_size);
77 gras_datadesc_ref_pop_arr(gras_datadesc_type_t element_type);
79 /*********************************
80 * Change stuff within datadescs *
81 *********************************/
83 void gras_datadesc_cycle_set(gras_datadesc_type_t type);
84 void gras_datadesc_cycle_unset(gras_datadesc_type_t type);
86 void gras_datadesc_cb_send (gras_datadesc_type_t type,
87 gras_datadesc_type_cb_void_t pre);
88 void gras_datadesc_cb_recv(gras_datadesc_type_t type,
89 gras_datadesc_type_cb_void_t post);
90 void gras_datadesc_cb_field_send (gras_datadesc_type_t type,
91 const char *field_name,
92 gras_datadesc_type_cb_void_t pre);
93 void gras_datadesc_cb_field_recv(gras_datadesc_type_t type,
94 const char *field_name,
95 gras_datadesc_type_cb_void_t post);
96 void gras_datadesc_cb_field_push (gras_datadesc_type_t type,
97 const char *field_name);
99 /******************************
100 * Get stuff within datadescs *
101 ******************************/
102 char * gras_datadesc_get_name(gras_datadesc_type_t ddt);
103 int gras_datadesc_get_id(gras_datadesc_type_t ddt);
105 /********************************************************
106 * Advanced data describing: callback persistent states *
107 ********************************************************/
108 /* simple one: push/pop sizes of arrays */
110 gras_cbps_i_push(gras_cbps_t ps, int val);
112 gras_cbps_i_pop(gras_cbps_t ps);
114 int gras_datadesc_cb_pop(gras_cbps_t vars, void *data);
115 void gras_datadesc_cb_push_int(gras_cbps_t vars, void *data);
116 void gras_datadesc_cb_push_uint(gras_cbps_t vars, void *data);
117 void gras_datadesc_cb_push_lint(gras_cbps_t vars, void *data);
118 void gras_datadesc_cb_push_ulint(gras_cbps_t vars, void *data);
122 /* complex one: complete variable environment support */
124 gras_cbps_v_pop (gras_cbps_t ps,
126 /* OUT */ gras_datadesc_type_t *ddt,
127 /* OUT */ void **res);
129 gras_cbps_v_push(gras_cbps_t ps,
132 gras_datadesc_type_t ddt);
134 gras_cbps_v_set (gras_cbps_t ps,
137 gras_datadesc_type_t ddt);
140 gras_cbps_v_get (gras_cbps_t ps,
142 /* OUT */ gras_datadesc_type_t *ddt);
145 gras_cbps_block_begin(gras_cbps_t ps);
147 gras_cbps_block_end(gras_cbps_t ps);
152 /*******************************
153 **** About data convertion ****
154 *******************************/
155 int gras_arch_selfid(void); /* ID of this arch */
157 /****************************
158 **** Parse C statements ****
159 ****************************/
161 gras_datadesc_parse(const char *name,
162 const char *Cdefinition);
163 #define GRAS_DEFINE_TYPE(name,def) \
164 static const char * _gras_this_type_symbol_does_not_exist__##name=#def; def
165 #define GRAS_ANNOTE(key,val)
167 #define gras_datadesc_by_symbol(name) \
168 (gras_datadesc_by_name(#name) ? \
169 gras_datadesc_by_name(#name) : \
170 gras_datadesc_parse(#name, \
171 _gras_this_type_symbol_does_not_exist__##name) \
174 /*****************************
175 **** NWS datadescription ****
176 *****************************/
179 * Basic types we can embeed in DataDescriptors.
182 {CHAR_TYPE, DOUBLE_TYPE, FLOAT_TYPE, INT_TYPE, LONG_TYPE, SHORT_TYPE,
183 UNSIGNED_INT_TYPE, UNSIGNED_LONG_TYPE, UNSIGNED_SHORT_TYPE, STRUCT_TYPE}
185 #define SIMPLE_TYPE_COUNT 9
187 /*! \brief Describe a collection of data.
189 ** A description of a collection of #type# data. #repetitions# is used only
190 ** for arrays; it contains the number of elements. #offset# is used only for
191 ** struct members in host format; it contains the offset of the member from the
192 ** beginning of the struct, taking into account internal padding added by the
193 ** compiler for alignment purposes. #members#, #length#, and #tailPadding# are
194 ** used only for STRUCT_TYPE data; the #length#-long array #members# describes
195 ** the members of the nested struct, and #tailPadding# indicates how many
196 ** padding bytes the compiler adds to the end of the structure.
199 typedef struct DataDescriptorStruct {
203 /*@null@*/ struct DataDescriptorStruct *members;
207 /** DataDescriptor for an array */
208 #define SIMPLE_DATA(type,repetitions) \
209 {type, repetitions, 0, NULL, 0, 0}
210 /** DataDescriptor for an structure member */
211 #define SIMPLE_MEMBER(type,repetitions,offset) \
212 {type, repetitions, offset, NULL, 0, 0}
213 /** DataDescriptor for padding bytes */
214 #define PAD_BYTES(structType,lastMember,memberType,repetitions) \
215 sizeof(structType) - offsetof(structType, lastMember) - \
216 sizeof(memberType) * repetitions
219 gras_datadesc_import_nws(const char *name,
220 const DataDescriptor *desc,
221 unsigned long howmany,
222 /* OUT */ gras_datadesc_type_t *dst);
226 #endif /* GRAS_DATADESC_H */