Logo AND Algorithmique Numérique Distribuée

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