Logo AND Algorithmique Numérique Distribuée

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