Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Version 0.5 (protocol not changed; ABI changed)
[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
114 /******************************
115  * Get stuff within datadescs *
116  ******************************/
117 char * gras_datadesc_get_name(gras_datadesc_type_t *ddt);
118 int gras_datadesc_get_id(gras_datadesc_type_t *ddt);
119
120 /********************************************************
121  * Advanced data describing: callback persistent states *
122  ********************************************************/
123 /* simple one: push/pop sizes of arrays */
124 void
125 gras_cbps_i_push(gras_cbps_t *ps, int val);
126 int 
127 gras_cbps_i_pop(gras_cbps_t *ps);
128 int gras_datadesc_cb_pop(gras_cbps_t *vars, void *data);
129
130 /* complex one: complete variable environment support */
131 gras_error_t
132 gras_cbps_v_pop (gras_cbps_t        *ps, 
133                     const char            *name,
134                     gras_datadesc_type_t **ddt,
135                   void                 **res);
136 gras_error_t
137 gras_cbps_v_push(gras_cbps_t        *ps,
138                     const char            *name,
139                     void                  *data,
140                     gras_datadesc_type_t  *ddt);
141 void
142 gras_cbps_v_set (gras_cbps_t        *ps,
143                     const char            *name,
144                     void                  *data,
145                     gras_datadesc_type_t  *ddt);
146
147 void *
148 gras_cbps_v_get (gras_cbps_t        *ps, 
149                     const char            *name,
150                     gras_datadesc_type_t **ddt);
151
152 void
153 gras_cbps_block_begin(gras_cbps_t *ps);
154 void
155 gras_cbps_block_end(gras_cbps_t *ps);
156
157
158
159
160 /*******************************
161  **** About data convertion ****
162  *******************************/
163 int gras_arch_selfid(void); /* ID of this arch */
164
165 /****************************
166  **** Parse C statements ****
167  ****************************/
168 gras_datadesc_type_t *
169 gras_datadesc_parse(const char *name,
170                     const char *Cdefinition);
171 #define GRAS_DEFINE_TYPE(name,def) \
172   static const char * _gras_this_type_symbol_does_not_exist__##name=#def; def
173  
174 #define gras_datadesc_by_symbol(name)  \
175   (gras_datadesc_by_name(#name) ?      \
176    gras_datadesc_by_name(#name) :      \
177      gras_datadesc_parse(#name,        \
178                          _gras_this_type_symbol_does_not_exist__##name) \
179   )
180
181 /*****************************
182  **** NWS datadescription ****
183  *****************************/
184
185 /**
186  * Basic types we can embeed in DataDescriptors.
187  */
188 typedef enum
189   {CHAR_TYPE, DOUBLE_TYPE, FLOAT_TYPE, INT_TYPE, LONG_TYPE, SHORT_TYPE,
190    UNSIGNED_INT_TYPE, UNSIGNED_LONG_TYPE, UNSIGNED_SHORT_TYPE, STRUCT_TYPE}
191   DataTypes;
192 #define SIMPLE_TYPE_COUNT 9
193
194 /*!  \brief Describe a collection of data.
195  * 
196 ** A description of a collection of #type# data.  #repetitions# is used only
197 ** for arrays; it contains the number of elements.  #offset# is used only for
198 ** struct members in host format; it contains the offset of the member from the
199 ** beginning of the struct, taking into account internal padding added by the
200 ** compiler for alignment purposes.  #members#, #length#, and #tailPadding# are
201 ** used only for STRUCT_TYPE data; the #length#-long array #members# describes
202 ** the members of the nested struct, and #tailPadding# indicates how many
203 ** padding bytes the compiler adds to the end of the structure.
204 */
205
206 typedef struct DataDescriptorStruct {
207   DataTypes type;
208   size_t repetitions;
209   size_t offset;
210   /*@null@*/ struct DataDescriptorStruct *members;
211   size_t length;
212   size_t tailPadding;
213 } DataDescriptor;
214 /** DataDescriptor for an array */
215 #define SIMPLE_DATA(type,repetitions) \
216   {type, repetitions, 0, NULL, 0, 0}
217 /** DataDescriptor for an structure member */
218 #define SIMPLE_MEMBER(type,repetitions,offset) \
219   {type, repetitions, offset, NULL, 0, 0}
220 /** DataDescriptor for padding bytes */
221 #define PAD_BYTES(structType,lastMember,memberType,repetitions) \
222   sizeof(structType) - offsetof(structType, lastMember) - \
223   sizeof(memberType) * repetitions
224
225 gras_error_t
226 gras_datadesc_import_nws(const char           *name,
227                          const DataDescriptor *desc,
228                          size_t                howmany,
229                          gras_datadesc_type_t **dst);
230
231 END_DECL
232
233 #endif /* GRAS_DATADESC_H */