2 * $Id: cdr.h,v 0.0.0.1 2004/11/26
4 * -------------------------------------------------------------------
6 * Open Real-Time Ethernet
8 * Copyright (C) 2001-2006
9 * Department of Control Engineering FEE CTU Prague, Czech Republic
10 * http://dce.felk.cvut.cz
11 * http://www.ocera.org
13 * Author: Petr Smolik petr@smoliku.cz
15 * Project Responsible: Zdenek Hanzalek
16 * --------------------------------------------------------------------
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * Original of source was from ORBit: A CORBA v2.2 ORB
33 #include "basic_types.h"
36 * Alignment of CORBA types mapped to C.
37 * These have *nothing* to do with CDR alignment.
39 #define ORTE_ALIGNOF_CORBA_OCTET 1
40 #define ORTE_ALIGNOF_CORBA_BOOLEAN 1
41 #define ORTE_ALIGNOF_CORBA_CHAR 1
42 #define ORTE_ALIGNOF_CORBA_WCHAR 2
43 #define ORTE_ALIGNOF_CORBA_SHORT 2
44 #define ORTE_ALIGNOF_CORBA_LONG 4
45 #define ORTE_ALIGNOF_CORBA_LONG_LONG 8
46 #define ORTE_ALIGNOF_CORBA_FLOAT 4
47 #define ORTE_ALIGNOF_CORBA_DOUBLE 8
48 #define ORTE_ALIGNOF_CORBA_LONG_DOUBLE 16
49 #define ORTE_ALIGNOF_CORBA_STRUCT 1
50 #define ORTE_ALIGNOF_CORBA_POINTER 4
58 * struct CDR_Codec - used for serialization/deserialization
61 * @buffer: buffer for data
62 * @buf_len: buffer length
63 * @wptr_max: maximal size of writing data
64 * @wptr: write pointer
66 * @readonly: readonly attribute
67 * @release_buffer: use CORBA_TRUE if is necessary to free buffer memory after destruction of structure
69 * Struct @CDR_Codec is used by serialization and deserialization functions.
71 typedef struct CDR_Codec {
72 CDR_Endianness host_endian;
73 CDR_Endianness data_endian;
76 unsigned int wptr_max;
79 CORBA_boolean readonly;
80 CORBA_boolean release_buffer;
83 #define HEXDIGIT(c) (isdigit((guchar)(c)) ? (c)-'0' : tolower((guchar)(c))-'a'+10)
84 #define HEXOCTET(a, b) ((HEXDIGIT((a)) << 4) | HEXDIGIT((b)))
87 CDR_buffer_init(CDR_Codec *codec, const unsigned int size);
91 CDR_codec_init_static(CDR_Codec *codec);
93 CDR_codec_release_buffer(CDR_Codec *codec);
95 CDR_codec_free(CDR_Codec *);
98 CDR_buffer_puts(CDR_Codec *codec, const void *data, const unsigned int len);
100 CDR_buffer_gets(CDR_Codec *codec, void *dest, const unsigned int len);
103 CDR_put_short(CDR_Codec *codec, CORBA_short s);
105 CDR_put_ushort(CDR_Codec *codec, CORBA_unsigned_short us);
107 CDR_put_long(CDR_Codec *codec, CORBA_long l);
109 CDR_put_ulong(CDR_Codec *codec, CORBA_unsigned_long ul);
110 #ifdef HAVE_CORBA_LONG_LONG
112 CDR_put_long_long(CDR_Codec *codec, CORBA_long_long ll);
114 CDR_put_ulong_long(CDR_Codec *codec, CORBA_unsigned_long_long ull);
116 CDR_get_ulong_long(CDR_Codec *codec, CORBA_unsigned_long_long *ul);
118 CDR_get_long_long(CDR_Codec *codec, CORBA_long_long *ul);
121 CDR_put_float(CDR_Codec *codec, CORBA_float f);
123 CDR_put_double(CDR_Codec *codec, CORBA_double d);
125 CDR_put_long_double(CDR_Codec *codec, CORBA_long_double ld);
127 CDR_put_octet(CDR_Codec *codec, CORBA_octet datum);
129 CDR_put_octets(CDR_Codec *codec, void *data, unsigned long len);
131 CDR_put_char(CDR_Codec *codec, CORBA_char c);
133 CDR_put_boolean(CDR_Codec *codec, CORBA_boolean datum);
135 CDR_put_string(CDR_Codec *codec, const char *str);
137 CDR_buffer_gets(CDR_Codec *codec, void *dest, const unsigned int len);
139 CDR_get_short(CDR_Codec *codec, CORBA_short *us);
141 CDR_get_ushort(CDR_Codec *codec, CORBA_unsigned_short *us);
143 CDR_get_long(CDR_Codec *codec, CORBA_long *l);
145 CDR_get_ulong(CDR_Codec *codec, CORBA_unsigned_long *ul);
147 CDR_get_octet(CDR_Codec *codec, CORBA_octet *datum);
149 CDR_get_boolean(CDR_Codec *codec, CORBA_boolean *b);
151 CDR_get_char(CDR_Codec *codec, CORBA_char *c);
153 CDR_get_string(CDR_Codec *codec, CORBA_char **str);
155 CDR_get_string_buff(CDR_Codec *codec, CORBA_char *str);
157 CDR_get_string_static(CDR_Codec *codec, CORBA_char **str);
159 CDR_get_seq_begin(CDR_Codec *codec, CORBA_unsigned_long *ul);
161 CDR_get_float(CDR_Codec *codec, CORBA_float *f);
163 CDR_get_double(CDR_Codec *codec, CORBA_double *d);
166 /* serialization functions */
167 #define CORBA_short_serialize(x, y) CDR_put_short((x), *(y))
168 #define CORBA_long_serialize(x, y) CDR_put_long((x), *(y))
169 #define CORBA_unsigned_short_serialize(x, y) CDR_put_ushort((x), *(y))
170 #define CORBA_unsigned_long_serialize(x, y) CDR_put_ulong((x), *(y))
171 #define CORBA_float_serialize(x, y) CDR_put_float((x), *(y))
172 #define CORBA_double_serialize(x, y) CDR_put_double((x), *(y))
173 #define CORBA_char_serialize(x, y) CDR_put_char((x), *(y))
174 #define CORBA_boolean_serialize(x, y) CDR_put_boolean((x), *(y))
175 #define CORBA_octet_serialize(x, y) CDR_put_octet((x), *(y))
176 #define CORBA_long_double_serialize(x, y) CDR_put_long_double((x), *(y))
177 #define CORBA_string_serialize(x, y) CDR_put_string((x), *(y))
179 /* deserialization functions */
180 #define CORBA_short_deserialize(x, y) CDR_get_short((x), (y))
181 #define CORBA_long_deserialize(x, y) CDR_get_long((x), (y))
182 #define CORBA_unsigned_short_deserialize(x, y) CDR_get_ushort((x), (y))
183 #define CORBA_unsigned_long_deserialize(x, y) CDR_get_ulong((x), (y))
184 #define CORBA_float_deserialize(x, y) CDR_get_float((x), (y))
185 #define CORBA_double_deserialize(x, y) CDR_get_double((x), (y))
186 #define CORBA_char_deserialize(x, y) CDR_get_char((x), (y))
187 #define CORBA_boolean_deserialize(x, y) CDR_get_boolean((x), (y))
188 #define CORBA_octet_deserialize(x, y) CDR_get_octet((x), (y))
189 #define CORBA_long_double_deserialize(x, y) CDR_get_long_double((x), (y))
190 #define CORBA_string_deserialize(x, y) CDR_get_string((x), (y))
192 /* get_max_size functions */
193 #define CORBA_short_get_max_size(x, num) ((x)->csize = \
194 (unsigned long)ALIGN_ADDRESS((x)->csize, ORTE_ALIGNOF_CORBA_SHORT)+(num)*ORTE_ALIGNOF_CORBA_SHORT)
195 #define CORBA_long_get_max_size(x, num) ((x)->csize = \
196 (unsigned long)ALIGN_ADDRESS((x)->csize, ORTE_ALIGNOF_CORBA_LONG)+(num)*ORTE_ALIGNOF_CORBA_LONG)
197 #define CORBA_unsigned_short_get_max_size(x, num) ((x)->csize = \
198 (unsigned long)ALIGN_ADDRESS((x)->csize, ORTE_ALIGNOF_CORBA_SHORT)+(num)*ORTE_ALIGNOF_CORBA_SHORT)
199 #define CORBA_unsigned_long_get_max_size(x, num) ((x)->csize = \
200 (unsigned long)ALIGN_ADDRESS((x)->csize, ORTE_ALIGNOF_CORBA_LONG)+(num)*ORTE_ALIGNOF_CORBA_LONG)
201 #define CORBA_float_get_max_size(x, num) ((x)->csize = \
202 (unsigned long)ALIGN_ADDRESS((x)->csize, ORTE_ALIGNOF_CORBA_FLOAT)+(num)*ORTE_ALIGNOF_CORBA_FLOAT)
203 #define CORBA_double_get_max_size(x, num) ((x)->csize = \
204 (unsigned long)ALIGN_ADDRESS((x)->csize, ORTE_ALIGNOF_CORBA_DOUBLE)+(num)*ORTE_ALIGNOF_CORBA_DOUBLE)
205 #define CORBA_char_get_max_size(x, num) ((x)->csize = \
206 (unsigned long)ALIGN_ADDRESS((x)->csize, ORTE_ALIGNOF_CORBA_CHAR)+(num)*ORTE_ALIGNOF_CORBA_CHAR)
207 #define CORBA_boolean_get_max_size(x, num) ((x)->csize = \
208 (unsigned long)ALIGN_ADDRESS((x)->csize, ORTE_ALIGNOF_CORBA_BOOLEAN)+(num)*ORTE_ALIGNOF_CORBA_BOOLEAN)
209 #define CORBA_octet_get_max_size(x, num) ((x)->csize = \
210 (unsigned long)ALIGN_ADDRESS((x)->csize, ORTE_ALIGNOF_CORBA_OCTET)+(num)*ORTE_ALIGNOF_CORBA_OCTET)
211 #define CORBA_long_double_get_max_size(x, num) ((x)->csize = \
212 (unsigned long)ALIGN_ADDRESS((x)->csize, ORTE_ALIGNOF_CORBA_LONG_DOUBLE)+(num)*ORTE_ALIGNOF_CORBA_DOUBLE)
213 #define CORBA_string_get_max_size(x, y) \
214 ((x)->csize = (unsigned long)ALIGN_ADDRESS((x)->csize, ORTE_ALIGNOF_CORBA_LONG) + ORTE_ALIGNOF_CORBA_LONG + y + 1)
216 #endif /* !_ORTE_CDR_H_ */