Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Simplify the mmalloc library further
[simgrid.git] / include / xbt / datadesc.h
1 /* xbt/datadesc.h - Describing the data you want to exchange               */
2
3 /* Copyright (c) 2004, 2005, 2006, 2007, 2009, 2010. The SimGrid Team.
4  * All rights reserved.                                                     */
5
6 /* This program is free software; you can redistribute it and/or modify it
7  * under the terms of the license (GNU LGPL) which comes with this package. */
8
9 #ifndef XBT_DATADESC_H
10 #define XBT_DATADESC_H
11
12 #include "xbt/misc.h"           /* SG_BEGIN_DECL */
13 #include "xbt/dynar.h"          /* void_f_pvoid_t */
14
15 SG_BEGIN_DECL()
16
17 /** @addtogroup XBT_dd Data description
18  *  @brief Describing data to be exchanged
19  *
20  * Since XBT takes care of potential representation conversion when the platform is heterogeneous,
21  * any data which transits on the network must be described beforehand.
22  * 
23  * There are several possible interfaces for this, ranging from the really completely automatic parsing to
24  * completely manual. Let's study each of them from the simplest to the more advanced:
25  * 
26  *   - Section \ref XBT_dd_basic presents how to retrieve and use an already described type.
27  *   - Section \ref XBT_dd_auto shows how to make XBT parse your type description automagically. This
28  *     is unfortunately not always possible (only works for some structures), but if it is for your data,
29  *     this is definitely the way to go.
30  *   - Section \ref XBT_dd_manual presents how to build a description manually. This is useful when you want
31  *     to describe an array or a pointer of pre-defined structures.
32  *   - You sometimes need to exchange informations between descriptions at send or receive time. This is 
33  *     for example useful when your structure contains an array which size is given by another field of the 
34  *     structure.
35  *     - Section \ref XBT_dd_cb_simple provides a simple interface to do so, allowing to share integers stored on a stack.
36  *     - Section \ref XBT_dd_cb_full provides a full featured interface to do so, but it may reveal somehow difficult to use.
37  **/
38 /** @defgroup XBT_dd_basic Basic operations on data descriptions
39  *  @ingroup XBT_dd
40  * \htmlonly <!-- DOXYGEN_NAVBAR_LABEL="Basics" --> \endhtmlonly
41  *
42  * If you only want to send pre-existing types, simply retrieve the pre-defined description with 
43  * the \ref xbt_datadesc_by_name function. Existing types entail:
44  *  - char (both signed and unsigned)
45  *  - int (short, regular, long and long long, both signed and unsigned)
46  *  - float and double
47  *  - string (which is indeed a reference to a dynamically sized array of char, strlen being used to retrieve the size)
48  * 
49  * Example:\verbatim xbt_datadesc_type_t i = xbt_datadesc_by_name("int");
50  xbt_datadesc_type_t uc = xbt_datadesc_by_name("unsigned char");
51  xbt_datadesc_type_t str = xbt_datadesc_by_name("string");\endverbatim
52  *
53  */
54 /* @{ */
55 /** @brief Opaque type describing a type description. */
56 typedef struct s_xbt_datadesc_type *xbt_datadesc_type_t;
57
58 /** \brief Search a type description from its name */
59 XBT_PUBLIC(xbt_datadesc_type_t) xbt_datadesc_by_name(const char *name);
60 XBT_PUBLIC(xbt_datadesc_type_t) xbt_datadesc_by_name_or_null(const char
61                                                                *name);
62
63 /* @} */
64
65 /** @defgroup XBT_dd_auto Automatic parsing of data descriptions
66  *  @ingroup XBT_dd
67  * \htmlonly <!-- DOXYGEN_NAVBAR_LABEL="Automatic parsing" --> \endhtmlonly
68  * 
69  *  If you need to declare a new datatype, this is the simplest way to describe it to XBT. Simply
70  *  enclose its type definition  into a \ref XBT_DEFINE_TYPE macro call, and you're set. Here is 
71  *  an type declaration  example: \verbatim XBT_DEFINE_TYPE(mytype,struct mytype {
72    int myfirstfield;
73    char mysecondfield;
74  });\endverbatim
75  *  The type is then both copied verbatim into your source file and stored for further parsing. This allows
76  *  you to let XBT parse the exact version you are actually using in your program.
77  *  You can then retrieve the corresponding type description with \ref xbt_datadesc_by_symbol.
78  *  Don't worry too much for the performances, the type is only parsed once and a binary representation 
79  *  is stored and used in any subsequent calls.
80  * 
81  *  If your structure contains any pointer, you have to explain XBT the size of the pointed array. This
82  *  can be 1 in the case of simple references, or more in the case of regular arrays. For that, use the 
83  *  \ref XBT_ANNOTE macro within the type declaration you are passing to \ref XBT_DEFINE_TYPE. This macro
84  *  rewrites itself to nothing in the declaration (so they won't pollute the type definition copied verbatim
85  *  into your code), and give some information to XBT about your pointer. 
86  
87  *  XBT_ANNOTE takes two arguments being the key name and the key value. For now, the only accepted key name 
88  *  is "size", to specify the length of the pointed array. It can either be:
89  *    - the string "1" (without the quote),
90  *    - the name of another field of the structure
91  *    - a sort of computed expression for multidimensional arrays (see below -- pay attention to the warnings below).
92  *  
93  *  Here is an example:\verbatim XBT_DEFINE_TYPE(s_clause,
94   struct s_array {
95     xbt_string_t name;
96     struct s_array *father XBT_ANNOTE(size,1);
97     int length;
98     int *data XBT_ANNOTE(size,length);
99     int rows;
100     int cols;
101     int *matrix XBT_ANNOTE(size,rows*cols);
102  }
103 ;)\endverbatim
104  * It specifies that the structure s_array contains six fields, that the \a name field is a classical null-terminated 
105  * char* string (#xbt_string_t is just an helper type defined exactly to help the parsing macro to specify the semantic of the pointer),
106  * that \a father field is a simple reference, that the size of the array pointed by \a data is the \a length field, and that the 
107  * \a matrix field is an arraywhich size is the result of \a rows times \a cols.
108  *
109  *  \warning Since XBT_DEFINE_TYPE is a macro, you shouldn't put any comma in your type definition 
110  *  (comma separates macro args). For example, change \verbatim int a, b;\endverbatim to \verbatim int a;
111 int b;\endverbatim
112  * 
113  * \section xbt_dd_define \#define and fixed size array
114  *
115  * If you want to exchange arrays which size is given at compilation time by a
116  * \#defined constant, you need to keep XBT informed. It would be done the
117  * following way:
118
119 \verbatim #define BLOCK_SIZE 32
120 XBT_DEFINE_TYPE(s_toto,
121 struct {
122   double data[BLOCK_SIZE];
123 } s_toto;)
124
125 void register_messages() { 
126   xbt_datadesc_type_t toto_type;
127
128   xbt_datadesc_set_const("BLOCK_SIZE",BLOCK_SIZE);
129   toto_type = xbt_datadesc_by_symbol(s_toto);
130 }\endverbatim
131  *
132  * The form <tt>xbt_datadesc_set_const("BLOCK_SIZE",BLOCK_SIZE);</tt> ensures
133  * that when you change the definition of the constant, XBT keeps informed of
134  * the right value. Passing the numerical value of the constant as second
135  * argument would be a bad idea to that regard. Of course, the call to
136  * xbt_datadesc_set_const() should come before any xbt_datadesc_by_symbol()
137  * containing references to it.
138  *
139  * \section XBT_dd_multidim Defining multidimentional arrays
140  * 
141  *  The mecanism for multidimensional arrays is known to be fragile and cumbersome. If you want to use it,
142  *  you have to understand how it is implemented: the multiplication is performed using the sizes stack. In previous example,
143  *  a \ref xbt_datadesc_cb_push_int callback is added to the \a rows field and a \ref xbt_datadesc_cb_push_int_mult one is
144  *  added to \a cols. So, when the structure is sent, the \a rows field push its value onto the stack, then the \a cols field
145  *  retrieve this value from the stack, compute (and push) the multiplication value. The \a matrix field can then retrieve this
146  *  value by poping the array. There is several ways for this to go wrong:
147  *   - if the matrix field is placed before the sizes, the right value won't get pushed into the stack soon enough.
148  *     Reorder your structure fields if needed.
149  *   - if you write XBT_ANNOTE(size,cols*rows); in previous example (inverting rows and cols in annotation),
150  *     \a rows will be given a \ref xbt_datadesc_cb_push_int_mult. This cannot work since it will try to
151  *     pop the value which will be pushed by \a cols <i>afterward</i>.
152  *   - if you have more than one matrix in your structure, don't interleave the size. They are pushed/poped in the structure order.
153  *   - if some of the sizes are used in more than one matrix, you cannot use this mecanism -- sorry.
154  *
155  * If you cannot express your datadescs with this mechanism, you'll have to use the more advanced
156  * (and somehow complex) one described in the \ref XBT_dd_cb_full.
157  *
158  * \section XBT_dd_multifile Projects spanning over multiple files
159  * 
160  * XBT_DEFINE_TYPE declares some symbols to work, it needs some special
161  * care when used in several files. In such case, you want the regular type
162  * definition in all files, but the xbt specific symbol defined in only
163  * one file. For example, consider the following xbt project sketch.
164  * 
165 \verbatim #include <xbt/datadesc.h>
166
167 XBT_DEFINE_TYPE(my_type,struct my_type {
168   int a;
169   int b;
170   double c;
171 });
172
173 int client(int argc, char *argv[]) {
174  ...
175 }
176
177 int server(int argc, char *argv[]) {
178  ...
179 }\endverbatim
180  * 
181  * If you want to split this in two files (one for each kind of processes),
182  * you need to put the XBT_DEFINE_TYPE block in a separate header (so that
183  * each process kind see the associated C type definition). But
184  * then you cannot include this right away in all files because the extra
185  * symbols containing the XBT definition would be dupplicated.
186  * 
187  * You thus have to decide in which C file the symbols will live. In that
188  * file, include the header without restriction:
189  * 
190 \verbatim #include "my_header.h"
191
192 int client(int argc, char *argv[]) {
193   ...
194 }\endverbatim
195
196  * And in the other files needing the C definitions without the extra XBT
197  * symbols, declare the symbol XBT_DEFINE_TYPE_EXTERN before loading
198  * xbt/datadesc.h:
199  * 
200 \verbatim #define XBT_DEFINE_TYPE_EXTERN
201 #include <xbt/datadesc.h>
202 #include "my_header.h"
203
204 int server(int argc, char *argv[]) {
205   ...
206 }\endverbatim
207
208  * 
209  * Sometimes, the situation is even more complicated: There is some shared
210  * messages that you want to see from every file, and some private messages 
211  * that you want to be defined only in one C file.
212  * In that case, use the previous trick for common messages, and use 
213  * #XBT_DEFINE_TYPE_LOCAL for the private messages.
214  *
215  * For now, there is no way to have semi-private symbols (for example shared 
216  * in all files of a library), sorry. Use functions as interface to your 
217  * library instead of publishing directly the messages.
218  * 
219  */
220 /** @{ */
221
222
223 /**   @brief Automatically parse C code
224  *    @hideinitializer
225  */
226 #define XBT_DEFINE_TYPE(name,def) \
227   const char * _xbt_this_type_symbol_does_not_exist__##name=#def; def
228
229 #ifndef DOXYGEN_SKIP            /* doxygen don't like macro fun too much */
230 #  ifdef XBT_DEFINE_TYPE_EXTERN
231 #    undef  XBT_DEFINE_TYPE
232 #    define XBT_DEFINE_TYPE(name,def)  def
233 #    undef XBT_DEFINE_TYPE_EXTERN
234 #  endif
235 #endif
236
237 /**   @brief if this symbol is defined, the \a XBT_DEFINE_TYPE symbols live in another file.
238  *    @hideinitializer
239  */
240 #define XBT_DEFINE_TYPE_EXTERN 1
241 /* leave the fun of declaring this to the user */
242 #undef XBT_DEFINE_TYPE_EXTERN
243
244 /** @brief Define a symbol to be automatically parsed, disregarding #XBT_DEFINE_TYPE_EXTERN
245  *  @hideinitializer
246  * 
247  *  Call this macro instead of #XBT_DEFINE_TYPE if you had to define #XBT_DEFINE_TYPE_EXTERN
248  *  to load some external symbols, but if you now want to automatically parse the content of 
249  *  your private messages.
250  */
251 #define XBT_DEFINE_TYPE_LOCAL(name, def) \
252   const char * _xbt_this_type_symbol_does_not_exist__##name=#def; def
253
254 /** @brief Retrieve a datadesc which was previously parsed 
255  *  @hideinitializer
256  */
257 #define xbt_datadesc_by_symbol(name)  \
258   (xbt_datadesc_by_name_or_null(#name) ?      \
259    xbt_datadesc_by_name_or_null(#name) :      \
260      xbt_datadesc_parse(#name,        \
261                          _xbt_this_type_symbol_does_not_exist__##name) \
262   )
263
264 /** @def XBT_ANNOTE
265  *  @brief Add an annotation to a type to be automatically parsed
266  */
267 #define XBT_ANNOTE(key,val)
268
269 /** @brief Defines the value of a define to the datatype parsing infrastructure
270  */
271 XBT_PUBLIC(void) xbt_datadesc_set_const(const char *name, int value);
272
273 /* @} */
274
275 XBT_PUBLIC(xbt_datadesc_type_t)
276     xbt_datadesc_parse(const char *name, const char *C_statement);
277
278 /** @defgroup XBT_dd_manual Simple manual data description
279  *  @ingroup XBT_dd
280  * 
281  * Here are the functions to use if you want to declare your description manually. 
282  * The function names should be self-explanatory in most cases.
283  * 
284  * You can add callbacks to the datatypes doing any kind of action you may want. Usually, 
285  * pre-send callbacks are used to prepare the type expedition while post-receive callbacks 
286  * are used to fix any issue after the receive.
287  * 
288  * If your types are dynamic, you'll need to add some extra callback. For example, there is a
289  * specific callback for the string type which is in charge of computing the length of the char
290  * array. This is done with the cbps mechanism, explained in next section.
291  * 
292  * If your types may contain pointer cycle, you must specify it to XBT using the @ref xbt_datadesc_cycle_set.
293  * 
294  * Example:\verbatim
295  typedef struct {
296    unsigned char c1;
297    unsigned long int l1;
298    unsigned char c2;
299    unsigned long int l2;
300  } mystruct;
301  [...]
302   my_type=xbt_datadesc_struct("mystruct");
303   xbt_datadesc_struct_append(my_type,"c1", xbt_datadesc_by_name("unsigned char"));
304   xbt_datadesc_struct_append(my_type,"l1", xbt_datadesc_by_name("unsigned long"));
305   xbt_datadesc_struct_append(my_type,"c2", xbt_datadesc_by_name("unsigned char"));
306   xbt_datadesc_struct_append(my_type,"l2", xbt_datadesc_by_name("unsigned long int"));
307   xbt_datadesc_struct_close(my_type);
308
309   my_type=xbt_datadesc_ref("mystruct*", xbt_datadesc_by_name("mystruct"));
310
311   [Use my_type to send pointers to mystruct data]\endverbatim
312  */
313 /* @{ */
314
315
316 /** \brief Opaque type describing a type description callback persistant state. */
317 typedef struct s_xbt_cbps *xbt_cbps_t;
318
319 /* callbacks prototypes */
320 /** \brief Prototype of type callbacks returning nothing. */
321 typedef void (*xbt_datadesc_type_cb_void_t) (xbt_datadesc_type_t
322                                               typedesc, xbt_cbps_t vars,
323                                               void *data);
324 /** \brief Prototype of type callbacks returning an int. */
325 typedef int (*xbt_datadesc_type_cb_int_t) (xbt_datadesc_type_t
326                                            typedesc, xbt_cbps_t vars,
327                                            void *data);
328 /** \brief Prototype of type callbacks selecting a type. */
329 typedef
330
331
332
333
334
335 xbt_datadesc_type_t(*xbt_datadesc_selector_t) (xbt_datadesc_type_t
336                                                  typedesc,
337                                                  xbt_cbps_t vars,
338                                                  void *data);
339
340
341 /******************************************
342  **** Declare datadescription yourself ****
343  ******************************************/
344
345 XBT_PUBLIC(xbt_datadesc_type_t) xbt_datadesc_struct(const char *name);
346 XBT_PUBLIC(void) xbt_datadesc_struct_append(xbt_datadesc_type_t
347                                              struct_type, const char *name,
348                                              xbt_datadesc_type_t
349                                              field_type);
350 XBT_PUBLIC(void) xbt_datadesc_struct_close(xbt_datadesc_type_t
351                                             struct_type);
352
353
354 XBT_PUBLIC(xbt_datadesc_type_t) xbt_datadesc_union(const char *name,
355                                                      xbt_datadesc_type_cb_int_t
356                                                      selector);
357 XBT_PUBLIC(void) xbt_datadesc_union_append(xbt_datadesc_type_t
358                                             union_type, const char *name,
359                                             xbt_datadesc_type_t
360                                             field_type);
361 XBT_PUBLIC(void) xbt_datadesc_union_close(xbt_datadesc_type_t
362                                            union_type);
363
364
365 XBT_PUBLIC(xbt_datadesc_type_t)
366     xbt_datadesc_ref(const char *name, xbt_datadesc_type_t referenced_type);
367 XBT_PUBLIC(xbt_datadesc_type_t)
368     xbt_datadesc_copy(const char *name, xbt_datadesc_type_t copied_type);
369 XBT_PUBLIC(xbt_datadesc_type_t)
370     xbt_datadesc_ref_generic(const char *name,
371                           xbt_datadesc_selector_t selector);
372
373 XBT_PUBLIC(xbt_datadesc_type_t)
374     xbt_datadesc_array_fixed(const char *name,
375                           xbt_datadesc_type_t element_type,
376                           long int fixed_size);
377 XBT_PUBLIC(xbt_datadesc_type_t)
378     xbt_datadesc_array_dyn(const char *name,
379                         xbt_datadesc_type_t element_type,
380                         xbt_datadesc_type_cb_int_t dynamic_size);
381 XBT_PUBLIC(xbt_datadesc_type_t)
382     xbt_datadesc_ref_pop_arr(xbt_datadesc_type_t element_type);
383
384 XBT_PUBLIC(xbt_datadesc_type_t)
385     xbt_datadesc_dynar(xbt_datadesc_type_t elm_t, void_f_pvoid_t free_func);
386 XBT_PUBLIC(xbt_datadesc_type_t)
387     xbt_datadesc_matrix(xbt_datadesc_type_t elm_t,
388                      void_f_pvoid_t const free_f);
389
390 /*********************************
391  * Change stuff within datadescs *
392  *********************************/
393
394 /** \brief Specify that this type may contain cycles */
395 XBT_PUBLIC(void) xbt_datadesc_cycle_set(xbt_datadesc_type_t type);
396 /** \brief Specify that this type do not contain any cycles (default) */
397 XBT_PUBLIC(void) xbt_datadesc_cycle_unset(xbt_datadesc_type_t type);
398 /** \brief Add a pre-send callback to this datadesc. */
399 XBT_PUBLIC(void) xbt_datadesc_cb_send(xbt_datadesc_type_t type,
400                                       xbt_datadesc_type_cb_void_t pre);
401 /** \brief Add a post-receive callback to this datadesc.*/
402 XBT_PUBLIC(void) xbt_datadesc_cb_recv(xbt_datadesc_type_t type,
403                                       xbt_datadesc_type_cb_void_t post);
404 /** \brief Add a pre-send callback to the given field of the datadesc */
405 XBT_PUBLIC(void) xbt_datadesc_cb_field_send(xbt_datadesc_type_t type,
406                                             const char *field_name,
407                                             xbt_datadesc_type_cb_void_t
408                                             pre);
409 /** \brief Add a post-receive callback to the given field of the datadesc */
410 XBT_PUBLIC(void) xbt_datadesc_cb_field_recv(xbt_datadesc_type_t type,
411                                             const char *field_name,
412                                             xbt_datadesc_type_cb_void_t
413                                             post);
414 /** \brief Add a pre-send callback to the given field resulting in its value to be pushed */
415 XBT_PUBLIC(void) xbt_datadesc_cb_field_push(xbt_datadesc_type_t type,
416                                             const char *field_name);
417 /** \brief Add a pre-send callback to the given field resulting in its value multiplied to any previously pushed value and then pushed back */
418 XBT_PUBLIC(void)
419 xbt_datadesc_cb_field_push_multiplier(xbt_datadesc_type_t type,
420                                       const char
421                                       *field_name);
422
423 /******************************
424  * Get stuff within datadescs *
425  ******************************/
426 /** \brief Returns the name of a datadescription */
427 XBT_PUBLIC(const char *) xbt_datadesc_get_name(xbt_datadesc_type_t ddt);
428 /** \brief Returns the identifier of a datadescription */
429 XBT_PUBLIC(int) xbt_datadesc_get_id(xbt_datadesc_type_t ddt);
430
431 /* @} */
432
433 /** @defgroup XBT_dd_cb_simple Data description with Callback Persistant State: Simple push/pop mechanism
434  *  @ingroup XBT_dd
435  * 
436  * Sometimes, one of the callbacks need to leave information for the next ones. If this is a simple integer (such as
437  * an array size), you can use the functions described here. If not, you'll have to play with the complete cbps interface.
438  *
439  * \htmlonly <!--  DOXYGEN_NAVBAR_LABEL="Simple push/pop Callback State" -->\endhtmlonly      
440  * 
441  * Here is an example:\verbatim
442 struct s_array {
443   int length;
444   int *data;
445 }
446 [...]
447 my_type=xbt_datadesc_struct("s_array");
448 xbt_datadesc_struct_append(my_type,"length", xbt_datadesc_by_name("int"));
449 xbt_datadesc_cb_field_send (my_type, "length", xbt_datadesc_cb_push_int);
450
451 xbt_datadesc_struct_append(my_type,"data",
452                             xbt_datadesc_array_dyn ("s_array::data",xbt_datadesc_by_name("int"), xbt_datadesc_cb_pop));
453 xbt_datadesc_struct_close(my_type);
454 \endverbatim
455
456  *
457  * The *_mult versions are intended for multi-dimensional arrays: They multiply their value to the previously pushed one 
458  * (by another field callback) and push the result of the multiplication back. An example of use follows. Please note
459  * that the first field needs a regular push callback, not a multiplier one. Think of it as a stacked calculator (man dc(1)).\verbatim
460 struct s_matrix {
461   int row;
462   int col;
463   int *data;
464 }
465 [...]
466 my_type=xbt_datadesc_struct("s_matrix");
467 xbt_datadesc_struct_append(my_type,"row", xbt_datadesc_by_name("int"));
468 xbt_datadesc_cb_field_send (my_type, "length", xbt_datadesc_cb_push_int);
469 xbt_datadesc_struct_append(my_type,"col", xbt_datadesc_by_name("int"));
470 xbt_datadesc_cb_field_send (my_type, "length", xbt_datadesc_cb_push_int_mult);
471
472 xbt_datadesc_struct_append(my_type,"data",
473                             xbt_datadesc_array_dyn ("s_matrix::data",xbt_datadesc_by_name("int"), xbt_datadesc_cb_pop));
474 xbt_datadesc_struct_close(my_type);
475 \endverbatim
476  
477  */
478 /* @{ */
479
480 XBT_PUBLIC(void) xbt_cbps_i_push(xbt_cbps_t ps, int val);
481 XBT_PUBLIC(int) xbt_cbps_i_pop(xbt_cbps_t ps);
482
483 XBT_PUBLIC(int) xbt_datadesc_cb_pop(xbt_datadesc_type_t typedesc,
484                                      xbt_cbps_t vars, void *data);
485
486 XBT_PUBLIC(void) xbt_datadesc_cb_push_int(xbt_datadesc_type_t typedesc,
487                                            xbt_cbps_t vars, void *data);
488 XBT_PUBLIC(void) xbt_datadesc_cb_push_uint(xbt_datadesc_type_t typedesc,
489                                             xbt_cbps_t vars, void *data);
490 XBT_PUBLIC(void) xbt_datadesc_cb_push_lint(xbt_datadesc_type_t typedesc,
491                                             xbt_cbps_t vars, void *data);
492 XBT_PUBLIC(void) xbt_datadesc_cb_push_ulint(xbt_datadesc_type_t typedesc,
493                                              xbt_cbps_t vars, void *data);
494
495 XBT_PUBLIC(void) xbt_datadesc_cb_push_int_mult(xbt_datadesc_type_t
496                                                 typedesc, xbt_cbps_t vars,
497                                                 void *data);
498 XBT_PUBLIC(void) xbt_datadesc_cb_push_uint_mult(xbt_datadesc_type_t
499                                                  typedesc,
500                                                  xbt_cbps_t vars,
501                                                  void *data);
502 XBT_PUBLIC(void) xbt_datadesc_cb_push_lint_mult(xbt_datadesc_type_t
503                                                  typedesc,
504                                                  xbt_cbps_t vars,
505                                                  void *data);
506 XBT_PUBLIC(void) xbt_datadesc_cb_push_ulint_mult(xbt_datadesc_type_t
507                                                   typedesc,
508                                                   xbt_cbps_t vars,
509                                                   void *data);
510
511
512 /* @} */
513
514 /** @defgroup XBT_dd_cb_full Data description with Callback Persistant State: Full featured interface
515  *  @ingroup XBT_dd
516  * 
517  * Sometimes, one of the callbacks need to leave information for the next
518  * ones. If the simple push/pop mechanism introduced in previous section
519  * isn't enough, you can always use this full featured one. The bad point is
520  * that it is quite badly documented...
521  *
522  * \htmlonly <!--  DOXYGEN_NAVBAR_LABEL="Full featured Callback State" -->\endhtmlonly      
523  *
524  */
525
526 /* @{ */
527
528 XBT_PUBLIC(void) xbt_cbps_v_pop(xbt_cbps_t ps, const char *name,
529                                  /* OUT */ xbt_datadesc_type_t * ddt,
530                                  /* OUT */ void **res);
531 XBT_PUBLIC(void) xbt_cbps_v_push(xbt_cbps_t ps,
532                                   const char *name,
533                                   void *data, xbt_datadesc_type_t ddt);
534 XBT_PUBLIC(void) xbt_cbps_v_set(xbt_cbps_t ps,
535                                  const char *name,
536                                  void *data, xbt_datadesc_type_t ddt);
537
538 XBT_PUBLIC(void *) xbt_cbps_v_get(xbt_cbps_t ps, const char *name,
539                                    /* OUT */ xbt_datadesc_type_t * ddt);
540
541 XBT_PUBLIC(void) xbt_cbps_block_begin(xbt_cbps_t ps);
542 XBT_PUBLIC(void) xbt_cbps_block_end(xbt_cbps_t ps);
543
544 /* @} */
545 /* @} */
546
547
548 /*******************************
549  **** About data convertion ****
550  *******************************/
551 XBT_PUBLIC(int) xbt_arch_selfid(void); /* ID of this arch */
552
553
554 /*****************************
555  **** NWS datadescription * FIXME: obsolete?
556  *****************************/
557
558 /**
559  * Basic types we can embeed in DataDescriptors.
560  */
561 typedef enum
562     { CHAR_TYPE, DOUBLE_TYPE, FLOAT_TYPE, INT_TYPE, LONG_TYPE, SHORT_TYPE,
563   UNSIGNED_INT_TYPE, UNSIGNED_LONG_TYPE, UNSIGNED_SHORT_TYPE, STRUCT_TYPE
564 } DataTypes;
565 #define SIMPLE_TYPE_COUNT 9
566
567 /**  \brief Describe a collection of data.
568  * 
569 ** A description of a collection of \a type data.  \a repetitions is used only
570 ** for arrays; it contains the number of elements.  \a offset is used only for
571 ** struct members in host format; it contains the offset of the member from the
572 ** beginning of the struct, taking into account internal padding added by the
573 ** compiler for alignment purposes.  \a members, \a length, and \a tailPadding are
574 ** used only for STRUCT_TYPE data; the \a length -long array \a members describes
575 ** the members of the nested struct, and \a tailPadding indicates how many
576 ** padding bytes the compiler adds to the end of the structure.
577 */
578
579 typedef struct DataDescriptorStruct {
580   DataTypes type;
581   size_t repetitions;
582   size_t offset;
583   /*@null@ */ struct DataDescriptorStruct *members;
584   size_t length;
585   size_t tailPadding;
586 } DataDescriptor;
587 /** DataDescriptor for an array */
588 #define SIMPLE_DATA(type,repetitions) \
589   {type, repetitions, 0, NULL, 0, 0}
590 /** DataDescriptor for an structure member */
591 #define SIMPLE_MEMBER(type,repetitions,offset) \
592   {type, repetitions, offset, NULL, 0, 0}
593 /** DataDescriptor for padding bytes */
594 #define PAD_BYTES(structType,lastMember,memberType,repetitions) \
595   sizeof(structType) - offsetof(structType, lastMember) - \
596   sizeof(memberType) * repetitions
597
598 XBT_PUBLIC(xbt_datadesc_type_t)
599     xbt_datadesc_import_nws(const char *name,
600                          const DataDescriptor * desc,
601                          unsigned long howmany);
602
603
604 SG_END_DECL()
605 #endif                          /* XBT_DATADESC_H */