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/dynar.h"
23 #include "portable.h" /* GRAS_THISARCH */
25 #include "gras/transport.h" /* socket handling */
27 #include "gras_modinter.h" /* module init/exit */
28 #include "gras/datadesc.h" /* rest of module public interface */
30 #include "gras/DataDesc/datadesc_interface.h" /* semi-public API */
35 * Align the data v on the boundary a.
37 #define ddt_aligned(v, a) (((v) + (a - 1)) & ~(a - 1))
39 /*@null@*/extern xbt_set_t gras_datadesc_set_local;
40 void gras_ddt_freev(void *ddt);
41 /*******************************************
42 * Descriptions of all known architectures *
43 *******************************************/
45 #define gras_arch_count 11
47 gras_ddt_scalar_char = 0,
48 gras_ddt_scalar_short = 1,
49 gras_ddt_scalar_int = 2,
50 gras_ddt_scalar_long = 3,
51 gras_ddt_scalar_long_long = 4,
53 gras_ddt_scalar_pdata = 5,
54 gras_ddt_scalar_pfunc = 6,
56 gras_ddt_scalar_float = 7,
57 gras_ddt_scalar_double = 8
58 } gras_ddt_scalar_type_t;
65 int sizeofs[9]; /* char,short,int,long,long_long,pdata,pfunc,float,double */
66 int boundaries[9]; /* idem */
69 extern const gras_arch_desc_t gras_arches[gras_arch_count];
70 extern const char *gras_datadesc_cat_names[9];
72 /**********************************************************/
73 /* Actual definitions of the stuff in the type descriptor */
74 /**********************************************************/
77 * e_gras_datadesc_type_category:
79 * Defines all possible type categories.
81 typedef enum e_gras_datadesc_type_category {
83 /* if you edit this, also fix gras_datadesc_cat_names in ddt_exchange.c */
85 e_gras_datadesc_type_cat_undefined = 0,
87 e_gras_datadesc_type_cat_scalar = 1,
88 e_gras_datadesc_type_cat_struct = 2,
89 e_gras_datadesc_type_cat_union = 3,
90 e_gras_datadesc_type_cat_ref = 4, /* ref to an uniq element */
91 e_gras_datadesc_type_cat_array = 5,
93 e_gras_datadesc_type_cat_invalid = 6
94 } gras_datadesc_type_category_t;
96 /*------------------------------------------------*/
97 /* definitions of specific data for each category */
98 /*------------------------------------------------*/
100 * s_gras_dd_cat_field:
102 * Fields of struct and union
104 typedef struct s_gras_dd_cat_field {
107 long int offset[gras_arch_count];
108 gras_datadesc_type_t type;
110 gras_datadesc_type_cb_void_t send;
111 gras_datadesc_type_cb_void_t recv;
113 } s_gras_dd_cat_field_t,*gras_dd_cat_field_t;
115 void gras_dd_cat_field_free(void *f);
118 * gras_dd_cat_scalar_t:
120 * Specific fields of a scalar
122 enum e_gras_dd_scalar_encoding {
123 e_gras_dd_scalar_encoding_undefined = 0,
125 e_gras_dd_scalar_encoding_uint,
126 e_gras_dd_scalar_encoding_sint,
127 e_gras_dd_scalar_encoding_float,
129 e_gras_dd_scalar_encoding_invalid
131 typedef struct s_gras_dd_cat_scalar {
132 enum e_gras_dd_scalar_encoding encoding;
133 gras_ddt_scalar_type_t type; /* to check easily that redefinition matches */
134 } gras_dd_cat_scalar_t;
137 * gras_dd_cat_struct_t:
139 * Specific fields of a struct
141 typedef struct s_gras_dd_cat_struct {
142 xbt_dynar_t fields; /* elm type = gras_dd_cat_field_t */
143 int closed; /* gras_datadesc_declare_struct_close() was called */
144 } gras_dd_cat_struct_t;
147 * gras_dd_cat_union_t:
149 * Specific fields of a union
151 typedef struct s_gras_dd_cat_union {
152 gras_datadesc_type_cb_int_t selector;
153 xbt_dynar_t fields; /* elm type = gras_dd_cat_field_t */
154 int closed; /* gras_datadesc_declare_union_close() was called */
155 } gras_dd_cat_union_t;
160 * Specific fields of a reference
162 typedef struct s_gras_dd_cat_ref {
163 gras_datadesc_type_t type;
165 /* callback used to return the referenced type number */
166 gras_datadesc_selector_t selector;
171 * gras_dd_cat_array_t:
173 * Specific fields of an array
175 typedef struct s_gras_dd_cat_array {
176 gras_datadesc_type_t type;
178 /* element_count == 0 means dynamically defined */
179 unsigned long int fixed_size;
181 /* callback used to return the dynamic length */
182 gras_datadesc_type_cb_int_t dynamic_size;
184 } gras_dd_cat_array_t;
187 * u_gras_datadesc_category:
189 * Specific data to each possible category
191 union u_gras_datadesc_category {
192 void *undefined_data;
193 gras_dd_cat_scalar_t scalar_data;
194 gras_dd_cat_struct_t struct_data;
195 gras_dd_cat_union_t union_data;
196 gras_dd_cat_ref_t ref_data;
197 gras_dd_cat_array_t array_data;
200 /****************************************/
201 /* The holy grail: type descriptor type */
202 /****************************************/
204 * s_gras_datadesc_type:
208 typedef struct s_gras_datadesc_type {
209 /* headers for the data set */
212 unsigned int name_len;
215 unsigned long int size[gras_arch_count];
217 unsigned long int alignment[gras_arch_count];
218 unsigned long int aligned_size[gras_arch_count];
220 enum e_gras_datadesc_type_category category_code;
221 union u_gras_datadesc_category category;
223 gras_datadesc_type_cb_void_t send;
224 gras_datadesc_type_cb_void_t recv;
229 /* random value for users (like default value or whatever) */
230 char extra[SIZEOF_MAX];
232 } s_gras_datadesc_type_t;
234 /***************************
235 * constructor/desctructor *
236 ***************************/
237 void gras_datadesc_free(gras_datadesc_type_t *type);
240 gras_datadesc_scalar(const char *name,
241 gras_ddt_scalar_type_t type,
242 enum e_gras_dd_scalar_encoding encoding);
244 /****************************************************
245 * Callback persistant state constructor/destructor *
246 ****************************************************/
247 gras_cbps_t gras_cbps_new(void);
248 void gras_cbps_free(gras_cbps_t *state);
249 void gras_cbps_reset(gras_cbps_t state);
255 gras_dd_convert_elm(gras_datadesc_type_t type, int count,
257 void *src, void *dst);
259 /********************************************************************
260 * Dictionnary containing the constant values for the parsing macro *
261 ********************************************************************/
262 extern xbt_dict_t gras_dd_constants; /* lives in ddt_parse.c of course */
264 #endif /* GRAS_DATADESC_PRIVATE_H */