Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Version 0.6 (protocol not changed; ABI expended)
[simgrid.git] / include / gras / 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, 2004 Martin Quinson.                                 */
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 /**
42  * gras_datadesc_type_t:
43  * 
44  * Opaque type describing a type description you don't want to open.
45  */
46 typedef struct s_gras_datadesc_type gras_datadesc_type_t;
47
48 typedef struct s_gras_cbps gras_cbps_t;
49
50 /* callbacks prototypes */
51 typedef void (*gras_datadesc_type_cb_void_t)(gras_cbps_t *vars, void *data);
52 typedef int (*gras_datadesc_type_cb_int_t)(gras_cbps_t *vars, void *data);
53 typedef gras_datadesc_type_t *(*gras_datadesc_selector_t)(gras_cbps_t *vars, void *data);
54
55 /***********************************************
56  **** Search and retrieve declared datatype ****
57  ***********************************************/
58 gras_datadesc_type_t *gras_datadesc_by_name(const char *name);
59
60 /******************************************
61  **** Declare datadescription yourself ****
62  ******************************************/
63
64 gras_error_t 
65 gras_datadesc_struct(const char            *name,
66                      gras_datadesc_type_t **dst);
67 gras_error_t 
68 gras_datadesc_struct_append(gras_datadesc_type_t          *struct_type,
69                             const char                    *name,
70                             gras_datadesc_type_t          *field_type);
71 void
72 gras_datadesc_struct_close(gras_datadesc_type_t          *struct_type);
73 gras_error_t 
74 gras_datadesc_union(const char                      *name,
75                     gras_datadesc_type_cb_int_t      selector,
76                     gras_datadesc_type_t           **dst);
77 gras_error_t 
78 gras_datadesc_union_append(gras_datadesc_type_t          *union_type,
79                            const char                    *name,
80                            gras_datadesc_type_t          *field_type);
81 void
82 gras_datadesc_union_close(gras_datadesc_type_t          *union_type);
83 gras_error_t 
84 gras_datadesc_ref(const char                      *name,
85                   gras_datadesc_type_t            *referenced_type,
86                   gras_datadesc_type_t           **dst);
87 gras_error_t
88 gras_datadesc_ref_generic(const char                *name,
89                           gras_datadesc_selector_t   selector,
90                           gras_datadesc_type_t     **dst);
91 gras_error_t 
92 gras_datadesc_array_fixed(const char                    *name,
93                           gras_datadesc_type_t          *element_type,
94                           long int                       fixed_size,
95                           gras_datadesc_type_t         **dst);
96 gras_error_t 
97 gras_datadesc_array_dyn(const char                      *name,
98                         gras_datadesc_type_t            *element_type,
99                         gras_datadesc_type_cb_int_t      dynamic_size,
100                         gras_datadesc_type_t           **dst);
101 gras_error_t 
102 gras_datadesc_ref_pop_arr(gras_datadesc_type_t  *element_type,
103                           gras_datadesc_type_t **dst);
104
105 /*********************************
106  * Change stuff within datadescs *
107  *********************************/
108
109 void gras_datadesc_cb_send (gras_datadesc_type_t    *type,
110                             gras_datadesc_type_cb_void_t  pre);
111 void gras_datadesc_cb_recv(gras_datadesc_type_t    *type,
112                            gras_datadesc_type_cb_void_t  post);
113 void gras_datadesc_cb_field_send (gras_datadesc_type_t    *type,
114                                   const char *field_name,
115                                   gras_datadesc_type_cb_void_t  pre);
116 void gras_datadesc_cb_field_recv(gras_datadesc_type_t    *type,
117                                  const char *field_name,
118                                  gras_datadesc_type_cb_void_t  post);
119 void gras_datadesc_cb_field_push (gras_datadesc_type_t         *type,
120                                   const char                   *field_name);
121
122 /******************************
123  * Get stuff within datadescs *
124  ******************************/
125 char * gras_datadesc_get_name(gras_datadesc_type_t *ddt);
126 int gras_datadesc_get_id(gras_datadesc_type_t *ddt);
127
128 /********************************************************
129  * Advanced data describing: callback persistent states *
130  ********************************************************/
131 /* simple one: push/pop sizes of arrays */
132 void
133 gras_cbps_i_push(gras_cbps_t *ps, int val);
134 int 
135 gras_cbps_i_pop(gras_cbps_t *ps);
136
137 int gras_datadesc_cb_pop(gras_cbps_t *vars, void *data);
138 void gras_datadesc_cb_push_int(gras_cbps_t *vars, void *data);
139 void gras_datadesc_cb_push_uint(gras_cbps_t *vars, void *data);
140 void gras_datadesc_cb_push_lint(gras_cbps_t *vars, void *data);
141 void gras_datadesc_cb_push_ulint(gras_cbps_t *vars, void *data);
142
143
144
145 /* complex one: complete variable environment support */
146 gras_error_t
147 gras_cbps_v_pop (gras_cbps_t        *ps, 
148                     const char            *name,
149                     gras_datadesc_type_t **ddt,
150                   void                 **res);
151 gras_error_t
152 gras_cbps_v_push(gras_cbps_t        *ps,
153                     const char            *name,
154                     void                  *data,
155                     gras_datadesc_type_t  *ddt);
156 void
157 gras_cbps_v_set (gras_cbps_t        *ps,
158                     const char            *name,
159                     void                  *data,
160                     gras_datadesc_type_t  *ddt);
161
162 void *
163 gras_cbps_v_get (gras_cbps_t        *ps, 
164                     const char            *name,
165                     gras_datadesc_type_t **ddt);
166
167 void
168 gras_cbps_block_begin(gras_cbps_t *ps);
169 void
170 gras_cbps_block_end(gras_cbps_t *ps);
171
172
173
174
175 /*******************************
176  **** About data convertion ****
177  *******************************/
178 int gras_arch_selfid(void); /* ID of this arch */
179
180 /****************************
181  **** Parse C statements ****
182  ****************************/
183 gras_datadesc_type_t *
184 gras_datadesc_parse(const char *name,
185                     const char *Cdefinition);
186 #define GRAS_DEFINE_TYPE(name,def) \
187   static const char * _gras_this_type_symbol_does_not_exist__##name=#def; def
188 #define GRAS_ANNOTE(key,val)
189  
190 #define gras_datadesc_by_symbol(name)  \
191   (gras_datadesc_by_name(#name) ?      \
192    gras_datadesc_by_name(#name) :      \
193      gras_datadesc_parse(#name,        \
194                          _gras_this_type_symbol_does_not_exist__##name) \
195   )
196
197 /*****************************
198  **** NWS datadescription ****
199  *****************************/
200
201 /**
202  * Basic types we can embeed in DataDescriptors.
203  */
204 typedef enum
205   {CHAR_TYPE, DOUBLE_TYPE, FLOAT_TYPE, INT_TYPE, LONG_TYPE, SHORT_TYPE,
206    UNSIGNED_INT_TYPE, UNSIGNED_LONG_TYPE, UNSIGNED_SHORT_TYPE, STRUCT_TYPE}
207   DataTypes;
208 #define SIMPLE_TYPE_COUNT 9
209
210 /*!  \brief Describe a collection of data.
211  * 
212 ** A description of a collection of #type# data.  #repetitions# is used only
213 ** for arrays; it contains the number of elements.  #offset# is used only for
214 ** struct members in host format; it contains the offset of the member from the
215 ** beginning of the struct, taking into account internal padding added by the
216 ** compiler for alignment purposes.  #members#, #length#, and #tailPadding# are
217 ** used only for STRUCT_TYPE data; the #length#-long array #members# describes
218 ** the members of the nested struct, and #tailPadding# indicates how many
219 ** padding bytes the compiler adds to the end of the structure.
220 */
221
222 typedef struct DataDescriptorStruct {
223   DataTypes type;
224   size_t repetitions;
225   size_t offset;
226   /*@null@*/ struct DataDescriptorStruct *members;
227   size_t length;
228   size_t tailPadding;
229 } DataDescriptor;
230 /** DataDescriptor for an array */
231 #define SIMPLE_DATA(type,repetitions) \
232   {type, repetitions, 0, NULL, 0, 0}
233 /** DataDescriptor for an structure member */
234 #define SIMPLE_MEMBER(type,repetitions,offset) \
235   {type, repetitions, offset, NULL, 0, 0}
236 /** DataDescriptor for padding bytes */
237 #define PAD_BYTES(structType,lastMember,memberType,repetitions) \
238   sizeof(structType) - offsetof(structType, lastMember) - \
239   sizeof(memberType) * repetitions
240
241 gras_error_t
242 gras_datadesc_import_nws(const char           *name,
243                          const DataDescriptor *desc,
244                          size_t                howmany,
245                          gras_datadesc_type_t **dst);
246
247 END_DECL
248
249 #endif /* GRAS_DATADESC_H */