Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Integrate Bruno's work on SIMIX onto main stream. Tests are broken, but it looks...
[simgrid.git] / src / gras_simix / DataDesc / gras_simix_datadesc_private.h
1 /* $Id$ */
2
3 /* datadesc - describing the data to exchange                               */
4
5 /* module's private interface masked even to other parts of GRAS.           */
6
7 /* Copyright (c) 2003 Olivier Aumage.                                       */
8 /* Copyright (c) 2003, 2004 Martin Quinson.                                 */
9 /* All rights reserved.                                                     */
10
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. */
13
14 #ifndef GRAS_DATADESC_PRIVATE_H
15 #define GRAS_DATADESC_PRIVATE_H
16
17 #include "xbt/sysdep.h"
18 #include "xbt/log.h"
19 #include "xbt/dynar.h"
20 #include "xbt/dict.h"
21 #include "xbt/set.h"
22
23 #include "portable.h" /* GRAS_THISARCH */
24
25 #include "gras/transport.h"  /* socket handling */
26
27 #include "gras_modinter.h"   /* module init/exit */
28 #include "gras/datadesc.h"   /* rest of module public interface */
29
30 #include "gras/DataDesc/datadesc_interface.h" /* semi-public API */
31
32 /**
33  * ddt_aligned:
34  * 
35  * Align the data v on the boundary a.
36  */
37 #define ddt_aligned(v, a) (((v) + (a - 1)) & ~(a - 1))
38
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  *******************************************/
44
45 #define gras_arch_count 11
46 typedef enum {
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,
52
53   gras_ddt_scalar_pdata     = 5,
54   gras_ddt_scalar_pfunc     = 6,
55
56   gras_ddt_scalar_float     = 7,
57   gras_ddt_scalar_double    = 8
58 } gras_ddt_scalar_type_t;
59
60 typedef struct {
61   const char *name;
62
63   int endian;
64
65   int sizeofs[9]; /* char,short,int,long,long_long,pdata,pfunc,float,double */
66   int boundaries[9]; /* idem */
67 } gras_arch_desc_t;
68
69 extern const gras_arch_desc_t gras_arches[gras_arch_count];
70 extern const char *gras_datadesc_cat_names[9];
71
72 /**********************************************************/
73 /* Actual definitions of the stuff in the type descriptor */
74 /**********************************************************/
75
76 /**
77  * e_gras_datadesc_type_category:
78  *
79  * Defines all possible type categories. 
80  */
81 typedef enum e_gras_datadesc_type_category {
82   
83   /* if you edit this, also fix gras_datadesc_cat_names in ddt_exchange.c */
84
85   e_gras_datadesc_type_cat_undefined = 0,
86   
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,
92   
93   e_gras_datadesc_type_cat_invalid = 6
94 } gras_datadesc_type_category_t;
95
96 /*------------------------------------------------*/
97 /* definitions of specific data for each category */
98 /*------------------------------------------------*/
99 /**
100  * s_gras_dd_cat_field:
101  *
102  * Fields of struct and union
103  */
104 typedef struct s_gras_dd_cat_field {
105
106   char     *name;
107   long int  offset[gras_arch_count];
108   gras_datadesc_type_t type;
109   
110   gras_datadesc_type_cb_void_t send;
111   gras_datadesc_type_cb_void_t recv;
112
113 } s_gras_dd_cat_field_t,*gras_dd_cat_field_t;
114
115 void gras_dd_cat_field_free(void *f);
116
117 /**
118  * gras_dd_cat_scalar_t:
119  *
120  * Specific fields of a scalar
121  */
122 enum e_gras_dd_scalar_encoding {
123   e_gras_dd_scalar_encoding_undefined = 0,
124   
125   e_gras_dd_scalar_encoding_uint,
126   e_gras_dd_scalar_encoding_sint,
127   e_gras_dd_scalar_encoding_float,
128   
129   e_gras_dd_scalar_encoding_invalid 
130 };
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;
135
136 /**
137  * gras_dd_cat_struct_t:
138  *
139  * Specific fields of a struct
140  */
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;
145
146 /**
147  * gras_dd_cat_union_t:
148  *
149  * Specific fields of a union
150  */
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;
156
157 /**
158  * gras_dd_cat_ref_t:
159  *
160  * Specific fields of a reference
161  */
162 typedef struct s_gras_dd_cat_ref {
163   gras_datadesc_type_t      type;
164
165   /* callback used to return the referenced type number  */
166   gras_datadesc_selector_t  selector;
167 } gras_dd_cat_ref_t;
168
169
170 /**
171  * gras_dd_cat_array_t:
172  *
173  * Specific fields of an array
174  */
175 typedef struct s_gras_dd_cat_array {
176   gras_datadesc_type_t  type;
177
178   /* element_count == 0 means dynamically defined */
179   unsigned long int           fixed_size;
180
181   /* callback used to return the dynamic length */
182   gras_datadesc_type_cb_int_t dynamic_size;
183
184 } gras_dd_cat_array_t;
185
186 /**
187  * u_gras_datadesc_category:
188  *
189  * Specific data to each possible category
190  */
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;
198 };
199
200 /****************************************/
201 /* The holy grail: type descriptor type */
202 /****************************************/
203 /**
204  * s_gras_datadesc_type:
205  *
206  * Type descriptor.
207  */
208 typedef struct s_gras_datadesc_type {
209   /* headers for the data set */
210   unsigned int                         code;
211   char                                *name;
212   unsigned int                         name_len;
213         
214   /* payload */
215   unsigned long int                    size[gras_arch_count];
216   
217   unsigned long int                    alignment[gras_arch_count];  
218   unsigned long int                    aligned_size[gras_arch_count];
219   
220   enum  e_gras_datadesc_type_category  category_code;
221   union u_gras_datadesc_category       category;
222   
223   gras_datadesc_type_cb_void_t         send;
224   gras_datadesc_type_cb_void_t         recv;
225    
226   /* flags */
227   int                                  cycle :1;
228    
229   /* random value for users (like default value or whatever) */
230   char                                 extra[SIZEOF_MAX]; 
231
232 } s_gras_datadesc_type_t;
233
234 /***************************
235  * constructor/desctructor *
236  ***************************/
237 void gras_datadesc_free(gras_datadesc_type_t *type);
238
239   gras_datadesc_type_t
240   gras_datadesc_scalar(const char                       *name,
241                        gras_ddt_scalar_type_t           type,
242                        enum e_gras_dd_scalar_encoding   encoding);
243
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);
250
251 /***************
252  * Convertions *
253  ***************/
254 void
255 gras_dd_convert_elm(gras_datadesc_type_t type, int count,
256                     int r_arch, 
257                     void *src, void *dst);
258
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 */
263
264 #endif /* GRAS_DATADESC_PRIVATE_H */
265