2 * $Id: cdr.h,v 0.0.0.1 2004/11/26
4 * AUTHOR: Petr Smolik petr.smolik@wo.cz
6 * ORTE - OCERA Real-Time Ethernet http://www.ocera.org/
7 * --------------------------------------------------------------------
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * Original of source was from ORBit: A CORBA v2.2 ORB
24 #include "basic_types.h"
27 * Alignment of CORBA types mapped to C.
28 * These have *nothing* to do with CDR alignment.
30 #define ORTE_ALIGNOF_CORBA_OCTET 1
31 #define ORTE_ALIGNOF_CORBA_BOOLEAN 1
32 #define ORTE_ALIGNOF_CORBA_CHAR 1
33 #define ORTE_ALIGNOF_CORBA_WCHAR 2
34 #define ORTE_ALIGNOF_CORBA_SHORT 2
35 #define ORTE_ALIGNOF_CORBA_LONG 4
36 #define ORTE_ALIGNOF_CORBA_LONG_LONG 8
37 #define ORTE_ALIGNOF_CORBA_FLOAT 4
38 #define ORTE_ALIGNOF_CORBA_DOUBLE 8
39 #define ORTE_ALIGNOF_CORBA_LONG_DOUBLE 16
40 #define ORTE_ALIGNOF_CORBA_STRUCT 1
41 #define ORTE_ALIGNOF_CORBA_POINTER 4
49 * struct CDR_Codec - used for serialization/deserialization
52 * @buffer: buffer for data
53 * @buf_len: buffer length
54 * @wptr_max: maximal size of writing data
55 * @wptr: write pointer
57 * @readonly: readonly attribute
58 * @release_buffer: use CORBA_TRUE if is necessary to free buffer memory after destruction of structure
60 * Struct @CDR_Codec is used by serialization and deserialization functions.
62 typedef struct CDR_Codec {
63 CDR_Endianness host_endian;
64 CDR_Endianness data_endian;
67 unsigned int wptr_max;
70 CORBA_boolean readonly;
71 CORBA_boolean release_buffer;
74 #define HEXDIGIT(c) (isdigit((guchar)(c))?(c)-'0':tolower((guchar)(c))-'a'+10)
75 #define HEXOCTET(a,b) ((HEXDIGIT((a)) << 4) | HEXDIGIT((b)))
77 extern CORBA_boolean CDR_buffer_init(CDR_Codec *codec, const unsigned int size);
78 extern CDR_Codec *CDR_codec_init(void);
79 extern CDR_Codec *CDR_codec_init_static(CDR_Codec *codec);
80 extern void CDR_codec_release_buffer(CDR_Codec *codec);
81 extern void CDR_codec_free(CDR_Codec *);
83 extern CORBA_boolean CDR_buffer_puts(CDR_Codec *codec, const void *data, const unsigned int len);
84 extern CORBA_boolean CDR_buffer_gets(CDR_Codec *codec, void *dest, const unsigned int len);
86 extern CORBA_boolean CDR_put_short(CDR_Codec *codec, CORBA_short s);
87 extern CORBA_boolean CDR_put_ushort(CDR_Codec *codec, CORBA_unsigned_short us);
88 extern CORBA_boolean CDR_put_long(CDR_Codec *codec, CORBA_long l);
89 extern CORBA_boolean CDR_put_ulong(CDR_Codec *codec, CORBA_unsigned_long ul);
90 #ifdef HAVE_CORBA_LONG_LONG
91 extern CORBA_boolean CDR_put_long_long(CDR_Codec *codec, CORBA_long_long ll);
92 extern CORBA_boolean CDR_put_ulong_long(CDR_Codec *codec, CORBA_unsigned_long_long ull);
93 extern CORBA_boolean CDR_get_ulong_long(CDR_Codec *codec, CORBA_unsigned_long_long *ul);
94 extern CORBA_boolean CDR_get_long_long(CDR_Codec *codec, CORBA_long_long *ul);
96 extern CORBA_boolean CDR_put_float(CDR_Codec *codec, CORBA_float f);
97 extern CORBA_boolean CDR_put_double(CDR_Codec *codec, CORBA_double d);
98 extern CORBA_boolean CDR_put_long_double(CDR_Codec *codec, CORBA_long_double ld);
99 extern CORBA_boolean CDR_put_octet(CDR_Codec *codec, CORBA_octet datum);
100 extern CORBA_boolean CDR_put_octets(CDR_Codec *codec, void *data, unsigned long len);
101 extern CORBA_boolean CDR_put_char(CDR_Codec *codec, CORBA_char c);
102 extern CORBA_boolean CDR_put_boolean(CDR_Codec *codec, CORBA_boolean datum);
103 extern CORBA_boolean CDR_put_string(CDR_Codec *codec, const char *str);
104 extern CORBA_boolean CDR_buffer_gets(CDR_Codec *codec, void *dest, const unsigned int len);
105 extern CORBA_boolean CDR_get_short(CDR_Codec *codec, CORBA_short *us);
106 extern CORBA_boolean CDR_get_ushort(CDR_Codec *codec, CORBA_unsigned_short *us);
107 extern CORBA_boolean CDR_get_long(CDR_Codec *codec, CORBA_long *l);
108 extern CORBA_boolean CDR_get_ulong(CDR_Codec *codec, CORBA_unsigned_long *ul);
109 extern CORBA_boolean CDR_get_octet(CDR_Codec *codec, CORBA_octet *datum);
110 extern CORBA_boolean CDR_get_boolean(CDR_Codec *codec, CORBA_boolean *b);
111 extern CORBA_boolean CDR_get_char(CDR_Codec *codec, CORBA_char *c);
112 extern CORBA_boolean CDR_get_string(CDR_Codec *codec, CORBA_char **str);
113 extern CORBA_boolean CDR_get_string_buff(CDR_Codec *codec, CORBA_char *str);
114 extern CORBA_boolean CDR_get_string_static(CDR_Codec *codec, CORBA_char **str);
115 extern CORBA_boolean CDR_get_seq_begin(CDR_Codec *codec, CORBA_unsigned_long *ul);
118 /* serialization functions */
119 #define CORBA_short_serialize(x,y) CDR_put_short((x),*(y))
120 #define CORBA_long_serialize(x,y) CDR_put_long((x),*(y))
121 #define CORBA_unsigned_short_serialize(x,y) CDR_put_ushort((x),*(y))
122 #define CORBA_unsigned_long_serialize(x,y) CDR_put_ulong((x),*(y))
123 #define CORBA_float_serialize(x,y) CDR_put_float((x),*(y))
124 #define CORBA_double_serialize(x,y) CDR_put_double((x),*(y))
125 #define CORBA_char_serialize(x,y) CDR_put_char((x),*(y))
126 #define CORBA_boolean_serialize(x,y) CDR_put_boolean((x),*(y))
127 #define CORBA_octet_serialize(x,y) CDR_put_octet((x),*(y))
128 #define CORBA_long_double_serialize(x,y) CDR_put_long_double((x),*(y))
129 #define CORBA_string_serialize(x,y) CDR_put_string((x),*(y))
131 /* deserialization functions */
132 #define CORBA_short_deserialize(x,y) CDR_get_short((x),(y))
133 #define CORBA_long_deserialize(x,y) CDR_get_long((x),(y))
134 #define CORBA_unsigned_short_deserialize(x,y) CDR_get_ushort((x),(y))
135 #define CORBA_unsigned_long_deserialize(x,y) CDR_get_ulong((x),(y))
136 #define CORBA_float_deserialize(x,y) CDR_get_float((x),(y))
137 #define CORBA_double_deserialize(x,y) CDR_get_double((x),(y))
138 #define CORBA_char_deserialize(x,y) CDR_get_char((x),(y))
139 #define CORBA_boolean_deserialize(x,y) CDR_get_boolean((x),(y))
140 #define CORBA_octet_deserialize(x,y) CDR_get_octet((x),(y))
141 #define CORBA_long_double_deserialize(x,y) CDR_get_long_double((x),(y))
142 #define CORBA_string_deserialize(x,y) CDR_get_string((x),(y))
144 /* get_max_size functions */
145 #define CORBA_short_get_max_size(x) ((x)->csize=\
146 (unsigned long)ALIGN_ADDRESS((x)->csize,ORTE_ALIGNOF_CORBA_SHORT)+ORTE_ALIGNOF_CORBA_SHORT)
147 #define CORBA_long_get_max_size(x) ((x)->csize=\
148 (unsigned long)ALIGN_ADDRESS((x)->csize,ORTE_ALIGNOF_CORBA_LONG)+ORTE_ALIGNOF_CORBA_LONG)
149 #define CORBA_unsigned_short_get_max_size(x) ((x)->csize=\
150 (unsigned long)ALIGN_ADDRESS((x)->csize,ORTE_ALIGNOF_CORBA_SHORT)+ORTE_ALIGNOF_CORBA_SHORT)
151 #define CORBA_unsigned_long_get_max_size(x) ((x)->csize=\
152 (unsigned long)ALIGN_ADDRESS((x)->csize,ORTE_ALIGNOF_CORBA_LONG)+ORTE_ALIGNOF_CORBA_LONG)
153 #define CORBA_float_get_max_size(x) ((x)->csize=\
154 (unsigned long)ALIGN_ADDRESS((x)->csize,ORTE_ALIGNOF_CORBA_FLOAT)+ORTE_ALIGNOF_CORBA_FLOAT)
155 #define CORBA_double_get_max_size(x) ((x)->csize=\
156 (unsigned long)ALIGN_ADDRESS((x)->csize,ORTE_ALIGNOF_CORBA_DOUBLE)+ORTE_ALIGNOF_CORBA_DOUBLE)
157 #define CORBA_char_get_max_size(x) ((x)->csize=\
158 (unsigned long)ALIGN_ADDRESS((x)->csize,ORTE_ALIGNOF_CORBA_CHAR)+ORTE_ALIGNOF_CORBA_CHAR)
159 #define CORBA_boolean_get_max_size(x) ((x)->csize=\
160 (unsigned long)ALIGN_ADDRESS((x)->csize,ORTE_ALIGNOF_CORBA_BOOLEAN)+ORTE_ALIGNOF_CORBA_BOOLEAN)
161 #define CORBA_octet_get_max_size(x) ((x)->csize=\
162 (unsigned long)ALIGN_ADDRESS((x)->csize,ORTE_ALIGNOF_CORBA_OCTET)+ORTE_ALIGNOF_CORBA_OCTET)
163 #define CORBA_long_double_get_max_size(x) ((x)->csize=\
164 (unsigned long)ALIGN_ADDRESS((x)->csize,ORTE_ALIGNOF_CORBA_LONG_DOUBLE)+ORTE_ALIGNOF_CORBA_DOUBLE)
165 #define CORBA_string_get_max_size(x,y) \
166 ((x)->csize=(unsigned long)ALIGN_ADDRESS((x)->csize,ORTE_ALIGNOF_CORBA_LONG) + ORTE_ALIGNOF_CORBA_LONG + y + 1)
168 #endif /* !_ORTE_CDR_H_ */