Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
51c4c20603351cf24cb798e8755b45729a012e16
[simgrid.git] / include / gras / datadesc.h
1 /* $Id$ */
2
3 /* gras/datadesc.h - Describing the data you want to exchange               */
4
5 /* Copyright (c) 2003, 2004 Martin Quinson. All rights reserved.            */
6
7 /* This program is free software; you can redistribute it and/or modify it
8  * under the terms of the license (GNU LGPL) which comes with this package. */
9
10 #ifndef GRAS_DATADESC_H
11 #define GRAS_DATADESC_H
12
13 #include "xbt/misc.h" /* BEGIN_DECL */
14
15 BEGIN_DECL
16
17 /**
18  * gras_datadesc_type_t:
19  * 
20  * Opaque type describing a type description you don't want to open.
21  */
22 typedef struct s_gras_datadesc_type *gras_datadesc_type_t;
23
24 typedef struct s_gras_cbps *gras_cbps_t;
25
26 /* callbacks prototypes */
27 typedef void (*gras_datadesc_type_cb_void_t)(gras_cbps_t vars, void *data);
28 typedef int (*gras_datadesc_type_cb_int_t)(gras_cbps_t vars, void *data);
29 typedef gras_datadesc_type_t (*gras_datadesc_selector_t)(gras_cbps_t vars, void *data);
30
31 /***********************************************
32  **** Search and retrieve declared datatype ****
33  ***********************************************/
34 gras_datadesc_type_t gras_datadesc_by_name(const char *name);
35
36 /******************************************
37  **** Declare datadescription yourself ****
38  ******************************************/
39
40 gras_datadesc_type_t gras_datadesc_struct(const char *name);
41
42 void
43   gras_datadesc_struct_append(gras_datadesc_type_t  struct_type,
44                               const char           *name,
45                               gras_datadesc_type_t  field_type);
46 void
47   gras_datadesc_struct_close(gras_datadesc_type_t   struct_type);
48
49 gras_datadesc_type_t 
50   gras_datadesc_union(const char                   *name,
51                       gras_datadesc_type_cb_int_t   selector);
52 void
53   gras_datadesc_union_append(gras_datadesc_type_t   union_type,
54                              const char            *name,
55                              gras_datadesc_type_t   field_type);
56 void
57   gras_datadesc_union_close(gras_datadesc_type_t    union_type);
58
59 gras_datadesc_type_t 
60   gras_datadesc_ref(const char                     *name,
61                     gras_datadesc_type_t            referenced_type);
62 gras_datadesc_type_t 
63   gras_datadesc_ref_generic(const char                *name,
64                             gras_datadesc_selector_t   selector);
65
66 gras_datadesc_type_t 
67   gras_datadesc_array_fixed(const char             *name,
68                             gras_datadesc_type_t    element_type,
69                             long int                fixed_size);
70 gras_datadesc_type_t 
71   gras_datadesc_array_dyn(const char                 *name,
72                           gras_datadesc_type_t        element_type,
73                           gras_datadesc_type_cb_int_t dynamic_size);
74
75 gras_datadesc_type_t 
76   gras_datadesc_ref_pop_arr(gras_datadesc_type_t  element_type);
77
78 /*********************************
79  * Change stuff within datadescs *
80  *********************************/
81
82 void gras_datadesc_cycle_set(gras_datadesc_type_t type);
83 void gras_datadesc_cycle_unset(gras_datadesc_type_t type);
84
85 void gras_datadesc_cb_send (gras_datadesc_type_t         type,
86                             gras_datadesc_type_cb_void_t pre);
87 void gras_datadesc_cb_recv(gras_datadesc_type_t          type,
88                            gras_datadesc_type_cb_void_t  post);
89 void gras_datadesc_cb_field_send (gras_datadesc_type_t   type,
90                                   const char            *field_name,
91                                   gras_datadesc_type_cb_void_t  pre);
92 void gras_datadesc_cb_field_recv(gras_datadesc_type_t    type,
93                                  const char             *field_name,
94                                  gras_datadesc_type_cb_void_t  post);
95 void gras_datadesc_cb_field_push (gras_datadesc_type_t   type,
96                                   const char            *field_name);
97
98 /******************************
99  * Get stuff within datadescs *
100  ******************************/
101 char * gras_datadesc_get_name(gras_datadesc_type_t ddt);
102 int gras_datadesc_get_id(gras_datadesc_type_t ddt);
103
104 /********************************************************
105  * Advanced data describing: callback persistent states *
106  ********************************************************/
107 /* simple one: push/pop sizes of arrays */
108 void
109 gras_cbps_i_push(gras_cbps_t ps, int val);
110 int 
111 gras_cbps_i_pop(gras_cbps_t ps);
112
113 int gras_datadesc_cb_pop(gras_cbps_t vars, void *data);
114 void gras_datadesc_cb_push_int(gras_cbps_t vars, void *data);
115 void gras_datadesc_cb_push_uint(gras_cbps_t vars, void *data);
116 void gras_datadesc_cb_push_lint(gras_cbps_t vars, void *data);
117 void gras_datadesc_cb_push_ulint(gras_cbps_t vars, void *data);
118
119
120
121 /* complex one: complete variable environment support */
122 xbt_error_t
123   gras_cbps_v_pop (gras_cbps_t            ps, 
124                    const char            *name,
125          /* OUT */ gras_datadesc_type_t  *ddt,
126          /* OUT */ void                 **res);
127 xbt_error_t
128 gras_cbps_v_push(gras_cbps_t            ps,
129                  const char            *name,
130                  void                  *data,
131                  gras_datadesc_type_t   ddt);
132 void
133 gras_cbps_v_set (gras_cbps_t            ps,
134                  const char            *name,
135                  void                  *data,
136                  gras_datadesc_type_t   ddt);
137
138 void *
139 gras_cbps_v_get (gras_cbps_t            ps, 
140                  const char            *name,
141        /* OUT */ gras_datadesc_type_t  *ddt);
142
143 void
144 gras_cbps_block_begin(gras_cbps_t ps);
145 void
146 gras_cbps_block_end(gras_cbps_t ps);
147
148
149
150
151 /*******************************
152  **** About data convertion ****
153  *******************************/
154 int gras_arch_selfid(void); /* ID of this arch */
155
156 /****************************
157  **** Parse C statements ****
158  ****************************/
159 gras_datadesc_type_t 
160 gras_datadesc_parse(const char *name,
161                     const char *Cdefinition);
162 #define GRAS_DEFINE_TYPE(name,def) \
163   static const char * _gras_this_type_symbol_does_not_exist__##name=#def; def
164 #define GRAS_ANNOTE(key,val)
165  
166 #define gras_datadesc_by_symbol(name)  \
167   (gras_datadesc_by_name(#name) ?      \
168    gras_datadesc_by_name(#name) :      \
169      gras_datadesc_parse(#name,        \
170                          _gras_this_type_symbol_does_not_exist__##name) \
171   )
172
173 /*****************************
174  **** NWS datadescription ****
175  *****************************/
176
177 /**
178  * Basic types we can embeed in DataDescriptors.
179  */
180 typedef enum
181   {CHAR_TYPE, DOUBLE_TYPE, FLOAT_TYPE, INT_TYPE, LONG_TYPE, SHORT_TYPE,
182    UNSIGNED_INT_TYPE, UNSIGNED_LONG_TYPE, UNSIGNED_SHORT_TYPE, STRUCT_TYPE}
183   DataTypes;
184 #define SIMPLE_TYPE_COUNT 9
185
186 /*!  \brief Describe a collection of data.
187  * 
188 ** A description of a collection of #type# data.  #repetitions# is used only
189 ** for arrays; it contains the number of elements.  #offset# is used only for
190 ** struct members in host format; it contains the offset of the member from the
191 ** beginning of the struct, taking into account internal padding added by the
192 ** compiler for alignment purposes.  #members#, #length#, and #tailPadding# are
193 ** used only for STRUCT_TYPE data; the #length#-long array #members# describes
194 ** the members of the nested struct, and #tailPadding# indicates how many
195 ** padding bytes the compiler adds to the end of the structure.
196 */
197
198 typedef struct DataDescriptorStruct {
199   DataTypes type;
200   size_t repetitions;
201   size_t offset;
202   /*@null@*/ struct DataDescriptorStruct *members;
203   size_t length;
204   size_t tailPadding;
205 } DataDescriptor;
206 /** DataDescriptor for an array */
207 #define SIMPLE_DATA(type,repetitions) \
208   {type, repetitions, 0, NULL, 0, 0}
209 /** DataDescriptor for an structure member */
210 #define SIMPLE_MEMBER(type,repetitions,offset) \
211   {type, repetitions, offset, NULL, 0, 0}
212 /** DataDescriptor for padding bytes */
213 #define PAD_BYTES(structType,lastMember,memberType,repetitions) \
214   sizeof(structType) - offsetof(structType, lastMember) - \
215   sizeof(memberType) * repetitions
216
217 xbt_error_t
218 gras_datadesc_import_nws(const char           *name,
219                          const DataDescriptor *desc,
220                          unsigned long         howmany,
221                /* OUT */ gras_datadesc_type_t *dst);
222
223 END_DECL
224
225 #endif /* GRAS_DATADESC_H */