Logo AND Algorithmique Numérique Distribuée

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