Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
0c1c802ec1b7967b8c5497f820f108638e989557
[simgrid.git] / src / xbt / datadesc / datadesc_private.h
1 /* datadesc - describing the data to exchange                               */
2
3 /* module's private interface masked even to other parts of XBT.           */
4
5 /* Copyright (c) 2004, 2005, 2006, 2007, 2009, 2010. The SimGrid Team.
6  * All rights reserved.                                                     */
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 XBT_DATADESC_PRIVATE_H
12 #define XBT_DATADESC_PRIVATE_H
13
14 #include "xbt/sysdep.h"
15 #include "xbt/log.h"
16 #include "xbt/dynar.h"
17 #include "xbt/dict.h"
18 #include "xbt/set.h"
19
20 #include "gras_config.h"        /* XBT_THISARCH */
21 #include "xbt_modinter.h"       /* module init/exit */
22 #include "datadesc_interface.h" /* semi-public API */
23
24 /**
25  * ddt_aligned:
26  *
27  * Align the data v on the boundary a.
28  */
29 #define ddt_aligned(v, a) (((v) + (a - 1)) & ~(a - 1))
30
31 /*@null@*/ extern xbt_set_t xbt_datadesc_set_local;
32 void xbt_ddt_freev(void *ddt);
33 /*******************************************
34  * Descriptions of all known architectures *
35  *******************************************/
36
37 #define xbt_arch_count 12
38 typedef enum {
39   xbt_ddt_scalar_char = 0,
40   xbt_ddt_scalar_short = 1,
41   xbt_ddt_scalar_int = 2,
42   xbt_ddt_scalar_long = 3,
43   xbt_ddt_scalar_long_long = 4,
44
45   xbt_ddt_scalar_pdata = 5,
46   xbt_ddt_scalar_pfunc = 6,
47
48   xbt_ddt_scalar_float = 7,
49   xbt_ddt_scalar_double = 8
50 } xbt_ddt_scalar_type_t;
51
52 typedef struct {
53   const char *name;
54
55   int endian;
56
57   int sizeofs[9];               /* char,short,int,long,long_long,pdata,pfunc,float,double */
58   int boundaries[9];            /* idem */
59 } xbt_arch_desc_t;
60
61 extern const xbt_arch_desc_t xbt_arches[xbt_arch_count];
62 extern const char *xbt_datadesc_cat_names[9];
63
64 /**********************************************************/
65 /* Actual definitions of the stuff in the type descriptor */
66 /**********************************************************/
67
68 /**
69  * e_xbt_datadesc_type_category:
70  *
71  * Defines all possible type categories.
72  */
73 typedef enum e_xbt_datadesc_type_category {
74
75   /* if you edit this, also fix xbt_datadesc_cat_names in ddt_exchange.c */
76
77   e_xbt_datadesc_type_cat_undefined = 0,
78
79   e_xbt_datadesc_type_cat_scalar = 1,
80   e_xbt_datadesc_type_cat_struct = 2,
81   e_xbt_datadesc_type_cat_union = 3,
82   e_xbt_datadesc_type_cat_ref = 4,     /* ref to an uniq element */
83   e_xbt_datadesc_type_cat_array = 5,
84
85   e_xbt_datadesc_type_cat_invalid = 6
86 } xbt_datadesc_type_category_t;
87
88 /*------------------------------------------------*/
89 /* definitions of specific data for each category */
90 /*------------------------------------------------*/
91 /**
92  * s_xbt_dd_cat_field:
93  *
94  * Fields of struct and union
95  */
96 typedef struct s_xbt_dd_cat_field {
97
98   char *name;
99   long int offset[xbt_arch_count];
100   xbt_datadesc_type_t type;
101
102   xbt_datadesc_type_cb_void_t send;
103   xbt_datadesc_type_cb_void_t recv;
104
105 } s_xbt_dd_cat_field_t, *xbt_dd_cat_field_t;
106
107 void xbt_dd_cat_field_free(void *f);
108
109 /**
110  * xbt_dd_cat_scalar_t:
111  *
112  * Specific fields of a scalar
113  */
114 enum e_xbt_dd_scalar_encoding {
115   e_xbt_dd_scalar_encoding_undefined = 0,
116
117   e_xbt_dd_scalar_encoding_uint,
118   e_xbt_dd_scalar_encoding_sint,
119   e_xbt_dd_scalar_encoding_float,
120
121   e_xbt_dd_scalar_encoding_invalid
122 };
123 typedef struct s_xbt_dd_cat_scalar {
124   enum e_xbt_dd_scalar_encoding encoding;
125   xbt_ddt_scalar_type_t type;  /* to check easily that redefinition matches */
126 } xbt_dd_cat_scalar_t;
127
128 /**
129  * xbt_dd_cat_struct_t:
130  *
131  * Specific fields of a struct
132  */
133 typedef struct s_xbt_dd_cat_struct {
134   xbt_dynar_t fields;           /* elm type = xbt_dd_cat_field_t */
135   int closed;                   /* xbt_datadesc_declare_struct_close() was called */
136 } xbt_dd_cat_struct_t;
137
138 /**
139  * xbt_dd_cat_union_t:
140  *
141  * Specific fields of a union
142  */
143 typedef struct s_xbt_dd_cat_union {
144   xbt_datadesc_type_cb_int_t selector;
145   xbt_dynar_t fields;           /* elm type = xbt_dd_cat_field_t */
146   int closed;                   /* xbt_datadesc_declare_union_close() was called */
147 } xbt_dd_cat_union_t;
148
149 /**
150  * xbt_dd_cat_ref_t:
151  *
152  * Specific fields of a reference
153  */
154 typedef struct s_xbt_dd_cat_ref {
155   xbt_datadesc_type_t type;
156
157   /* callback used to return the referenced type number  */
158   xbt_datadesc_selector_t selector;
159 } xbt_dd_cat_ref_t;
160
161
162 /**
163  * xbt_dd_cat_array_t:
164  *
165  * Specific fields of an array
166  */
167 typedef struct s_xbt_dd_cat_array {
168   xbt_datadesc_type_t type;
169
170   /* element_count == -1 means dynamically defined */
171   long int fixed_size;
172
173   /* callback used to return the dynamic length */
174   xbt_datadesc_type_cb_int_t dynamic_size;
175
176 } xbt_dd_cat_array_t;
177
178 /**
179  * u_xbt_datadesc_category:
180  *
181  * Specific data to each possible category
182  */
183 union u_xbt_datadesc_category {
184   void *undefined_data;
185   xbt_dd_cat_scalar_t scalar_data;
186   xbt_dd_cat_struct_t struct_data;
187   xbt_dd_cat_union_t union_data;
188   xbt_dd_cat_ref_t ref_data;
189   xbt_dd_cat_array_t array_data;
190 };
191
192 /****************************************/
193 /* The holy grail: type descriptor type */
194 /****************************************/
195 /**
196  * s_xbt_datadesc_type:
197  *
198  * Type descriptor.
199  */
200 typedef struct s_xbt_datadesc_type {
201   /* headers for the data set */
202   int code;
203   char *name;
204   unsigned int name_len;
205
206   /* payload */
207   long int size[xbt_arch_count];       /* Cannot be unsigned: -1 means dynamic */
208
209   unsigned long int alignment[xbt_arch_count];
210   unsigned long int aligned_size[xbt_arch_count];
211
212   enum e_xbt_datadesc_type_category category_code;
213   union u_xbt_datadesc_category category;
214
215   xbt_datadesc_type_cb_void_t send;
216   xbt_datadesc_type_cb_void_t recv;
217
218   /* flags */
219   int cycle:1;
220
221   /* random value for users (like default value or whatever) */
222   char extra[SIZEOF_MAX];
223
224 } s_xbt_datadesc_type_t;
225
226 /***************************
227  * constructor/desctructor *
228  ***************************/
229 void xbt_datadesc_free(xbt_datadesc_type_t * type);
230
231 xbt_datadesc_type_t
232 xbt_datadesc_scalar(const char *name,
233                      xbt_ddt_scalar_type_t type,
234                      enum e_xbt_dd_scalar_encoding encoding);
235
236 /****************************************************
237  * Callback persistent state constructor/destructor *
238  ****************************************************/
239 xbt_cbps_t xbt_cbps_new(void);
240 void xbt_cbps_free(xbt_cbps_t * state);
241 void xbt_cbps_reset(xbt_cbps_t state);
242
243 /***************
244  * Convertions *
245  ***************/
246 void
247 xbt_dd_convert_elm(xbt_datadesc_type_t type, int count,
248                     int r_arch, void *src, void *dst);
249
250 /********************************************************************
251  * Dictionnary containing the constant values for the parsing macro *
252  ********************************************************************/
253 extern xbt_dict_t xbt_dd_constants;    /* lives in ddt_parse.c of course */
254
255 #endif                          /* XBT_DATADESC_PRIVATE_H */