Logo AND Algorithmique Numérique Distribuée

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