Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Kill old $Id$ command dating from CVS
[simgrid.git] / src / gras / DataDesc / datadesc_private.h
1 /* datadesc - describing the data to exchange                               */
2
3 /* module's private interface masked even to other parts of GRAS.           */
4
5 /* Copyright (c) 2003 Olivier Aumage.                                       */
6 /* Copyright (c) 2003, 2004 Martin Quinson.                                 */
7 /* All rights reserved.                                                     */
8
9 /* This program is free software; you can redistribute it and/or modify it
10  * under the terms of the license (GNU LGPL) which comes with this package. */
11
12 #ifndef GRAS_DATADESC_PRIVATE_H
13 #define GRAS_DATADESC_PRIVATE_H
14
15 #include "xbt/sysdep.h"
16 #include "xbt/log.h"
17 #include "xbt/dynar.h"
18 #include "xbt/dict.h"
19 #include "xbt/set.h"
20
21 #include "portable.h"           /* GRAS_THISARCH */
22
23 #include "gras/transport.h"     /* socket handling */
24
25 #include "gras_modinter.h"      /* module init/exit */
26 #include "gras/datadesc.h"      /* rest of module public interface */
27
28 #include "gras/DataDesc/datadesc_interface.h"   /* semi-public API */
29
30 /**
31  * ddt_aligned:
32  *
33  * Align the data v on the boundary a.
34  */
35 #define ddt_aligned(v, a) (((v) + (a - 1)) & ~(a - 1))
36
37 /*@null@*/ extern xbt_set_t gras_datadesc_set_local;
38 void gras_ddt_freev(void *ddt);
39 /*******************************************
40  * Descriptions of all known architectures *
41  *******************************************/
42
43 #define gras_arch_count 11
44 typedef enum {
45   gras_ddt_scalar_char = 0,
46   gras_ddt_scalar_short = 1,
47   gras_ddt_scalar_int = 2,
48   gras_ddt_scalar_long = 3,
49   gras_ddt_scalar_long_long = 4,
50
51   gras_ddt_scalar_pdata = 5,
52   gras_ddt_scalar_pfunc = 6,
53
54   gras_ddt_scalar_float = 7,
55   gras_ddt_scalar_double = 8
56 } gras_ddt_scalar_type_t;
57
58 typedef struct {
59   const char *name;
60
61   int endian;
62
63   int sizeofs[9];               /* char,short,int,long,long_long,pdata,pfunc,float,double */
64   int boundaries[9];            /* idem */
65 } gras_arch_desc_t;
66
67 extern const gras_arch_desc_t gras_arches[gras_arch_count];
68 extern const char *gras_datadesc_cat_names[9];
69
70 /**********************************************************/
71 /* Actual definitions of the stuff in the type descriptor */
72 /**********************************************************/
73
74 /**
75  * e_gras_datadesc_type_category:
76  *
77  * Defines all possible type categories.
78  */
79 typedef enum e_gras_datadesc_type_category {
80
81   /* if you edit this, also fix gras_datadesc_cat_names in ddt_exchange.c */
82
83   e_gras_datadesc_type_cat_undefined = 0,
84
85   e_gras_datadesc_type_cat_scalar = 1,
86   e_gras_datadesc_type_cat_struct = 2,
87   e_gras_datadesc_type_cat_union = 3,
88   e_gras_datadesc_type_cat_ref = 4,     /* ref to an uniq element */
89   e_gras_datadesc_type_cat_array = 5,
90
91   e_gras_datadesc_type_cat_invalid = 6
92 } gras_datadesc_type_category_t;
93
94 /*------------------------------------------------*/
95 /* definitions of specific data for each category */
96 /*------------------------------------------------*/
97 /**
98  * s_gras_dd_cat_field:
99  *
100  * Fields of struct and union
101  */
102 typedef struct s_gras_dd_cat_field {
103
104   char *name;
105   long int offset[gras_arch_count];
106   gras_datadesc_type_t type;
107
108   gras_datadesc_type_cb_void_t send;
109   gras_datadesc_type_cb_void_t recv;
110
111 } s_gras_dd_cat_field_t, *gras_dd_cat_field_t;
112
113 void gras_dd_cat_field_free(void *f);
114
115 /**
116  * gras_dd_cat_scalar_t:
117  *
118  * Specific fields of a scalar
119  */
120 enum e_gras_dd_scalar_encoding {
121   e_gras_dd_scalar_encoding_undefined = 0,
122
123   e_gras_dd_scalar_encoding_uint,
124   e_gras_dd_scalar_encoding_sint,
125   e_gras_dd_scalar_encoding_float,
126
127   e_gras_dd_scalar_encoding_invalid
128 };
129 typedef struct s_gras_dd_cat_scalar {
130   enum e_gras_dd_scalar_encoding encoding;
131   gras_ddt_scalar_type_t type;  /* to check easily that redefinition matches */
132 } gras_dd_cat_scalar_t;
133
134 /**
135  * gras_dd_cat_struct_t:
136  *
137  * Specific fields of a struct
138  */
139 typedef struct s_gras_dd_cat_struct {
140   xbt_dynar_t fields;           /* elm type = gras_dd_cat_field_t */
141   int closed;                   /* gras_datadesc_declare_struct_close() was called */
142 } gras_dd_cat_struct_t;
143
144 /**
145  * gras_dd_cat_union_t:
146  *
147  * Specific fields of a union
148  */
149 typedef struct s_gras_dd_cat_union {
150   gras_datadesc_type_cb_int_t selector;
151   xbt_dynar_t fields;           /* elm type = gras_dd_cat_field_t */
152   int closed;                   /* gras_datadesc_declare_union_close() was called */
153 } gras_dd_cat_union_t;
154
155 /**
156  * gras_dd_cat_ref_t:
157  *
158  * Specific fields of a reference
159  */
160 typedef struct s_gras_dd_cat_ref {
161   gras_datadesc_type_t type;
162
163   /* callback used to return the referenced type number  */
164   gras_datadesc_selector_t selector;
165 } gras_dd_cat_ref_t;
166
167
168 /**
169  * gras_dd_cat_array_t:
170  *
171  * Specific fields of an array
172  */
173 typedef struct s_gras_dd_cat_array {
174   gras_datadesc_type_t type;
175
176   /* element_count == -1 means dynamically defined */
177   long int fixed_size;
178
179   /* callback used to return the dynamic length */
180   gras_datadesc_type_cb_int_t dynamic_size;
181
182 } gras_dd_cat_array_t;
183
184 /**
185  * u_gras_datadesc_category:
186  *
187  * Specific data to each possible category
188  */
189 union u_gras_datadesc_category {
190   void *undefined_data;
191   gras_dd_cat_scalar_t scalar_data;
192   gras_dd_cat_struct_t struct_data;
193   gras_dd_cat_union_t union_data;
194   gras_dd_cat_ref_t ref_data;
195   gras_dd_cat_array_t array_data;
196 };
197
198 /****************************************/
199 /* The holy grail: type descriptor type */
200 /****************************************/
201 /**
202  * s_gras_datadesc_type:
203  *
204  * Type descriptor.
205  */
206 typedef struct s_gras_datadesc_type {
207   /* headers for the data set */
208   int code;
209   char *name;
210   unsigned int name_len;
211
212   /* payload */
213   long int size[gras_arch_count];       /* Cannot be unsigned: -1 means dynamic */
214
215   unsigned long int alignment[gras_arch_count];
216   unsigned long int aligned_size[gras_arch_count];
217
218   enum e_gras_datadesc_type_category category_code;
219   union u_gras_datadesc_category category;
220
221   gras_datadesc_type_cb_void_t send;
222   gras_datadesc_type_cb_void_t recv;
223
224   /* flags */
225   int cycle:1;
226
227   /* random value for users (like default value or whatever) */
228   char extra[SIZEOF_MAX];
229
230 } s_gras_datadesc_type_t;
231
232 /***************************
233  * constructor/desctructor *
234  ***************************/
235 void gras_datadesc_free(gras_datadesc_type_t * type);
236
237 gras_datadesc_type_t
238 gras_datadesc_scalar(const char *name,
239                      gras_ddt_scalar_type_t type,
240                      enum e_gras_dd_scalar_encoding encoding);
241
242 /****************************************************
243  * Callback persistant state constructor/destructor *
244  ****************************************************/
245 gras_cbps_t gras_cbps_new(void);
246 void gras_cbps_free(gras_cbps_t * state);
247 void gras_cbps_reset(gras_cbps_t state);
248
249 /***************
250  * Convertions *
251  ***************/
252 void
253 gras_dd_convert_elm(gras_datadesc_type_t type, int count,
254                     int r_arch, void *src, void *dst);
255
256 /********************************************************************
257  * Dictionnary containing the constant values for the parsing macro *
258  ********************************************************************/
259 extern xbt_dict_t gras_dd_constants;    /* lives in ddt_parse.c of course */
260
261 #endif /* GRAS_DATADESC_PRIVATE_H */