3 /* gras/datadesc.h - Describing the data you want to exchange */
5 /* Copyright (c) 2003, 2004 Martin Quinson. All rights reserved. */
7 /* This program is free software; you can redistribute it and/or modify it
8 * under the terms of the license (GNU LGPL) which comes with this package. */
10 #ifndef GRAS_DATADESC_H
11 #define GRAS_DATADESC_H
13 #include "xbt/misc.h" /* BEGIN_DECL */
18 * gras_datadesc_type_t:
20 * Opaque type describing a type description you don't want to open.
22 typedef struct s_gras_datadesc_type *gras_datadesc_type_t;
24 typedef struct s_gras_cbps *gras_cbps_t;
26 /* callbacks prototypes */
27 typedef void (*gras_datadesc_type_cb_void_t)(gras_cbps_t vars, void *data);
28 typedef int (*gras_datadesc_type_cb_int_t)(gras_cbps_t vars, void *data);
29 typedef gras_datadesc_type_t (*gras_datadesc_selector_t)(gras_cbps_t vars, void *data);
31 /***********************************************
32 **** Search and retrieve declared datatype ****
33 ***********************************************/
34 gras_datadesc_type_t gras_datadesc_by_name(const char *name);
36 /******************************************
37 **** Declare datadescription yourself ****
38 ******************************************/
40 gras_datadesc_type_t gras_datadesc_struct(const char *name);
43 gras_datadesc_struct_append(gras_datadesc_type_t struct_type,
45 gras_datadesc_type_t field_type);
47 gras_datadesc_struct_close(gras_datadesc_type_t struct_type);
50 gras_datadesc_union(const char *name,
51 gras_datadesc_type_cb_int_t selector);
53 gras_datadesc_union_append(gras_datadesc_type_t union_type,
55 gras_datadesc_type_t field_type);
57 gras_datadesc_union_close(gras_datadesc_type_t union_type);
60 gras_datadesc_ref(const char *name,
61 gras_datadesc_type_t referenced_type);
63 gras_datadesc_ref_generic(const char *name,
64 gras_datadesc_selector_t selector);
67 gras_datadesc_array_fixed(const char *name,
68 gras_datadesc_type_t element_type,
71 gras_datadesc_array_dyn(const char *name,
72 gras_datadesc_type_t element_type,
73 gras_datadesc_type_cb_int_t dynamic_size);
76 gras_datadesc_ref_pop_arr(gras_datadesc_type_t element_type);
78 /*********************************
79 * Change stuff within datadescs *
80 *********************************/
82 void gras_datadesc_cycle_set(gras_datadesc_type_t type);
83 void gras_datadesc_cycle_unset(gras_datadesc_type_t type);
85 void gras_datadesc_cb_send (gras_datadesc_type_t type,
86 gras_datadesc_type_cb_void_t pre);
87 void gras_datadesc_cb_recv(gras_datadesc_type_t type,
88 gras_datadesc_type_cb_void_t post);
89 void gras_datadesc_cb_field_send (gras_datadesc_type_t type,
90 const char *field_name,
91 gras_datadesc_type_cb_void_t pre);
92 void gras_datadesc_cb_field_recv(gras_datadesc_type_t type,
93 const char *field_name,
94 gras_datadesc_type_cb_void_t post);
95 void gras_datadesc_cb_field_push (gras_datadesc_type_t type,
96 const char *field_name);
98 /******************************
99 * Get stuff within datadescs *
100 ******************************/
101 char * gras_datadesc_get_name(gras_datadesc_type_t ddt);
102 int gras_datadesc_get_id(gras_datadesc_type_t ddt);
104 /********************************************************
105 * Advanced data describing: callback persistent states *
106 ********************************************************/
107 /* simple one: push/pop sizes of arrays */
109 gras_cbps_i_push(gras_cbps_t ps, int val);
111 gras_cbps_i_pop(gras_cbps_t ps);
113 int gras_datadesc_cb_pop(gras_cbps_t vars, void *data);
114 void gras_datadesc_cb_push_int(gras_cbps_t vars, void *data);
115 void gras_datadesc_cb_push_uint(gras_cbps_t vars, void *data);
116 void gras_datadesc_cb_push_lint(gras_cbps_t vars, void *data);
117 void gras_datadesc_cb_push_ulint(gras_cbps_t vars, void *data);
121 /* complex one: complete variable environment support */
123 gras_cbps_v_pop (gras_cbps_t ps,
125 /* OUT */ gras_datadesc_type_t *ddt,
126 /* OUT */ void **res);
128 gras_cbps_v_push(gras_cbps_t ps,
131 gras_datadesc_type_t ddt);
133 gras_cbps_v_set (gras_cbps_t ps,
136 gras_datadesc_type_t ddt);
139 gras_cbps_v_get (gras_cbps_t ps,
141 /* OUT */ gras_datadesc_type_t *ddt);
144 gras_cbps_block_begin(gras_cbps_t ps);
146 gras_cbps_block_end(gras_cbps_t ps);
151 /*******************************
152 **** About data convertion ****
153 *******************************/
154 int gras_arch_selfid(void); /* ID of this arch */
156 /****************************
157 **** Parse C statements ****
158 ****************************/
160 gras_datadesc_parse(const char *name,
161 const char *Cdefinition);
162 #define GRAS_DEFINE_TYPE(name,def) \
163 static const char * _gras_this_type_symbol_does_not_exist__##name=#def; def
164 #define GRAS_ANNOTE(key,val)
166 #define gras_datadesc_by_symbol(name) \
167 (gras_datadesc_by_name(#name) ? \
168 gras_datadesc_by_name(#name) : \
169 gras_datadesc_parse(#name, \
170 _gras_this_type_symbol_does_not_exist__##name) \
173 /*****************************
174 **** NWS datadescription ****
175 *****************************/
178 * Basic types we can embeed in DataDescriptors.
181 {CHAR_TYPE, DOUBLE_TYPE, FLOAT_TYPE, INT_TYPE, LONG_TYPE, SHORT_TYPE,
182 UNSIGNED_INT_TYPE, UNSIGNED_LONG_TYPE, UNSIGNED_SHORT_TYPE, STRUCT_TYPE}
184 #define SIMPLE_TYPE_COUNT 9
186 /*! \brief Describe a collection of data.
188 ** A description of a collection of #type# data. #repetitions# is used only
189 ** for arrays; it contains the number of elements. #offset# is used only for
190 ** struct members in host format; it contains the offset of the member from the
191 ** beginning of the struct, taking into account internal padding added by the
192 ** compiler for alignment purposes. #members#, #length#, and #tailPadding# are
193 ** used only for STRUCT_TYPE data; the #length#-long array #members# describes
194 ** the members of the nested struct, and #tailPadding# indicates how many
195 ** padding bytes the compiler adds to the end of the structure.
198 typedef struct DataDescriptorStruct {
202 /*@null@*/ struct DataDescriptorStruct *members;
206 /** DataDescriptor for an array */
207 #define SIMPLE_DATA(type,repetitions) \
208 {type, repetitions, 0, NULL, 0, 0}
209 /** DataDescriptor for an structure member */
210 #define SIMPLE_MEMBER(type,repetitions,offset) \
211 {type, repetitions, offset, NULL, 0, 0}
212 /** DataDescriptor for padding bytes */
213 #define PAD_BYTES(structType,lastMember,memberType,repetitions) \
214 sizeof(structType) - offsetof(structType, lastMember) - \
215 sizeof(memberType) * repetitions
218 gras_datadesc_import_nws(const char *name,
219 const DataDescriptor *desc,
220 unsigned long howmany,
221 /* OUT */ gras_datadesc_type_t *dst);
225 #endif /* GRAS_DATADESC_H */