3 /* datadesc - describing the data to exchange */
5 /* module's private interface masked even to other parts of GRAS. */
7 /* Copyright (c) 2003 Olivier Aumage. */
8 /* Copyright (c) 2003, 2004 Martin Quinson. */
9 /* All rights reserved. */
11 /* This program is free software; you can redistribute it and/or modify it
12 * under the terms of the license (GNU LGPL) which comes with this package. */
14 #ifndef GRAS_DATADESC_PRIVATE_H
15 #define GRAS_DATADESC_PRIVATE_H
17 #include "xbt/sysdep.h"
19 #include "xbt/error.h"
20 #include "xbt/dynar.h"
24 #include "gras_config.h" /* GRAS_THISARCH */
26 #include "gras/transport.h" /* socket handling */
28 #include "gras_modinter.h" /* module init/exit */
29 #include "gras/datadesc.h" /* rest of module public interface */
31 #include "gras/DataDesc/datadesc_interface.h" /* semi-public API */
36 * Align the data v on the boundary a.
38 #define aligned(v, a) (((v) + (a - 1)) & ~(a - 1))
40 /*@null@*/extern xbt_set_t gras_datadesc_set_local;
41 void gras_ddt_freev(void *ddt);
42 /*******************************************
43 * Descriptions of all known architectures *
44 *******************************************/
46 #define gras_arch_count 8
48 gras_ddt_scalar_char = 0,
49 gras_ddt_scalar_short = 1,
50 gras_ddt_scalar_int = 2,
51 gras_ddt_scalar_long = 3,
52 gras_ddt_scalar_long_long = 4,
54 gras_ddt_scalar_pdata = 5,
55 gras_ddt_scalar_pfunc = 6,
57 gras_ddt_scalar_float = 7,
58 gras_ddt_scalar_double = 8
59 } gras_ddt_scalar_type_t;
66 int sizeofs[9]; /* char,short,int,long,long_long,
69 int boundaries[9]; /* idem */
72 extern const gras_arch_desc_t gras_arches[gras_arch_count];
73 extern const char *gras_datadesc_cat_names[9];
75 /**********************************************************/
76 /* Actual definitions of the stuff in the type descriptor */
77 /**********************************************************/
80 * e_gras_datadesc_type_category:
82 * Defines all possible type categories.
84 typedef enum e_gras_datadesc_type_category {
86 /* if you edit this, also fix gras_datadesc_cat_names in ddt_exchange.c */
88 e_gras_datadesc_type_cat_undefined = 0,
90 e_gras_datadesc_type_cat_scalar = 1,
91 e_gras_datadesc_type_cat_struct = 2,
92 e_gras_datadesc_type_cat_union = 3,
93 e_gras_datadesc_type_cat_ref = 4, /* ref to an uniq element */
94 e_gras_datadesc_type_cat_array = 5,
95 e_gras_datadesc_type_cat_ignored = 6,
97 e_gras_datadesc_type_cat_invalid = 7
98 } gras_datadesc_type_category_t;
100 /*------------------------------------------------*/
101 /* definitions of specific data for each category */
102 /*------------------------------------------------*/
104 * s_gras_dd_cat_field:
106 * Fields of struct and union
108 typedef struct s_gras_dd_cat_field {
111 long int offset[gras_arch_count];
112 gras_datadesc_type_t type;
114 gras_datadesc_type_cb_void_t pre;
115 gras_datadesc_type_cb_void_t post;
117 } s_gras_dd_cat_field_t,*gras_dd_cat_field_t;
119 void gras_dd_cat_field_free(void *f);
122 * gras_dd_cat_scalar_t:
124 * Specific fields of a scalar
126 enum e_gras_dd_scalar_encoding {
127 e_gras_dd_scalar_encoding_undefined = 0,
129 e_gras_dd_scalar_encoding_uint,
130 e_gras_dd_scalar_encoding_sint,
131 e_gras_dd_scalar_encoding_float,
133 e_gras_dd_scalar_encoding_invalid
135 typedef struct s_gras_dd_cat_scalar {
136 enum e_gras_dd_scalar_encoding encoding;
137 gras_ddt_scalar_type_t type; /* to check easily that redefinition matches*/
138 } gras_dd_cat_scalar_t;
141 * gras_dd_cat_struct_t:
143 * Specific fields of a struct
145 typedef struct s_gras_dd_cat_struct {
146 xbt_dynar_t fields; /* elm type = gras_dd_cat_field_t */
147 int closed; /* gras_datadesc_declare_struct_close() was called */
148 } gras_dd_cat_struct_t;
151 * gras_dd_cat_union_t:
153 * Specific fields of a union
155 typedef struct s_gras_dd_cat_union {
156 gras_datadesc_type_cb_int_t selector;
157 xbt_dynar_t fields; /* elm type = gras_dd_cat_field_t */
158 int closed; /* gras_datadesc_declare_union_close() was called */
159 } gras_dd_cat_union_t;
164 * Specific fields of a reference
166 typedef struct s_gras_dd_cat_ref {
167 gras_datadesc_type_t type;
169 /* callback used to return the referenced type number */
170 gras_datadesc_selector_t selector;
175 * gras_dd_cat_array_t:
177 * Specific fields of an array
179 typedef struct s_gras_dd_cat_array {
180 gras_datadesc_type_t type;
182 /* element_count == 0 means dynamically defined */
183 unsigned long int fixed_size;
185 /* callback used to return the dynamic length */
186 gras_datadesc_type_cb_int_t dynamic_size;
188 } gras_dd_cat_array_t;
191 * gras_dd_cat_ignored_t:
193 * Specific fields of an ignored field
195 typedef struct s_gras_dd_cat_ignored {
197 void_f_pvoid_t *free_func;
198 } gras_dd_cat_ignored_t;
202 * u_gras_datadesc_category:
204 * Specific data to each possible category
206 union u_gras_datadesc_category {
207 void *undefined_data;
208 gras_dd_cat_scalar_t scalar_data;
209 gras_dd_cat_struct_t struct_data;
210 gras_dd_cat_union_t union_data;
211 gras_dd_cat_ref_t ref_data;
212 gras_dd_cat_array_t array_data;
213 gras_dd_cat_ignored_t ignored_data;
217 /****************************************/
218 /* The holy grail: type descriptor type */
219 /****************************************/
221 * s_gras_datadesc_type:
225 typedef struct s_gras_datadesc_type {
226 /* headers for the data set */
229 unsigned int name_len;
232 unsigned long int size[gras_arch_count];
234 unsigned long int alignment[gras_arch_count];
235 unsigned long int aligned_size[gras_arch_count];
237 enum e_gras_datadesc_type_category category_code;
238 union u_gras_datadesc_category category;
240 gras_datadesc_type_cb_void_t send;
241 gras_datadesc_type_cb_void_t recv;
243 int cycle; /* true if the datatype may contain cycle */
244 } s_gras_datadesc_type_t;
246 /***************************
247 * constructor/desctructor *
248 ***************************/
249 void gras_datadesc_free(gras_datadesc_type_t *type);
252 gras_datadesc_scalar(const char *name,
253 gras_ddt_scalar_type_t type,
254 enum e_gras_dd_scalar_encoding encoding);
256 /****************************************************
257 * Callback persistant state constructor/destructor *
258 ****************************************************/
259 gras_cbps_t gras_cbps_new(void);
260 void gras_cbps_free(gras_cbps_t *state);
266 gras_dd_convert_elm(gras_datadesc_type_t type, int count,
268 void *src, void *dst);
270 #endif /* GRAS_DATADESC_PRIVATE_H */