Logo AND Algorithmique Numérique Distribuée

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