Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
J'en ai marre de faire des messages detailles. 'Current state' ;)
[simgrid.git] / include / datadesc.h
1 /* $Id$ */
2
3 /* gras/datadesc.h - Describing the data you want to exchange               */
4
5 /* Authors: Martin Quinson                                                  */
6 /* Copyright (C) 2003 the OURAGAN project.                                  */
7
8 /* This program is free software; you can redistribute it and/or modify it
9    under the terms of the license (GNU LGPL) which comes with this package. */
10
11 #ifndef GRAS_DATADESC_H
12 #define GRAS_DATADESC_H
13
14 #include <stddef.h>    /* offsetof() */
15 #include <sys/types.h>  /* size_t */
16 #include <stdarg.h>
17
18
19 /*! C++ users need love */
20 #ifndef BEGIN_DECL
21 # ifdef __cplusplus
22 #  define BEGIN_DECL extern "C" {
23 # else
24 #  define BEGIN_DECL 
25 # endif
26 #endif
27
28 /*! C++ users need love */
29 #ifndef END_DECL
30 # ifdef __cplusplus
31 #  define END_DECL }
32 # else
33 #  define END_DECL 
34 # endif
35 #endif
36 /* End of cruft for C++ */
37
38 BEGIN_DECL
39
40
41 typedef struct s_gras_datadesc_type gras_datadesc_type_t;
42
43 /***********************************************
44  **** Search and retrieve declared datatype ****
45  ***********************************************/
46 long int gras_datadesc_get_id_from_name(const char *name);
47
48 /*********************************************
49  **** DataDesc callback persistent states ****
50  *********************************************/
51 typedef struct s_gras_dd_cbps gras_dd_cbps_t;
52
53 void *
54 gras_dd_cbps_pop (gras_dd_cbps_t        *ps, 
55                   const char            *name,
56                   gras_datadesc_type_t **ddt);
57 void
58 gras_dd_cbps_push(gras_dd_cbps_t        *ps,
59                   const char            *name,
60                   void                  *data,
61                   gras_datadesc_type_t  *ddt);
62 void
63 gras_dd_cbps_set (gras_dd_cbps_t        *ps,
64                   const char            *name,
65                   void                  *data,
66                   gras_datadesc_type_t  *ddt);
67
68 void *
69 gras_dd_cbps_get (gras_dd_cbps_t        *ps, 
70                   const char            *name,
71                   gras_datadesc_type_t **ddt);
72
73 void
74 gras_dd_cbps_block_begin(gras_dd_cbps_t *ps);
75 void
76 gras_dd_cbps_block_end(gras_dd_cbps_t *ps);
77
78
79 /******************************************
80  **** Declare datadescription manually ****
81  ******************************************/
82
83 typedef void (*gras_datadesc_type_cb_void_t)(void                 *vars,
84                                              gras_datadesc_type_t *p_type,
85                                              void                 *data);
86 typedef int (*gras_datadesc_type_cb_int_t)(void                 *vars,
87                                            gras_datadesc_type_t *p_type,
88                                            void                 *data);
89
90
91
92 /* Create a new type and register it on the local machine */
93 #define gras_datadesc_declare_struct(   name,             code) \
94         gras_datadesc_declare_struct_cb(name, NULL, NULL, code)
95
96 #define gras_datadesc_declare_struct_add_name(   struct_code,field_name,field_type_name) \
97         gras_datadesc_declare_struct_add_name_cb(struct_code,field_name,field_type_name, NULL, NULL)
98
99 #define gras_datadesc_declare_struct_add_code(   struct_code,field_name,field_type_code) \
100         gras_datadesc_declare_struct_add_code_cb(struct_code,field_name,field_type_code, NULL, NULL)
101
102 gras_error_t 
103 gras_datadesc_declare_struct_cb(const char                   *name,
104                                 gras_datadesc_type_cb_void_t  pre_cb,
105                                 gras_datadesc_type_cb_void_t  post_cb,
106                                 long int                     *code);
107 gras_error_t 
108 gras_datadesc_declare_struct_add_name_cb(long int                      struct_code,
109                                          const char                   *field_name,
110                                          const char                   *field_type_name,
111                                          gras_datadesc_type_cb_void_t  pre_cb,
112                                          gras_datadesc_type_cb_void_t  post_cb);
113
114 gras_error_t 
115 gras_datadesc_declare_struct_add_code_cb(long int                      struct_code,
116                                          const char                   *field_name,
117                                          long int                      field_code,
118                                          gras_datadesc_type_cb_void_t  pre_cb,
119                                          gras_datadesc_type_cb_void_t  post_cb);
120 /* union */
121 #define gras_datadesc_declare_union(   name,             code) \
122         gras_datadesc_declare_union_cb(name, NULL, NULL, code)
123
124 #define gras_datadesc_declare_union_add_name(   union_code,field_name,field_type_name) \
125         gras_datadesc_declare_union_add_name_cb(union_code,field_name,field_type_name, NULL, NULL)
126
127 #define gras_datadesc_declare_union_add_code(   union_code,field_name,field_type_code) \
128         gras_datadesc_declare_union_add_code_cb(union_code,field_name,field_type_code, NULL, NULL)
129
130 gras_error_t 
131 gras_datadesc_declare_union_cb(const char                   *name,
132                                gras_datadesc_type_cb_int_t   field_count,
133                                gras_datadesc_type_cb_void_t  post,
134                                long int                     *code);
135 gras_error_t 
136 gras_datadesc_declare_union_add_name_cb(long int                      union_code,
137                                         const char                   *field_name,
138                                         const char                   *field_type_name,
139                                         gras_datadesc_type_cb_void_t  pre_cb,
140                                         gras_datadesc_type_cb_void_t  post_cb);
141 gras_error_t 
142 gras_datadesc_declare_union_add_code_cb(long int                      union_code,
143                                         const char                   *field_name,
144                                         long int                      field_code,
145                                         gras_datadesc_type_cb_void_t  pre_cb,
146                                         gras_datadesc_type_cb_void_t  post_cb);
147 /* ref */
148 #define gras_datadesc_declare_ref(name,ref_type, code) \
149         gras_datadesc_declare_ref_cb(name, ref_type, NULL, NULL, code)
150 #define gras_datadesc_declare_ref_disc(name,discriminant, code) \
151         gras_datadesc_declare_ref_cb(name, NULL, discriminant,  NULL, code)
152
153 gras_error_t
154 gras_datadesc_declare_ref_cb(const char                      *name,
155                              gras_datadesc_type_t            *referenced_type,
156                              gras_datadesc_type_cb_int_t      discriminant,
157                              gras_datadesc_type_cb_void_t     post,
158                              long int                        *code);
159 /* array */
160 #define gras_datadesc_declare_array(name,elm_type, size, code) \
161         gras_datadesc_declare_array_cb(name, elm_type, size, NULL,         NULL, code)
162 #define gras_datadesc_declare_array_dyn(name,elm_type, dynamic_size, code) \
163         gras_datadesc_declare_array_cb(name, elm_type, -1,   dynamic_size, NULL, code)
164
165 gras_error_t 
166 gras_datadesc_declare_array_cb(const char                      *name,
167                                gras_datadesc_type_t            *element_type,
168                                long int                         fixed_size,
169                                gras_datadesc_type_cb_int_t      dynamic_size,
170                                gras_datadesc_type_cb_void_t     post,
171                                long int                        *code);
172
173 /****************************
174  **** Parse C statements ****
175  ****************************/
176 gras_error_t
177 gras_datadesc_parse(const char *name,
178                     const char *Cdefinition,
179                     long int   *code);
180 #define GRAS_DEFINE_TYPE(name,def) \
181   static const char * _gras_this_type_symbol_does_not_exist__##name=#def; def
182  
183 #define gras_type_symbol_parse(bag,name)                                  \
184  _gs_type_parse(bag, _gs_this_type_symbol_does_not_exist__##name)
185  
186 #define gs_type_get_by_symbol(bag,name)                  \
187   (bag->bag_ops->get_type_by_name(bag, NULL, #name) ?    \
188      bag->bag_ops->get_type_by_name(bag, NULL, #name) :  \
189      gras_type_symbol_parse(bag, name)                   \
190   )
191
192 /*****************************
193  **** NWS datadescription ****
194  *****************************/
195
196 /**
197  * Basic types we can embeed in DataDescriptors.
198  */
199 typedef enum
200   {CHAR_TYPE, DOUBLE_TYPE, FLOAT_TYPE, INT_TYPE, LONG_TYPE, SHORT_TYPE,
201    UNSIGNED_INT_TYPE, UNSIGNED_LONG_TYPE, UNSIGNED_SHORT_TYPE, STRUCT_TYPE}
202   DataTypes;
203 #define SIMPLE_TYPE_COUNT 9
204
205 /*!  \brief Describe a collection of data.
206  * 
207 ** A description of a collection of #type# data.  #repetitions# is used only
208 ** for arrays; it contains the number of elements.  #offset# is used only for
209 ** struct members in host format; it contains the offset of the member from the
210 ** beginning of the struct, taking into account internal padding added by the
211 ** compiler for alignment purposes.  #members#, #length#, and #tailPadding# are
212 ** used only for STRUCT_TYPE data; the #length#-long array #members# describes
213 ** the members of the nested struct, and #tailPadding# indicates how many
214 ** padding bytes the compiler adds to the end of the structure.
215 */
216
217 typedef struct DataDescriptorStruct {
218   DataTypes type;
219   size_t repetitions;
220   size_t offset;
221   /*@null@*/ struct DataDescriptorStruct *members;
222   size_t length;
223   size_t tailPadding;
224 } DataDescriptor;
225 /** DataDescriptor for an array */
226 #define SIMPLE_DATA(type,repetitions) \
227   {type, repetitions, 0, NULL, 0, 0}
228 /** DataDescriptor for an structure member */
229 #define SIMPLE_MEMBER(type,repetitions,offset) \
230   {type, repetitions, offset, NULL, 0, 0}
231 /** DataDescriptor for padding bytes */
232 #define PAD_BYTES(structType,lastMember,memberType,repetitions) \
233   sizeof(structType) - offsetof(structType, lastMember) - \
234   sizeof(memberType) * repetitions
235
236 gras_error_t
237 gras_datadesc_from_nws(const char           *name,
238                        const DataDescriptor *desc,
239                        size_t                howmany,
240                        long int             *code);
241
242
243 END_DECL
244
245 #endif /* GRAS_DATADESC_H */