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 9
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,
96 e_gras_datadesc_type_cat_invalid = 6
97 } gras_datadesc_type_category_t;
99 /*------------------------------------------------*/
100 /* definitions of specific data for each category */
101 /*------------------------------------------------*/
103 * s_gras_dd_cat_field:
105 * Fields of struct and union
107 typedef struct s_gras_dd_cat_field {
110 long int offset[gras_arch_count];
111 gras_datadesc_type_t type;
113 gras_datadesc_type_cb_void_t send;
114 gras_datadesc_type_cb_void_t recv;
116 } s_gras_dd_cat_field_t,*gras_dd_cat_field_t;
118 void gras_dd_cat_field_free(void *f);
121 * gras_dd_cat_scalar_t:
123 * Specific fields of a scalar
125 enum e_gras_dd_scalar_encoding {
126 e_gras_dd_scalar_encoding_undefined = 0,
128 e_gras_dd_scalar_encoding_uint,
129 e_gras_dd_scalar_encoding_sint,
130 e_gras_dd_scalar_encoding_float,
132 e_gras_dd_scalar_encoding_invalid
134 typedef struct s_gras_dd_cat_scalar {
135 enum e_gras_dd_scalar_encoding encoding;
136 gras_ddt_scalar_type_t type; /* to check easily that redefinition matches */
137 } gras_dd_cat_scalar_t;
140 * gras_dd_cat_struct_t:
142 * Specific fields of a struct
144 typedef struct s_gras_dd_cat_struct {
145 xbt_dynar_t fields; /* elm type = gras_dd_cat_field_t */
146 int closed; /* gras_datadesc_declare_struct_close() was called */
147 } gras_dd_cat_struct_t;
150 * gras_dd_cat_union_t:
152 * Specific fields of a union
154 typedef struct s_gras_dd_cat_union {
155 gras_datadesc_type_cb_int_t selector;
156 xbt_dynar_t fields; /* elm type = gras_dd_cat_field_t */
157 int closed; /* gras_datadesc_declare_union_close() was called */
158 } gras_dd_cat_union_t;
163 * Specific fields of a reference
165 typedef struct s_gras_dd_cat_ref {
166 gras_datadesc_type_t type;
168 /* callback used to return the referenced type number */
169 gras_datadesc_selector_t selector;
174 * gras_dd_cat_array_t:
176 * Specific fields of an array
178 typedef struct s_gras_dd_cat_array {
179 gras_datadesc_type_t type;
181 /* element_count == 0 means dynamically defined */
182 unsigned long int fixed_size;
184 /* callback used to return the dynamic length */
185 gras_datadesc_type_cb_int_t dynamic_size;
187 } gras_dd_cat_array_t;
190 * u_gras_datadesc_category:
192 * Specific data to each possible category
194 union u_gras_datadesc_category {
195 void *undefined_data;
196 gras_dd_cat_scalar_t scalar_data;
197 gras_dd_cat_struct_t struct_data;
198 gras_dd_cat_union_t union_data;
199 gras_dd_cat_ref_t ref_data;
200 gras_dd_cat_array_t array_data;
203 /* flags about the datadesc */
205 gras_datadesc_flag_cycle = 1, /* true if the datatype may contain cycle */
206 gras_datadesc_flag_sentinel = 1024
207 } gras_datadesc_flag_t;
210 /****************************************/
211 /* The holy grail: type descriptor type */
212 /****************************************/
214 * s_gras_datadesc_type:
218 typedef struct s_gras_datadesc_type {
219 /* headers for the data set */
222 unsigned int name_len;
225 unsigned long int size[gras_arch_count];
227 unsigned long int alignment[gras_arch_count];
228 unsigned long int aligned_size[gras_arch_count];
230 enum e_gras_datadesc_type_category category_code;
231 union u_gras_datadesc_category category;
233 gras_datadesc_type_cb_void_t send;
234 gras_datadesc_type_cb_void_t recv;
236 int flags; /* possible flags are in gras_datadesc_flag_t */
238 char extra[SIZEOF_MAX]; /* random value for users (like default value or whatever) */
240 } s_gras_datadesc_type_t;
242 /***************************
243 * constructor/desctructor *
244 ***************************/
245 void gras_datadesc_free(gras_datadesc_type_t *type);
248 gras_datadesc_scalar(const char *name,
249 gras_ddt_scalar_type_t type,
250 enum e_gras_dd_scalar_encoding encoding);
252 /****************************************************
253 * Callback persistant state constructor/destructor *
254 ****************************************************/
255 gras_cbps_t gras_cbps_new(void);
256 void gras_cbps_free(gras_cbps_t *state);
262 gras_dd_convert_elm(gras_datadesc_type_t type, int count,
264 void *src, void *dst);
266 #endif /* GRAS_DATADESC_PRIVATE_H */