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.smolik@wo.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"
34 #include "cdr_codec.h"
37 * Alignment of CORBA types mapped to C.
38 * These have *nothing* to do with CDR alignment.
40 #define ORTE_ALIGNOF_CORBA_OCTET 1
41 #define ORTE_ALIGNOF_CORBA_BOOLEAN 1
42 #define ORTE_ALIGNOF_CORBA_CHAR 1
43 #define ORTE_ALIGNOF_CORBA_WCHAR 2
44 #define ORTE_ALIGNOF_CORBA_SHORT 2
45 #define ORTE_ALIGNOF_CORBA_LONG 4
46 #define ORTE_ALIGNOF_CORBA_LONG_LONG 8
47 #define ORTE_ALIGNOF_CORBA_FLOAT 4
48 #define ORTE_ALIGNOF_CORBA_DOUBLE 8
49 #define ORTE_ALIGNOF_CORBA_LONG_DOUBLE 16
50 #define ORTE_ALIGNOF_CORBA_STRUCT 1
51 #define ORTE_ALIGNOF_CORBA_POINTER 4
59 * struct CDR_Codec - used for serialization/deserialization
62 * @buffer: buffer for data
63 * @buf_len: buffer length
64 * @wptr_max: maximal size of writing data
66 * @wptr_last: index of the data after the last written data
68 * @readonly: readonly attribute
69 * @release_buffer: use CORBA_TRUE if is necessary to free buffer memory after destruction of structure
71 * Struct @CDR_Codec is used by serialization and deserialization functions.
74 CDR_Endianness host_endian;
75 CDR_Endianness data_endian;
78 unsigned int wptr_max;
80 unsigned int wptr_last;
82 CORBA_boolean readonly;
83 CORBA_boolean release_buffer;
86 #define HEXDIGIT(c) (isdigit((guchar)(c))?(c)-'0':tolower((guchar)(c))-'a'+10)
87 #define HEXOCTET(a,b) ((HEXDIGIT((a)) << 4) | HEXDIGIT((b)))
89 static inline CORBA_long CDR_data_size(CDR_Codec *codec)
91 return codec->wptr_last - codec->rptr;
94 extern CORBA_boolean CDR_buffer_init(CDR_Codec *codec, const unsigned int size, const unsigned int first);
95 extern CORBA_boolean CDR_buffer_reset(CDR_Codec *codec, const unsigned int first);
96 extern CORBA_boolean CDR_buffer_prepend(CDR_Codec *codec, const unsigned int len);
97 extern CDR_Codec *CDR_codec_init(void);
98 extern CDR_Codec *CDR_codec_init_static(CDR_Codec *codec);
99 extern void CDR_codec_release_buffer(CDR_Codec *codec);
100 extern void CDR_codec_free(CDR_Codec *);
102 extern CORBA_boolean CDR_buffer_puts(CDR_Codec *codec, const void *data, const unsigned int len);
103 extern CORBA_boolean CDR_buffer_gets(CDR_Codec *codec, void *dest, const unsigned int len);
105 extern CORBA_boolean CDR_put_short(CDR_Codec *codec, CORBA_short s);
106 extern CORBA_boolean CDR_put_ushort(CDR_Codec *codec, CORBA_unsigned_short us);
107 extern CORBA_boolean CDR_put_long(CDR_Codec *codec, CORBA_long l);
108 extern CORBA_boolean CDR_put_ulong(CDR_Codec *codec, CORBA_unsigned_long ul);
109 /* #ifdef HAVE_CORBA_LONG_LONG */
110 extern CORBA_boolean CDR_put_long_long(CDR_Codec *codec, CORBA_long_long ll);
111 extern CORBA_boolean CDR_put_ulong_long(CDR_Codec *codec, CORBA_unsigned_long_long ull);
112 extern CORBA_boolean CDR_get_ulong_long(CDR_Codec *codec, CORBA_unsigned_long_long *ul);
113 extern CORBA_boolean CDR_get_long_long(CDR_Codec *codec, CORBA_long_long *ul);
115 extern CORBA_boolean CDR_put_float(CDR_Codec *codec, CORBA_float f);
116 extern CORBA_boolean CDR_put_double(CDR_Codec *codec, CORBA_double d);
117 extern CORBA_boolean CDR_put_long_double(CDR_Codec *codec, CORBA_long_double ld);
118 extern CORBA_boolean CDR_put_octet(CDR_Codec *codec, CORBA_octet datum);
119 extern CORBA_boolean CDR_put_octets(CDR_Codec *codec, void *data, unsigned long len);
120 extern CORBA_boolean CDR_put_char(CDR_Codec *codec, CORBA_char c);
121 extern CORBA_boolean CDR_put_boolean(CDR_Codec *codec, CORBA_boolean datum);
122 extern CORBA_boolean CDR_put_string(CDR_Codec *codec, const CORBA_char *str);
123 extern CORBA_boolean CDR_buffer_gets(CDR_Codec *codec, void *dest, const unsigned int len);
124 extern CORBA_boolean CDR_get_short(CDR_Codec *codec, CORBA_short *us);
125 extern CORBA_boolean CDR_get_ushort(CDR_Codec *codec, CORBA_unsigned_short *us);
126 extern CORBA_boolean CDR_get_long(CDR_Codec *codec, CORBA_long *l);
127 extern CORBA_boolean CDR_get_ulong(CDR_Codec *codec, CORBA_unsigned_long *ul);
128 extern CORBA_boolean CDR_get_octet(CDR_Codec *codec, CORBA_octet *datum);
129 extern CORBA_boolean CDR_get_boolean(CDR_Codec *codec, CORBA_boolean *b);
130 extern CORBA_boolean CDR_get_char(CDR_Codec *codec, CORBA_char *c);
131 extern CORBA_boolean CDR_get_string(CDR_Codec *codec, CORBA_char **str);
132 extern CORBA_boolean CDR_get_string_buff(CDR_Codec *codec, CORBA_char *str);
133 extern CORBA_boolean CDR_get_string_static(CDR_Codec *codec, CORBA_char **str);
134 extern CORBA_boolean CDR_get_seq_begin(CDR_Codec *codec, CORBA_unsigned_long *ul);
135 extern CORBA_boolean CDR_get_float(CDR_Codec *codec, CORBA_float *f);
136 extern CORBA_boolean CDR_get_double(CDR_Codec *codec, CORBA_double *d);
139 /* serialization functions */
140 #define CORBA_short_serialize(x,y) CDR_put_short((x),*(y))
141 #define CORBA_long_serialize(x,y) CDR_put_long((x),*(y))
142 #define CORBA_long_long_serialize(x,y) CDR_put_long_long((x),*(y))
143 #define CORBA_unsigned_short_serialize(x,y) CDR_put_ushort((x),*(y))
144 #define CORBA_unsigned_long_serialize(x,y) CDR_put_ulong((x),*(y))
145 #define CORBA_unsigned_long_long_serialize(x,y) CDR_put_ulong_long((x),*(y))
146 #define CORBA_float_serialize(x,y) CDR_put_float((x),*(y))
147 #define CORBA_double_serialize(x,y) CDR_put_double((x),*(y))
148 #define CORBA_char_serialize(x,y) CDR_put_char((x),*(y))
149 #define CORBA_boolean_serialize(x,y) CDR_put_boolean((x),*(y))
150 #define CORBA_octet_serialize(x,y) CDR_put_octet((x),*(y))
151 #define CORBA_long_double_serialize(x,y) CDR_put_long_double((x),*(y))
152 #define CORBA_string_serialize(x,y) CDR_put_string((x),*(y))
154 /* deserialization functions */
155 #define CORBA_short_deserialize(x,y) CDR_get_short((x),(y))
156 #define CORBA_long_deserialize(x,y) CDR_get_long((x),(y))
157 #define CORBA_long_long_deserialize(x,y) CDR_get_long_long((x),(y))
158 #define CORBA_unsigned_short_deserialize(x,y) CDR_get_ushort((x),(y))
159 #define CORBA_unsigned_long_deserialize(x,y) CDR_get_ulong((x),(y))
160 #define CORBA_unsigned_long_long_deserialize(x,y) CDR_get_ulong_long((x),(y))
161 #define CORBA_float_deserialize(x,y) CDR_get_float((x),(y))
162 #define CORBA_double_deserialize(x,y) CDR_get_double((x),(y))
163 #define CORBA_char_deserialize(x,y) CDR_get_char((x),(y))
164 #define CORBA_boolean_deserialize(x,y) CDR_get_boolean((x),(y))
165 #define CORBA_octet_deserialize(x,y) CDR_get_octet((x),(y))
166 #define CORBA_long_double_deserialize(x,y) CDR_get_long_double((x),(y))
167 #define CORBA_string_deserialize(x,y) CDR_get_string((x),(y))
169 /* get_max_size functions */
170 #define CORBA_short_get_max_size(x) ((x)->csize=\
171 (unsigned long)ALIGN_ADDRESS((x)->csize,ORTE_ALIGNOF_CORBA_SHORT)+ORTE_ALIGNOF_CORBA_SHORT)
172 #define CORBA_long_get_max_size(x) ((x)->csize=\
173 (unsigned long)ALIGN_ADDRESS((x)->csize,ORTE_ALIGNOF_CORBA_LONG)+ORTE_ALIGNOF_CORBA_LONG)
174 #define CORBA_unsigned_short_get_max_size(x) ((x)->csize=\
175 (unsigned long)ALIGN_ADDRESS((x)->csize,ORTE_ALIGNOF_CORBA_SHORT)+ORTE_ALIGNOF_CORBA_SHORT)
176 #define CORBA_unsigned_long_get_max_size(x) ((x)->csize=\
177 (unsigned long)ALIGN_ADDRESS((x)->csize,ORTE_ALIGNOF_CORBA_LONG)+ORTE_ALIGNOF_CORBA_LONG)
178 #define CORBA_float_get_max_size(x) ((x)->csize=\
179 (unsigned long)ALIGN_ADDRESS((x)->csize,ORTE_ALIGNOF_CORBA_FLOAT)+ORTE_ALIGNOF_CORBA_FLOAT)
180 #define CORBA_double_get_max_size(x) ((x)->csize=\
181 (unsigned long)ALIGN_ADDRESS((x)->csize,ORTE_ALIGNOF_CORBA_DOUBLE)+ORTE_ALIGNOF_CORBA_DOUBLE)
182 #define CORBA_char_get_max_size(x) ((x)->csize=\
183 (unsigned long)ALIGN_ADDRESS((x)->csize,ORTE_ALIGNOF_CORBA_CHAR)+ORTE_ALIGNOF_CORBA_CHAR)
184 #define CORBA_boolean_get_max_size(x) ((x)->csize=\
185 (unsigned long)ALIGN_ADDRESS((x)->csize,ORTE_ALIGNOF_CORBA_BOOLEAN)+ORTE_ALIGNOF_CORBA_BOOLEAN)
186 #define CORBA_octet_get_max_size(x) ((x)->csize=\
187 (unsigned long)ALIGN_ADDRESS((x)->csize,ORTE_ALIGNOF_CORBA_OCTET)+ORTE_ALIGNOF_CORBA_OCTET)
188 #define CORBA_long_double_get_max_size(x) ((x)->csize=\
189 (unsigned long)ALIGN_ADDRESS((x)->csize,ORTE_ALIGNOF_CORBA_LONG_DOUBLE)+ORTE_ALIGNOF_CORBA_DOUBLE)
190 #define CORBA_string_get_max_size(x,y) \
191 ((x)->csize=(unsigned long)ALIGN_ADDRESS((x)->csize,ORTE_ALIGNOF_CORBA_LONG) + ORTE_ALIGNOF_CORBA_LONG + y + 1)
193 #endif /* !_ORTE_CDR_H_ */