Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
My god, the AIX compiler is rather picky
[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 /* 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/error.h"
20 #include "xbt/dynar.h"
21 #include "xbt/dict.h"
22 #include "xbt/set.h"
23
24 #include "gras_config.h" /* GRAS_THISARCH */
25
26 #include "gras/transport.h"  /* socket handling */
27
28 #include "gras_modinter.h"   /* module init/exit */
29 #include "gras/datadesc.h"   /* rest of module public interface */
30
31 #include "gras/DataDesc/datadesc_interface.h" /* semi-public API */
32
33 /**
34  * aligned:
35  * 
36  * Align the data v on the boundary a.
37  */
38 #define aligned(v, a) (((v) + (a - 1)) & ~(a - 1))
39
40 extern xbt_set_t gras_datadesc_set_local;
41 void gras_ddt_freev(void *ddt);
42 /*******************************************
43  * Descriptions of all known architectures *
44  *******************************************/
45
46 #define gras_arch_count 7
47 typedef enum {
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,
53
54   gras_ddt_scalar_pdata     = 5,
55   gras_ddt_scalar_pfunc     = 6,
56
57   gras_ddt_scalar_float     = 7,
58   gras_ddt_scalar_double    = 8
59 } gras_ddt_scalar_type_t;
60
61 typedef struct {
62   const char *name;
63
64   int endian;
65
66   int sizeofs[9]; /* char,short,int,long,long_long,
67                    pdata,pfunc,
68                    float,double */
69   int boundaries[9]; /* idem */
70 } gras_arch_desc_t;
71
72 extern const gras_arch_desc_t gras_arches[gras_arch_count];
73 extern const char *gras_datadesc_cat_names[9];
74
75 /**********************************************************/
76 /* Actual definitions of the stuff in the type descriptor */
77 /**********************************************************/
78
79 /**
80  * e_gras_datadesc_type_category:
81  *
82  * Defines all possible type categories. 
83  */
84 typedef enum e_gras_datadesc_type_category {
85   
86   /* if you edit this, also fix gras_datadesc_cat_names in ddt_exchange.c */
87
88   e_gras_datadesc_type_cat_undefined = 0,
89   
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,
95   e_gras_datadesc_type_cat_ignored = 6,
96   
97   e_gras_datadesc_type_cat_invalid = 7
98 } gras_datadesc_type_category_t;
99
100 /*------------------------------------------------*/
101 /* definitions of specific data for each category */
102 /*------------------------------------------------*/
103 /**
104  * s_gras_dd_cat_field:
105  *
106  * Fields of struct and union
107  */
108 typedef struct s_gras_dd_cat_field {
109
110   char     *name;
111   long int  offset[gras_arch_count];
112   gras_datadesc_type_t type;
113   
114   gras_datadesc_type_cb_void_t pre;
115   gras_datadesc_type_cb_void_t post;
116
117 } s_gras_dd_cat_field_t,*gras_dd_cat_field_t;
118
119 void gras_dd_cat_field_free(void *f);
120
121 /**
122  * gras_dd_cat_scalar_t:
123  *
124  * Specific fields of a scalar
125  */
126 enum e_gras_dd_scalar_encoding {
127   e_gras_dd_scalar_encoding_undefined = 0,
128   
129   e_gras_dd_scalar_encoding_uint,
130   e_gras_dd_scalar_encoding_sint,
131   e_gras_dd_scalar_encoding_float,
132   
133   e_gras_dd_scalar_encoding_invalid 
134 };
135 typedef struct s_gras_dd_cat_scalar {
136   enum e_gras_dd_scalar_encoding encoding;
137   gras_ddt_scalar_type_t type; /* to check easily that redefinition matches*/
138 } gras_dd_cat_scalar_t;
139
140 /**
141  * gras_dd_cat_struct_t:
142  *
143  * Specific fields of a struct
144  */
145 typedef struct s_gras_dd_cat_struct {
146   xbt_dynar_t fields; /* elm type = gras_dd_cat_field_t */
147   int closed; /* gras_datadesc_declare_struct_close() was called */
148 } gras_dd_cat_struct_t;
149
150 /**
151  * gras_dd_cat_union_t:
152  *
153  * Specific fields of a union
154  */
155 typedef struct s_gras_dd_cat_union {
156   gras_datadesc_type_cb_int_t selector;
157   xbt_dynar_t fields; /* elm type = gras_dd_cat_field_t */
158   int closed; /* gras_datadesc_declare_union_close() was called */
159 } gras_dd_cat_union_t;
160
161 /**
162  * gras_dd_cat_ref_t:
163  *
164  * Specific fields of a reference
165  */
166 typedef struct s_gras_dd_cat_ref {
167   gras_datadesc_type_t      type;
168
169   /* callback used to return the referenced type number  */
170   gras_datadesc_selector_t  selector;
171 } gras_dd_cat_ref_t;
172
173
174 /**
175  * gras_dd_cat_array_t:
176  *
177  * Specific fields of an array
178  */
179 typedef struct s_gras_dd_cat_array {
180   gras_datadesc_type_t  type;
181
182   /* element_count == 0 means dynamically defined */
183   unsigned long int           fixed_size;
184
185   /* callback used to return the dynamic length */
186   gras_datadesc_type_cb_int_t dynamic_size;
187
188 } gras_dd_cat_array_t;
189
190 /**
191  * gras_dd_cat_ignored_t:
192  *
193  * Specific fields of an ignored field
194  */
195 typedef struct s_gras_dd_cat_ignored {
196   void                          *default_value;
197   void_f_pvoid_t                *free_func;
198 } gras_dd_cat_ignored_t;
199
200
201 /**
202  * u_gras_datadesc_category:
203  *
204  * Specific data to each possible category
205  */
206 union u_gras_datadesc_category {
207         void                  *undefined_data;
208         gras_dd_cat_scalar_t   scalar_data;
209         gras_dd_cat_struct_t   struct_data;
210         gras_dd_cat_union_t    union_data;
211         gras_dd_cat_ref_t      ref_data;
212         gras_dd_cat_array_t    array_data;
213         gras_dd_cat_ignored_t  ignored_data;
214 };
215
216
217 /****************************************/
218 /* The holy grail: type descriptor type */
219 /****************************************/
220 /**
221  * s_gras_datadesc_type:
222  *
223  * Type descriptor.
224  */
225 typedef struct s_gras_datadesc_type {
226   /* headers for the data set */
227   unsigned int                         code;
228   char                                *name;
229   unsigned int                         name_len;
230         
231   /* payload */
232   unsigned long int                    size[gras_arch_count];
233   
234   unsigned long int                    alignment[gras_arch_count];  
235   unsigned long int                    aligned_size[gras_arch_count];
236   
237   enum  e_gras_datadesc_type_category  category_code;
238   union u_gras_datadesc_category       category;
239   
240   gras_datadesc_type_cb_void_t         send;
241   gras_datadesc_type_cb_void_t         recv;
242    
243   int                                  cycle; /* true if the datatype may contain cycle */
244 } s_gras_datadesc_type_t;
245
246 /***************************
247  * constructor/desctructor *
248  ***************************/
249 void gras_datadesc_free(gras_datadesc_type_t *type);
250
251 gras_datadesc_type_t 
252   gras_datadesc_scalar(const char                       *name,
253                        gras_ddt_scalar_type_t           type,
254                        enum e_gras_dd_scalar_encoding   encoding);
255
256 /****************************************************
257  * Callback persistant state constructor/destructor *
258  ****************************************************/
259 gras_cbps_t gras_cbps_new(void);
260 void gras_cbps_free(gras_cbps_t *state);
261
262 /***************
263  * Convertions *
264  ***************/
265 xbt_error_t
266 gras_dd_convert_elm(gras_datadesc_type_t type, int count,
267                     int r_arch, 
268                     void *src, void *dst);
269
270 #endif /* GRAS_DATADESC_PRIVATE_H */
271