Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
00898c2371af31597355ecc7389d4b8393152f30
[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 /*@null@*/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 9
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   
96   e_gras_datadesc_type_cat_invalid = 6
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 send;
114   gras_datadesc_type_cb_void_t recv;
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  * u_gras_datadesc_category:
191  *
192  * Specific data to each possible category
193  */
194 union u_gras_datadesc_category {
195         void                  *undefined_data;
196         gras_dd_cat_scalar_t   scalar_data;
197         gras_dd_cat_struct_t   struct_data;
198         gras_dd_cat_union_t    union_data;
199         gras_dd_cat_ref_t      ref_data;
200         gras_dd_cat_array_t    array_data;
201 };
202
203 /* flags about the datadesc */
204 enum {
205    gras_datadesc_flag_cycle = 1, /* true if the datatype may contain cycle */
206    gras_datadesc_flag_sentinel = 1024
207 } gras_datadesc_flag_t;
208
209
210 /****************************************/
211 /* The holy grail: type descriptor type */
212 /****************************************/
213 /**
214  * s_gras_datadesc_type:
215  *
216  * Type descriptor.
217  */
218 typedef struct s_gras_datadesc_type {
219   /* headers for the data set */
220   unsigned int                         code;
221   char                                *name;
222   unsigned int                         name_len;
223         
224   /* payload */
225   unsigned long int                    size[gras_arch_count];
226   
227   unsigned long int                    alignment[gras_arch_count];  
228   unsigned long int                    aligned_size[gras_arch_count];
229   
230   enum  e_gras_datadesc_type_category  category_code;
231   union u_gras_datadesc_category       category;
232   
233   gras_datadesc_type_cb_void_t         send;
234   gras_datadesc_type_cb_void_t         recv;
235    
236   int                                  flags; /* possible flags are in gras_datadesc_flag_t */
237    
238   char                                 extra[SIZEOF_MAX]; /* random value for users (like default value or whatever) */
239
240 } s_gras_datadesc_type_t;
241
242 /***************************
243  * constructor/desctructor *
244  ***************************/
245 void gras_datadesc_free(gras_datadesc_type_t *type);
246
247 gras_datadesc_type_t 
248   gras_datadesc_scalar(const char                       *name,
249                        gras_ddt_scalar_type_t           type,
250                        enum e_gras_dd_scalar_encoding   encoding);
251
252 /****************************************************
253  * Callback persistant state constructor/destructor *
254  ****************************************************/
255 gras_cbps_t gras_cbps_new(void);
256 void gras_cbps_free(gras_cbps_t *state);
257
258 /***************
259  * Convertions *
260  ***************/
261 xbt_error_t
262 gras_dd_convert_elm(gras_datadesc_type_t type, int count,
263                     int r_arch, 
264                     void *src, void *dst);
265
266 #endif /* GRAS_DATADESC_PRIVATE_H */
267