Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
2435c23a94eb0d728a39d351ce8c1dd1aed94e7b
[simgrid.git] / src / gras / DataDesc / 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 /* Authors: Olivier Aumage, Martin Quinson                                  */
8 /* Copyright (C) 2003, 2004 the GRAS posse.                                 */
9
10 /* This program is free software; you can redistribute it and/or modify it
11    under the terms of the license (GNU LGPL) which comes with this package. */
12
13 #ifndef GRAS_DATADESC_PRIVATE_H
14 #define GRAS_DATADESC_PRIVATE_H
15
16 #include "xbt/sysdep.h"
17 #include "xbt/log.h"
18 #include "xbt/error.h"
19 #include "xbt/dynar.h"
20 #include "xbt/dict.h"
21 #include "xbt/set.h"
22
23 #include "gras_config.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  * aligned:
34  * 
35  * Align the data v on the boundary a.
36  */
37 #define aligned(v, a) (((v) + (a - 1)) & ~(a - 1))
38
39 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 5
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,
66                    pdata,pfunc,
67                    float,double */
68   int boundaries[9]; /* idem */
69 } gras_arch_desc_t;
70
71 extern const gras_arch_desc_t gras_arches[gras_arch_count];
72 extern const char *gras_datadesc_cat_names[9];
73
74 /**********************************************************/
75 /* Actual definitions of the stuff in the type descriptor */
76 /**********************************************************/
77
78 /**
79  * e_gras_datadesc_type_category:
80  *
81  * Defines all possible type categories. 
82  */
83 typedef enum e_gras_datadesc_type_category {
84   
85   /* if you edit this, also fix gras_datadesc_cat_names in ddt_exchange.c */
86
87   e_gras_datadesc_type_cat_undefined = 0,
88   
89   e_gras_datadesc_type_cat_scalar = 1,
90   e_gras_datadesc_type_cat_struct = 2,
91   e_gras_datadesc_type_cat_union = 3,
92   e_gras_datadesc_type_cat_ref = 4,       /* ref to an uniq element */
93   e_gras_datadesc_type_cat_array = 5,
94   e_gras_datadesc_type_cat_ignored = 6,
95   
96   e_gras_datadesc_type_cat_invalid = 7
97 } gras_datadesc_type_category_t;
98
99 /*------------------------------------------------*/
100 /* definitions of specific data for each category */
101 /*------------------------------------------------*/
102 /**
103  * s_gras_dd_cat_field:
104  *
105  * Fields of struct and union
106  */
107 typedef struct s_gras_dd_cat_field {
108
109   char     *name;
110   long int  offset[gras_arch_count];
111   gras_datadesc_type_t type;
112   
113   gras_datadesc_type_cb_void_t pre;
114   gras_datadesc_type_cb_void_t post;
115
116 } s_gras_dd_cat_field_t,*gras_dd_cat_field_t;
117
118 void gras_dd_cat_field_free(void *f);
119
120 /**
121  * gras_dd_cat_scalar_t:
122  *
123  * Specific fields of a scalar
124  */
125 enum e_gras_dd_scalar_encoding {
126   e_gras_dd_scalar_encoding_undefined = 0,
127   
128   e_gras_dd_scalar_encoding_uint,
129   e_gras_dd_scalar_encoding_sint,
130   e_gras_dd_scalar_encoding_float,
131   
132   e_gras_dd_scalar_encoding_invalid 
133 };
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;
138
139 /**
140  * gras_dd_cat_struct_t:
141  *
142  * Specific fields of a struct
143  */
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;
148
149 /**
150  * gras_dd_cat_union_t:
151  *
152  * Specific fields of a union
153  */
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;
159
160 /**
161  * gras_dd_cat_ref_t:
162  *
163  * Specific fields of a reference
164  */
165 typedef struct s_gras_dd_cat_ref {
166   gras_datadesc_type_t      type;
167
168   /* callback used to return the referenced type number  */
169   gras_datadesc_selector_t  selector;
170 } gras_dd_cat_ref_t;
171
172
173 /**
174  * gras_dd_cat_array_t:
175  *
176  * Specific fields of an array
177  */
178 typedef struct s_gras_dd_cat_array {
179   gras_datadesc_type_t  type;
180
181   /* element_count == 0 means dynamically defined */
182   unsigned long int           fixed_size;
183
184   /* callback used to return the dynamic length */
185   gras_datadesc_type_cb_int_t dynamic_size;
186
187 } gras_dd_cat_array_t;
188
189 /**
190  * gras_dd_cat_ignored_t:
191  *
192  * Specific fields of an ignored field
193  */
194 typedef struct s_gras_dd_cat_ignored {
195   void                          *default_value;
196   void_f_pvoid_t                *free_func;
197 } gras_dd_cat_ignored_t;
198
199
200 /**
201  * u_gras_datadesc_category:
202  *
203  * Specific data to each possible category
204  */
205 union u_gras_datadesc_category {
206         void                  *undefined_data;
207         gras_dd_cat_scalar_t   scalar_data;
208         gras_dd_cat_struct_t   struct_data;
209         gras_dd_cat_union_t    union_data;
210         gras_dd_cat_ref_t      ref_data;
211         gras_dd_cat_array_t    array_data;
212         gras_dd_cat_ignored_t  ignored_data;
213 };
214
215
216 /****************************************/
217 /* The holy grail: type descriptor type */
218 /****************************************/
219 /**
220  * s_gras_datadesc_type:
221  *
222  * Type descriptor.
223  */
224 typedef struct s_gras_datadesc_type {
225   /* headers for the data set */
226   unsigned int                         code;
227   char                                *name;
228   unsigned int                         name_len;
229         
230   /* payload */
231   unsigned long int                    size[gras_arch_count];
232   
233   unsigned long int                    alignment[gras_arch_count];  
234   unsigned long int                    aligned_size[gras_arch_count];
235   
236   enum  e_gras_datadesc_type_category  category_code;
237   union u_gras_datadesc_category       category;
238   
239   gras_datadesc_type_cb_void_t         send;
240   gras_datadesc_type_cb_void_t         recv;
241    
242   int                                  cycle; /* true if the datatype may contain cycle */
243 } s_gras_datadesc_type_t;
244
245 /***************************
246  * constructor/desctructor *
247  ***************************/
248 void gras_datadesc_free(gras_datadesc_type_t *type);
249
250 gras_datadesc_type_t 
251   gras_datadesc_scalar(const char                       *name,
252                        gras_ddt_scalar_type_t           type,
253                        enum e_gras_dd_scalar_encoding   encoding);
254
255 /****************************************************
256  * Callback persistant state constructor/destructor *
257  ****************************************************/
258 gras_cbps_t gras_cbps_new(void);
259 void gras_cbps_free(gras_cbps_t *state);
260
261 /***************
262  * Convertions *
263  ***************/
264 xbt_error_t
265 gras_dd_convert_elm(gras_datadesc_type_t type, int count,
266                     int r_arch, 
267                     void *src, void *dst);
268
269 #endif /* GRAS_DATADESC_PRIVATE_H */
270