Logo AND Algorithmique Numérique Distribuée

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