1 /* datadesc - describing the data to exchange */
3 /* module's private interface masked even to other parts of GRAS. */
5 /* Copyright (c) 2004, 2005, 2006, 2007, 2009, 2010. The SimGrid Team.
6 * All rights reserved. */
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_PRIVATE_H
12 #define GRAS_DATADESC_PRIVATE_H
14 #include "xbt/sysdep.h"
16 #include "xbt/dynar.h"
20 #include "portable.h" /* GRAS_THISARCH */
22 #include "gras/transport.h" /* socket handling */
24 #include "gras_modinter.h" /* module init/exit */
25 #include "gras/datadesc.h" /* rest of module public interface */
27 #include "gras/DataDesc/datadesc_interface.h" /* semi-public API */
32 * Align the data v on the boundary a.
34 #define ddt_aligned(v, a) (((v) + (a - 1)) & ~(a - 1))
36 /*@null@*/ extern xbt_set_t gras_datadesc_set_local;
37 void gras_ddt_freev(void *ddt);
38 /*******************************************
39 * Descriptions of all known architectures *
40 *******************************************/
42 #define gras_arch_count 12
44 gras_ddt_scalar_char = 0,
45 gras_ddt_scalar_short = 1,
46 gras_ddt_scalar_int = 2,
47 gras_ddt_scalar_long = 3,
48 gras_ddt_scalar_long_long = 4,
50 gras_ddt_scalar_pdata = 5,
51 gras_ddt_scalar_pfunc = 6,
53 gras_ddt_scalar_float = 7,
54 gras_ddt_scalar_double = 8
55 } gras_ddt_scalar_type_t;
62 int sizeofs[9]; /* char,short,int,long,long_long,pdata,pfunc,float,double */
63 int boundaries[9]; /* idem */
66 extern const gras_arch_desc_t gras_arches[gras_arch_count];
67 extern const char *gras_datadesc_cat_names[9];
69 /**********************************************************/
70 /* Actual definitions of the stuff in the type descriptor */
71 /**********************************************************/
74 * e_gras_datadesc_type_category:
76 * Defines all possible type categories.
78 typedef enum e_gras_datadesc_type_category {
80 /* if you edit this, also fix gras_datadesc_cat_names in ddt_exchange.c */
82 e_gras_datadesc_type_cat_undefined = 0,
84 e_gras_datadesc_type_cat_scalar = 1,
85 e_gras_datadesc_type_cat_struct = 2,
86 e_gras_datadesc_type_cat_union = 3,
87 e_gras_datadesc_type_cat_ref = 4, /* ref to an uniq element */
88 e_gras_datadesc_type_cat_array = 5,
90 e_gras_datadesc_type_cat_invalid = 6
91 } gras_datadesc_type_category_t;
93 /*------------------------------------------------*/
94 /* definitions of specific data for each category */
95 /*------------------------------------------------*/
97 * s_gras_dd_cat_field:
99 * Fields of struct and union
101 typedef struct s_gras_dd_cat_field {
104 long int offset[gras_arch_count];
105 gras_datadesc_type_t type;
107 gras_datadesc_type_cb_void_t send;
108 gras_datadesc_type_cb_void_t recv;
110 } s_gras_dd_cat_field_t, *gras_dd_cat_field_t;
112 void gras_dd_cat_field_free(void *f);
115 * gras_dd_cat_scalar_t:
117 * Specific fields of a scalar
119 enum e_gras_dd_scalar_encoding {
120 e_gras_dd_scalar_encoding_undefined = 0,
122 e_gras_dd_scalar_encoding_uint,
123 e_gras_dd_scalar_encoding_sint,
124 e_gras_dd_scalar_encoding_float,
126 e_gras_dd_scalar_encoding_invalid
128 typedef struct s_gras_dd_cat_scalar {
129 enum e_gras_dd_scalar_encoding encoding;
130 gras_ddt_scalar_type_t type; /* to check easily that redefinition matches */
131 } gras_dd_cat_scalar_t;
134 * gras_dd_cat_struct_t:
136 * Specific fields of a struct
138 typedef struct s_gras_dd_cat_struct {
139 xbt_dynar_t fields; /* elm type = gras_dd_cat_field_t */
140 int closed; /* gras_datadesc_declare_struct_close() was called */
141 } gras_dd_cat_struct_t;
144 * gras_dd_cat_union_t:
146 * Specific fields of a union
148 typedef struct s_gras_dd_cat_union {
149 gras_datadesc_type_cb_int_t selector;
150 xbt_dynar_t fields; /* elm type = gras_dd_cat_field_t */
151 int closed; /* gras_datadesc_declare_union_close() was called */
152 } gras_dd_cat_union_t;
157 * Specific fields of a reference
159 typedef struct s_gras_dd_cat_ref {
160 gras_datadesc_type_t type;
162 /* callback used to return the referenced type number */
163 gras_datadesc_selector_t selector;
168 * gras_dd_cat_array_t:
170 * Specific fields of an array
172 typedef struct s_gras_dd_cat_array {
173 gras_datadesc_type_t type;
175 /* element_count == -1 means dynamically defined */
178 /* callback used to return the dynamic length */
179 gras_datadesc_type_cb_int_t dynamic_size;
181 } gras_dd_cat_array_t;
184 * u_gras_datadesc_category:
186 * Specific data to each possible category
188 union u_gras_datadesc_category {
189 void *undefined_data;
190 gras_dd_cat_scalar_t scalar_data;
191 gras_dd_cat_struct_t struct_data;
192 gras_dd_cat_union_t union_data;
193 gras_dd_cat_ref_t ref_data;
194 gras_dd_cat_array_t array_data;
197 /****************************************/
198 /* The holy grail: type descriptor type */
199 /****************************************/
201 * s_gras_datadesc_type:
205 typedef struct s_gras_datadesc_type {
206 /* headers for the data set */
209 unsigned int name_len;
212 long int size[gras_arch_count]; /* Cannot be unsigned: -1 means dynamic */
214 unsigned long int alignment[gras_arch_count];
215 unsigned long int aligned_size[gras_arch_count];
217 enum e_gras_datadesc_type_category category_code;
218 union u_gras_datadesc_category category;
220 gras_datadesc_type_cb_void_t send;
221 gras_datadesc_type_cb_void_t recv;
226 /* random value for users (like default value or whatever) */
227 char extra[SIZEOF_MAX];
229 } s_gras_datadesc_type_t;
231 /***************************
232 * constructor/desctructor *
233 ***************************/
234 void gras_datadesc_free(gras_datadesc_type_t * type);
237 gras_datadesc_scalar(const char *name,
238 gras_ddt_scalar_type_t type,
239 enum e_gras_dd_scalar_encoding encoding);
241 /****************************************************
242 * Callback persistant state constructor/destructor *
243 ****************************************************/
244 gras_cbps_t gras_cbps_new(void);
245 void gras_cbps_free(gras_cbps_t * state);
246 void gras_cbps_reset(gras_cbps_t state);
252 gras_dd_convert_elm(gras_datadesc_type_t type, int count,
253 int r_arch, void *src, void *dst);
255 /********************************************************************
256 * Dictionnary containing the constant values for the parsing macro *
257 ********************************************************************/
258 extern xbt_dict_t gras_dd_constants; /* lives in ddt_parse.c of course */
260 #endif /* GRAS_DATADESC_PRIVATE_H */