Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
split process.h (init/exit process; get/set userdata) out of core.h (unsorted stuff)
[simgrid.git] / include / 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 the OURAGAN project.                                  */
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  * Basic types we can embeed in DataDescriptors.
42  */
43 typedef enum
44   {CHAR_TYPE, DOUBLE_TYPE, FLOAT_TYPE, INT_TYPE, LONG_TYPE, SHORT_TYPE,
45    UNSIGNED_INT_TYPE, UNSIGNED_LONG_TYPE, UNSIGNED_SHORT_TYPE, STRUCT_TYPE}
46   DataTypes;
47 #define SIMPLE_TYPE_COUNT 9
48
49 /*!  \brief Describe a collection of data.
50  * 
51 ** A description of a collection of #type# data.  #repetitions# is used only
52 ** for arrays; it contains the number of elements.  #offset# is used only for
53 ** struct members in host format; it contains the offset of the member from the
54 ** beginning of the struct, taking into account internal padding added by the
55 ** compiler for alignment purposes.  #members#, #length#, and #tailPadding# are
56 ** used only for STRUCT_TYPE data; the #length#-long array #members# describes
57 ** the members of the nested struct, and #tailPadding# indicates how many
58 ** padding bytes the compiler adds to the end of the structure.
59 */
60
61 typedef struct DataDescriptorStruct {
62   DataTypes type;
63   size_t repetitions;
64   size_t offset;
65   /*@null@*/ struct DataDescriptorStruct *members;
66   size_t length;
67   size_t tailPadding;
68 } DataDescriptor;
69 /** DataDescriptor for an array */
70 #define SIMPLE_DATA(type,repetitions) \
71   {type, repetitions, 0, NULL, 0, 0}
72 /** DataDescriptor for an structure member */
73 #define SIMPLE_MEMBER(type,repetitions,offset) \
74   {type, repetitions, offset, NULL, 0, 0}
75 /** DataDescriptor for padding bytes */
76 #define PAD_BYTES(structType,lastMember,memberType,repetitions) \
77   sizeof(structType) - offsetof(structType, lastMember) - \
78   sizeof(memberType) * repetitions
79
80 /*
81 gras_error_t gras_datadesc_parse(const char       *def,
82                                  gras_datadesc__t **dst);
83 gras_error_t gras_datadesc_from_nws(const DataDescriptor *desc,
84                                     size_t                howmany,
85                                     gras_datadesc_t     **dst);
86 gras_error_t gras_datadesc_sizeof_host(gras_datadesc_t *desc,
87                                        size_t          *dst);
88 gras_error_t gras_datadesc_sizeof_network(gras_datadesc_t *desc,
89                                           size_t          *dst);
90 */
91
92 typedef struct s_gras_datadesc_type gras_datadesc_type_t;
93
94 typedef void (*gras_datadesc_type_cb_void_t)(void                 *vars,
95                                              gras_datadesc_type_t *p_type,
96                                              void                 *data);
97 typedef int (*gras_datadesc_type_cb_int_t)(void                 *vars,
98                                            gras_datadesc_type_t *p_type,
99                                            void                 *data);
100
101
102
103 /* Create a new type and register it on the local machine */
104 #define gras_datadesc_declare_struct(   name,             code) \
105         gras_datadesc_declare_struct_cb(name, NULL, NULL, code)
106
107 #define gras_datadesc_declare_struct_add_name(   struct_code,field_name,field_type_name) \
108         gras_datadesc_declare_struct_add_name_cb(struct_code,field_name,field_type_name, NULL, NULL)
109
110 #define gras_datadesc_declare_struct_add_code(   struct_code,field_name,field_type_code) \
111         gras_datadesc_declare_struct_add_code_cb(struct_code,field_name,field_type_code, NULL, NULL)
112
113 gras_error_t 
114 gras_datadesc_declare_struct_cb(const char                   *name,
115                                 gras_datadesc_type_cb_void_t  pre_cb,
116                                 gras_datadesc_type_cb_void_t  post_cb,
117                                 long int                     *code);
118 gras_error_t 
119 gras_datadesc_declare_struct_add_name_cb(long int                      struct_code,
120                                          const char                   *field_name,
121                                          const char                   *field_type_name,
122                                          gras_datadesc_type_cb_void_t  pre_cb,
123                                          gras_datadesc_type_cb_void_t  post_cb);
124
125 gras_error_t 
126 gras_datadesc_declare_struct_add_code_cb(long int                      struct_code,
127                                          const char                   *field_name,
128                                          long int                      field_code,
129                                          gras_datadesc_type_cb_void_t  pre_cb,
130                                          gras_datadesc_type_cb_void_t  post_cb);
131 /* union */
132 #define gras_datadesc_declare_union(   name,             code) \
133         gras_datadesc_declare_union_cb(name, NULL, NULL, code)
134
135 #define gras_datadesc_declare_union_add_name(   union_code,field_name,field_type_name) \
136         gras_datadesc_declare_union_add_name_cb(union_code,field_name,field_type_name, NULL, NULL)
137
138 #define gras_datadesc_declare_union_add_code(   union_code,field_name,field_type_code) \
139         gras_datadesc_declare_union_add_code_cb(union_code,field_name,field_type_code, NULL, NULL)
140
141 gras_error_t 
142 gras_datadesc_declare_union_cb(const char                   *name,
143                                gras_datadesc_type_cb_int_t   field_count,
144                                gras_datadesc_type_cb_void_t  post,
145                                long int                     *code);
146 gras_error_t 
147 gras_datadesc_declare_union_add_name_cb(long int                      union_code,
148                                         const char                   *field_name,
149                                         const char                   *field_type_name,
150                                         gras_datadesc_type_cb_void_t  pre_cb,
151                                         gras_datadesc_type_cb_void_t  post_cb);
152 gras_error_t 
153 gras_datadesc_declare_union_add_code_cb(long int                      union_code,
154                                         const char                   *field_name,
155                                         long int                      field_code,
156                                         gras_datadesc_type_cb_void_t  pre_cb,
157                                         gras_datadesc_type_cb_void_t  post_cb);
158 /* ref */
159 #define gras_datadesc_declare_ref(name,ref_type, code) \
160         gras_datadesc_declare_ref_cb(name, ref_type, NULL, NULL, code)
161 #define gras_datadesc_declare_ref_disc(name,discriminant, code) \
162         gras_datadesc_declare_ref_cb(name, NULL, discriminant,  NULL, code)
163
164 gras_error_t
165 gras_datadesc_declare_ref_cb(const char                      *name,
166                              gras_datadesc_type_t            *referenced_type,
167                              gras_datadesc_type_cb_int_t      discriminant,
168                              gras_datadesc_type_cb_void_t     post,
169                              long int                        *code);
170 /* array */
171 #define gras_datadesc_declare_array(name,elm_type, size, code) \
172         gras_datadesc_declare_array_cb(name, elm_type, size, NULL,         NULL, code)
173 #define gras_datadesc_declare_array_dyn(name,elm_type, dynamic_size, code) \
174         gras_datadesc_declare_array_cb(name, elm_type, -1,   dynamic_size, NULL, code)
175
176 gras_error_t 
177 gras_datadesc_declare_array_cb(const char                      *name,
178                                gras_datadesc_type_t            *element_type,
179                                long int                         fixed_size,
180                                gras_datadesc_type_cb_int_t      dynamic_size,
181                                gras_datadesc_type_cb_void_t     post,
182                                long int                        *code);
183
184
185 /* Use the datadescriptions */
186 int
187 gras_datadesc_type_cmp(const gras_datadesc_type_t *d1,
188                        const gras_datadesc_type_t *d2);
189
190
191 gras_error_t 
192 gras_datadesc_cpy(gras_datadesc_type_t *type, void *src, void **dst);
193
194
195 END_DECL
196
197 #endif /* GRAS_DATADESC_H */