1 /* datadesc - describing the data to exchange */
3 /* module's private interface masked even to other parts of GRAS. */
5 /* Copyright (c) 2003 Olivier Aumage. */
6 /* Copyright (c) 2003, 2004 Martin Quinson. */
7 /* All rights reserved. */
9 /* This program is free software; you can redistribute it and/or modify it
10 * under the terms of the license (GNU LGPL) which comes with this package. */
12 #ifndef GRAS_DATADESC_PRIVATE_H
13 #define GRAS_DATADESC_PRIVATE_H
15 #include "xbt/sysdep.h"
17 #include "xbt/dynar.h"
21 #include "portable.h" /* GRAS_THISARCH */
23 #include "gras/transport.h" /* socket handling */
25 #include "gras_modinter.h" /* module init/exit */
26 #include "gras/datadesc.h" /* rest of module public interface */
28 #include "gras/DataDesc/datadesc_interface.h" /* semi-public API */
33 * Align the data v on the boundary a.
35 #define ddt_aligned(v, a) (((v) + (a - 1)) & ~(a - 1))
37 /*@null@*/ extern xbt_set_t gras_datadesc_set_local;
38 void gras_ddt_freev(void *ddt);
39 /*******************************************
40 * Descriptions of all known architectures *
41 *******************************************/
43 #define gras_arch_count 11
45 gras_ddt_scalar_char = 0,
46 gras_ddt_scalar_short = 1,
47 gras_ddt_scalar_int = 2,
48 gras_ddt_scalar_long = 3,
49 gras_ddt_scalar_long_long = 4,
51 gras_ddt_scalar_pdata = 5,
52 gras_ddt_scalar_pfunc = 6,
54 gras_ddt_scalar_float = 7,
55 gras_ddt_scalar_double = 8
56 } gras_ddt_scalar_type_t;
63 int sizeofs[9]; /* char,short,int,long,long_long,pdata,pfunc,float,double */
64 int boundaries[9]; /* idem */
67 extern const gras_arch_desc_t gras_arches[gras_arch_count];
68 extern const char *gras_datadesc_cat_names[9];
70 /**********************************************************/
71 /* Actual definitions of the stuff in the type descriptor */
72 /**********************************************************/
75 * e_gras_datadesc_type_category:
77 * Defines all possible type categories.
79 typedef enum e_gras_datadesc_type_category {
81 /* if you edit this, also fix gras_datadesc_cat_names in ddt_exchange.c */
83 e_gras_datadesc_type_cat_undefined = 0,
85 e_gras_datadesc_type_cat_scalar = 1,
86 e_gras_datadesc_type_cat_struct = 2,
87 e_gras_datadesc_type_cat_union = 3,
88 e_gras_datadesc_type_cat_ref = 4, /* ref to an uniq element */
89 e_gras_datadesc_type_cat_array = 5,
91 e_gras_datadesc_type_cat_invalid = 6
92 } gras_datadesc_type_category_t;
94 /*------------------------------------------------*/
95 /* definitions of specific data for each category */
96 /*------------------------------------------------*/
98 * s_gras_dd_cat_field:
100 * Fields of struct and union
102 typedef struct s_gras_dd_cat_field {
105 long int offset[gras_arch_count];
106 gras_datadesc_type_t type;
108 gras_datadesc_type_cb_void_t send;
109 gras_datadesc_type_cb_void_t recv;
111 } s_gras_dd_cat_field_t, *gras_dd_cat_field_t;
113 void gras_dd_cat_field_free(void *f);
116 * gras_dd_cat_scalar_t:
118 * Specific fields of a scalar
120 enum e_gras_dd_scalar_encoding {
121 e_gras_dd_scalar_encoding_undefined = 0,
123 e_gras_dd_scalar_encoding_uint,
124 e_gras_dd_scalar_encoding_sint,
125 e_gras_dd_scalar_encoding_float,
127 e_gras_dd_scalar_encoding_invalid
129 typedef struct s_gras_dd_cat_scalar {
130 enum e_gras_dd_scalar_encoding encoding;
131 gras_ddt_scalar_type_t type; /* to check easily that redefinition matches */
132 } gras_dd_cat_scalar_t;
135 * gras_dd_cat_struct_t:
137 * Specific fields of a struct
139 typedef struct s_gras_dd_cat_struct {
140 xbt_dynar_t fields; /* elm type = gras_dd_cat_field_t */
141 int closed; /* gras_datadesc_declare_struct_close() was called */
142 } gras_dd_cat_struct_t;
145 * gras_dd_cat_union_t:
147 * Specific fields of a union
149 typedef struct s_gras_dd_cat_union {
150 gras_datadesc_type_cb_int_t selector;
151 xbt_dynar_t fields; /* elm type = gras_dd_cat_field_t */
152 int closed; /* gras_datadesc_declare_union_close() was called */
153 } gras_dd_cat_union_t;
158 * Specific fields of a reference
160 typedef struct s_gras_dd_cat_ref {
161 gras_datadesc_type_t type;
163 /* callback used to return the referenced type number */
164 gras_datadesc_selector_t selector;
169 * gras_dd_cat_array_t:
171 * Specific fields of an array
173 typedef struct s_gras_dd_cat_array {
174 gras_datadesc_type_t type;
176 /* element_count == -1 means dynamically defined */
179 /* callback used to return the dynamic length */
180 gras_datadesc_type_cb_int_t dynamic_size;
182 } gras_dd_cat_array_t;
185 * u_gras_datadesc_category:
187 * Specific data to each possible category
189 union u_gras_datadesc_category {
190 void *undefined_data;
191 gras_dd_cat_scalar_t scalar_data;
192 gras_dd_cat_struct_t struct_data;
193 gras_dd_cat_union_t union_data;
194 gras_dd_cat_ref_t ref_data;
195 gras_dd_cat_array_t array_data;
198 /****************************************/
199 /* The holy grail: type descriptor type */
200 /****************************************/
202 * s_gras_datadesc_type:
206 typedef struct s_gras_datadesc_type {
207 /* headers for the data set */
210 unsigned int name_len;
213 long int size[gras_arch_count]; /* Cannot be unsigned: -1 means dynamic */
215 unsigned long int alignment[gras_arch_count];
216 unsigned long int aligned_size[gras_arch_count];
218 enum e_gras_datadesc_type_category category_code;
219 union u_gras_datadesc_category category;
221 gras_datadesc_type_cb_void_t send;
222 gras_datadesc_type_cb_void_t recv;
227 /* random value for users (like default value or whatever) */
228 char extra[SIZEOF_MAX];
230 } s_gras_datadesc_type_t;
232 /***************************
233 * constructor/desctructor *
234 ***************************/
235 void gras_datadesc_free(gras_datadesc_type_t * type);
238 gras_datadesc_scalar(const char *name,
239 gras_ddt_scalar_type_t type,
240 enum e_gras_dd_scalar_encoding encoding);
242 /****************************************************
243 * Callback persistant state constructor/destructor *
244 ****************************************************/
245 gras_cbps_t gras_cbps_new(void);
246 void gras_cbps_free(gras_cbps_t * state);
247 void gras_cbps_reset(gras_cbps_t state);
253 gras_dd_convert_elm(gras_datadesc_type_t type, int count,
254 int r_arch, void *src, void *dst);
256 /********************************************************************
257 * Dictionnary containing the constant values for the parsing macro *
258 ********************************************************************/
259 extern xbt_dict_t gras_dd_constants; /* lives in ddt_parse.c of course */
261 #endif /* GRAS_DATADESC_PRIVATE_H */