1 /* datadesc - describing the data to exchange */
3 /* module's private interface masked even to other parts of XBT. */
5 /* Copyright (c) 2004, 2005, 2006, 2007, 2009, 2010. The SimGrid Team.
6 * All rights reserved. */
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. */
11 #ifndef XBT_DATADESC_PRIVATE_H
12 #define XBT_DATADESC_PRIVATE_H
14 #include "xbt/sysdep.h"
16 #include "xbt/dynar.h"
20 #include "gras_config.h" /* XBT_THISARCH */
21 #include "xbt_modinter.h" /* module init/exit */
22 #include "datadesc_interface.h" /* semi-public API */
27 * Align the data v on the boundary a.
29 #define ddt_aligned(v, a) (((v) + (a - 1)) & ~(a - 1))
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 *******************************************/
37 #define xbt_arch_count 12
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,
45 xbt_ddt_scalar_pdata = 5,
46 xbt_ddt_scalar_pfunc = 6,
48 xbt_ddt_scalar_float = 7,
49 xbt_ddt_scalar_double = 8
50 } xbt_ddt_scalar_type_t;
57 int sizeofs[9]; /* char,short,int,long,long_long,pdata,pfunc,float,double */
58 int boundaries[9]; /* idem */
61 extern const xbt_arch_desc_t xbt_arches[xbt_arch_count];
62 extern const char *xbt_datadesc_cat_names[9];
64 /**********************************************************/
65 /* Actual definitions of the stuff in the type descriptor */
66 /**********************************************************/
69 * e_xbt_datadesc_type_category:
71 * Defines all possible type categories.
73 typedef enum e_xbt_datadesc_type_category {
75 /* if you edit this, also fix xbt_datadesc_cat_names in ddt_exchange.c */
77 e_xbt_datadesc_type_cat_undefined = 0,
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,
85 e_xbt_datadesc_type_cat_invalid = 6
86 } xbt_datadesc_type_category_t;
88 /*------------------------------------------------*/
89 /* definitions of specific data for each category */
90 /*------------------------------------------------*/
94 * Fields of struct and union
96 typedef struct s_xbt_dd_cat_field {
99 long int offset[xbt_arch_count];
100 xbt_datadesc_type_t type;
102 xbt_datadesc_type_cb_void_t send;
103 xbt_datadesc_type_cb_void_t recv;
105 } s_xbt_dd_cat_field_t, *xbt_dd_cat_field_t;
107 void xbt_dd_cat_field_free(void *f);
110 * xbt_dd_cat_scalar_t:
112 * Specific fields of a scalar
114 enum e_xbt_dd_scalar_encoding {
115 e_xbt_dd_scalar_encoding_undefined = 0,
117 e_xbt_dd_scalar_encoding_uint,
118 e_xbt_dd_scalar_encoding_sint,
119 e_xbt_dd_scalar_encoding_float,
121 e_xbt_dd_scalar_encoding_invalid
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;
129 * xbt_dd_cat_struct_t:
131 * Specific fields of a struct
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;
139 * xbt_dd_cat_union_t:
141 * Specific fields of a union
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;
152 * Specific fields of a reference
154 typedef struct s_xbt_dd_cat_ref {
155 xbt_datadesc_type_t type;
157 /* callback used to return the referenced type number */
158 xbt_datadesc_selector_t selector;
163 * xbt_dd_cat_array_t:
165 * Specific fields of an array
167 typedef struct s_xbt_dd_cat_array {
168 xbt_datadesc_type_t type;
170 /* element_count == -1 means dynamically defined */
173 /* callback used to return the dynamic length */
174 xbt_datadesc_type_cb_int_t dynamic_size;
176 } xbt_dd_cat_array_t;
179 * u_xbt_datadesc_category:
181 * Specific data to each possible category
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;
192 /****************************************/
193 /* The holy grail: type descriptor type */
194 /****************************************/
196 * s_xbt_datadesc_type:
200 typedef struct s_xbt_datadesc_type {
201 /* headers for the data set */
204 unsigned int name_len;
207 long int size[xbt_arch_count]; /* Cannot be unsigned: -1 means dynamic */
209 unsigned long int alignment[xbt_arch_count];
210 unsigned long int aligned_size[xbt_arch_count];
212 enum e_xbt_datadesc_type_category category_code;
213 union u_xbt_datadesc_category category;
215 xbt_datadesc_type_cb_void_t send;
216 xbt_datadesc_type_cb_void_t recv;
221 /* random value for users (like default value or whatever) */
222 char extra[SIZEOF_MAX];
224 } s_xbt_datadesc_type_t;
226 /***************************
227 * constructor/desctructor *
228 ***************************/
229 void xbt_datadesc_free(xbt_datadesc_type_t * type);
232 xbt_datadesc_scalar(const char *name,
233 xbt_ddt_scalar_type_t type,
234 enum e_xbt_dd_scalar_encoding encoding);
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);
247 xbt_dd_convert_elm(xbt_datadesc_type_t type, int count,
248 int r_arch, void *src, void *dst);
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 */
255 #endif /* XBT_DATADESC_PRIVATE_H */