3 /* gras/datadesc.h - Describing the data you want to exchange */
5 /* Authors: Martin Quinson */
6 /* Copyright (C) 2003 the OURAGAN project. */
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 GRAS_DATADESC_H
12 #define GRAS_DATADESC_H
14 #include <stddef.h> /* offsetof() */
15 #include <sys/types.h> /* size_t */
19 /*! C++ users need love */
22 # define BEGIN_DECL extern "C" {
28 /*! C++ users need love */
36 /* End of cruft for C++ */
41 * Basic types we can embeed in DataDescriptors.
44 {CHAR_TYPE, DOUBLE_TYPE, FLOAT_TYPE, INT_TYPE, LONG_TYPE, SHORT_TYPE,
45 UNSIGNED_INT_TYPE, UNSIGNED_LONG_TYPE, UNSIGNED_SHORT_TYPE, STRUCT_TYPE}
47 #define SIMPLE_TYPE_COUNT 9
49 /*! \brief Describe a collection of data.
51 ** A description of a collection of #type# data. #repetitions# is used only
52 ** for arrays; it contains the number of elements. #offset# is used only for
53 ** struct members in host format; it contains the offset of the member from the
54 ** beginning of the struct, taking into account internal padding added by the
55 ** compiler for alignment purposes. #members#, #length#, and #tailPadding# are
56 ** used only for STRUCT_TYPE data; the #length#-long array #members# describes
57 ** the members of the nested struct, and #tailPadding# indicates how many
58 ** padding bytes the compiler adds to the end of the structure.
61 typedef struct DataDescriptorStruct {
65 /*@null@*/ struct DataDescriptorStruct *members;
69 /** DataDescriptor for an array */
70 #define SIMPLE_DATA(type,repetitions) \
71 {type, repetitions, 0, NULL, 0, 0}
72 /** DataDescriptor for an structure member */
73 #define SIMPLE_MEMBER(type,repetitions,offset) \
74 {type, repetitions, offset, NULL, 0, 0}
75 /** DataDescriptor for padding bytes */
76 #define PAD_BYTES(structType,lastMember,memberType,repetitions) \
77 sizeof(structType) - offsetof(structType, lastMember) - \
78 sizeof(memberType) * repetitions
81 gras_error_t gras_datadesc_parse(const char *def,
82 gras_datadesc__t **dst);
83 gras_error_t gras_datadesc_from_nws(const DataDescriptor *desc,
85 gras_datadesc_t **dst);
86 gras_error_t gras_datadesc_eq(const gras_datadesc_t *d1,
87 const gras_datadesc_t *d2);
88 gras_error_t gras_datadesc_cpy(gras_datadesc_t *src,
89 gras_datadesc_t **dst);
90 gras_error_t gras_datadesc_sizeof_host(gras_datadesc_t *desc,
92 gras_error_t gras_datadesc_sizeof_network(gras_datadesc_t *desc,
96 typedef struct s_gras_datadesc_type gras_datadesc_type_t;
98 typedef void (*gras_datadesc_type_cb_void_t)(void *vars,
99 gras_datadesc_type_t *p_type,
101 typedef int (*gras_datadesc_type_cb_int_t)(void *vars,
102 gras_datadesc_type_t *p_type,
107 /* Create a new type and register it on the local machine */
108 #define gras_datadesc_declare_struct( name, code) \
109 gras_datadesc_declare_struct_cb(name, NULL, NULL, code)
111 #define gras_datadesc_declare_struct_add_name( struct_code,field_name,field_type_name) \
112 gras_datadesc_declare_struct_add_name_cb(struct_code,field_name,field_type_name, NULL, NULL)
114 #define gras_datadesc_declare_struct_add_code( struct_code,field_name,field_type_code) \
115 gras_datadesc_declare_struct_add_code_cb(struct_code,field_name,field_type_code, NULL, NULL)
118 gras_datadesc_declare_struct_cb(const char *name,
119 gras_datadesc_type_cb_void_t pre_cb,
120 gras_datadesc_type_cb_void_t post_cb,
123 gras_datadesc_declare_struct_add_name_cb(long int struct_code,
124 const char *field_name,
125 const char *field_type_name,
126 gras_datadesc_type_cb_void_t pre_cb,
127 gras_datadesc_type_cb_void_t post_cb);
130 gras_datadesc_declare_struct_add_code_cb(long int struct_code,
131 const char *field_name,
133 gras_datadesc_type_cb_void_t pre_cb,
134 gras_datadesc_type_cb_void_t post_cb);
136 #define gras_datadesc_declare_union( name, code) \
137 gras_datadesc_declare_union_cb(name, NULL, NULL, code)
139 #define gras_datadesc_declare_union_add_name( union_code,field_name,field_type_name) \
140 gras_datadesc_declare_union_add_name_cb(union_code,field_name,field_type_name, NULL, NULL)
142 #define gras_datadesc_declare_union_add_code( union_code,field_name,field_type_code) \
143 gras_datadesc_declare_union_add_code_cb(union_code,field_name,field_type_code, NULL, NULL)
146 gras_datadesc_declare_union_cb(const char *name,
147 gras_datadesc_type_cb_int_t field_count,
148 gras_datadesc_type_cb_void_t post,
151 gras_datadesc_declare_union_add_name_cb(long int union_code,
152 const char *field_name,
153 const char *field_type_name,
154 gras_datadesc_type_cb_void_t pre_cb,
155 gras_datadesc_type_cb_void_t post_cb);
157 gras_datadesc_declare_union_add_code_cb(long int union_code,
158 const char *field_name,
160 gras_datadesc_type_cb_void_t pre_cb,
161 gras_datadesc_type_cb_void_t post_cb);
163 #define gras_datadesc_declare_ref(name,ref_type, code) \
164 gras_datadesc_declare_ref_cb(name, ref_type, NULL, NULL, code)
165 #define gras_datadesc_declare_ref_disc(name,discriminant, code) \
166 gras_datadesc_declare_ref_cb(name, NULL, discriminant, NULL, code)
169 gras_datadesc_declare_ref_cb(const char *name,
170 gras_datadesc_type_t *referenced_type,
171 gras_datadesc_type_cb_int_t discriminant,
172 gras_datadesc_type_cb_void_t post,
175 #define gras_datadesc_declare_array(name,elm_type, size, code) \
176 gras_datadesc_declare_array_cb(name, elm_type, size, NULL, NULL, code)
177 #define gras_datadesc_declare_array_dyn(name,elm_type, dynamic_size, code) \
178 gras_datadesc_declare_array_cb(name, elm_type, -1, dynamic_size, NULL, code)
181 gras_datadesc_declare_array_cb(const char *name,
182 gras_datadesc_type_t *element_type,
184 gras_datadesc_type_cb_int_t dynamic_size,
185 gras_datadesc_type_cb_void_t post,
190 #endif /* GRAS_DATADESC_H */