Logo AND Algorithmique Numérique Distribuée

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