Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
split process.h (init/exit process; get/set userdata) out of core.h (unsorted stuff)
[simgrid.git] / include / datadesc_simple.h
1 /* $Id$ */
2
3 /* gras/datadesc.h - Describing the data you want to exchange               */
4
5 /* Authors: Martin Quinson                                                  */
6 /* Copyright (C) 2003 the OURAGAN project.                                  */
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_SIMPLE_H
12 #define GRAS_DATADESC_SIMPLE_H
13
14 #include <stddef.h>    /* offsetof() */
15 #include <sys/types.h>  /* size_t */
16 #include <stdarg.h>
17
18
19 /*! C++ users need love */
20 #ifndef BEGIN_DECL
21 # ifdef __cplusplus
22 #  define BEGIN_DECL extern "C" {
23 # else
24 #  define BEGIN_DECL 
25 # endif
26 #endif
27
28 /*! C++ users need love */
29 #ifndef END_DECL
30 # ifdef __cplusplus
31 #  define END_DECL }
32 # else
33 #  define END_DECL 
34 # endif
35 #endif
36 /* End of cruft for C++ */
37
38 BEGIN_DECL
39
40 /****
41  **** The NWS type and constructors 
42  ****/
43
44 typedef enum
45   {CHAR_TYPE, DOUBLE_TYPE, FLOAT_TYPE, INT_TYPE, LONG_TYPE, SHORT_TYPE,
46    UNSIGNED_INT_TYPE, UNSIGNED_LONG_TYPE, UNSIGNED_SHORT_TYPE, STRUCT_TYPE}
47   DataTypes;
48 #define SIMPLE_TYPE_COUNT 9
49
50 typedef struct DataDescriptorStruct {
51   DataTypes type;
52   size_t repetitions;
53   size_t offset;
54   struct DataDescriptorStruct *members;
55   size_t length;
56   size_t tailPadding;
57 } DataDescriptor;
58 #ifndef NULL
59 #define NULL 0
60 #endif
61 #define SIMPLE_DATA(type,repetitions) {type, repetitions, 0, NULL, 0, 0}
62 #define SIMPLE_MEMBER(type,repetitions,offset) \
63   {type, repetitions, offset, NULL, 0, 0}
64 #define PAD_BYTES(structType,lastMember,memberType,repetitions) \
65   sizeof(structType) - offsetof(structType, lastMember) - \
66   sizeof(memberType) * repetitions
67
68 /****
69  **** Gras (opaque) type, constructors and functions
70  ****/
71
72 typedef struct gras_datadesc_ gras_datadesc_t;
73
74 /* constructors, memory management */
75 gras_error_t gras_datadesc_parse(const char       *def,
76                                  gras_datadesc_t **dst);
77 gras_error_t gras_datadesc_from_nws(const DataDescriptor *desc,
78                                     size_t                howmany,
79                                     gras_datadesc_t     **dst);
80
81 gras_error_t gras_datadesc_cpy(gras_datadesc_t  *src,
82                                gras_datadesc_t **dst);
83 void         gras_datadesc_free(gras_datadesc_t **dd);
84
85 /* basic functionnalities */
86 int          gras_datadesc_cmp(const gras_datadesc_t *d1,
87                                const gras_datadesc_t *d2);
88
89 gras_error_t gras_datadesc_sizeof_host(gras_datadesc_t *desc,
90                                        size_t          *dst);
91 gras_error_t gras_datadesc_sizeof_network(gras_datadesc_t *desc,
92                                           size_t          *dst);
93
94 /* high level function needed in SG */
95 gras_error_t gras_datadesc_data_cpy(const gras_datadesc_t *dd,
96                                     const void *src,
97                                     void **dst);
98
99 /* high level functions needed in RL */
100 gras_error_t gras_datadesc_convert_recv(const gras_datadesc_t *dd,
101                                         gras_trp_plugin_t *trp,
102                                         void **dst);
103 gras_error_t gras_datadesc_convert_send(const gras_datadesc_t *dd,
104                                         gras_trp_plugin_t *trp,
105                                         void *src);
106
107 END_DECL
108
109 #endif /* GRAS_DATADESC_SIMPLE_H */
110