]> rtime.felk.cvut.cz Git - orte.git/blob - orte/include/orte/cdr.h
Add shell.nix
[orte.git] / orte / include / orte / cdr.h
1 /*
2  *  $Id: cdr.h,v 0.0.0.1                2004/11/26
3  *
4  *  -------------------------------------------------------------------
5  *                                ORTE
6  *                      Open Real-Time Ethernet
7  *
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
12  *
13  *  Author:              Petr Smolik    petr@smoliku.cz
14  *  Advisor:             Pavel Pisa
15  *  Project Responsible: Zdenek Hanzalek
16  *  --------------------------------------------------------------------
17  *
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.
22  *
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.
27  *
28  *  Original of source was from ORBit: A CORBA v2.2 ORB
29  */
30 #ifndef _ORTE_CDR_H_
31 #define _ORTE_CDR_H_
32
33 #include "basic_types.h"
34
35 /*
36  * Alignment of CORBA types mapped to C.
37  * These have *nothing* to do with CDR alignment.
38  */
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
51
52 typedef enum {
53   BigEndian = 0,
54   LittleEndian = 1
55 } CDR_Endianness;
56
57 /**
58  * struct CDR_Codec - used for serialization/deserialization
59  * @host_endian:
60  * @data_endian:
61  * @buffer: buffer for data
62  * @buf_len: buffer length
63  * @wptr_max: maximal size of writing data
64  * @wptr: write pointer
65  * @rptr: read pointer
66  * @readonly: readonly attribute
67  * @release_buffer: use CORBA_TRUE if is necessary to free buffer memory after destruction of structure
68  *
69  * Struct @CDR_Codec is used by serialization and deserialization functions.
70  */
71 typedef struct CDR_Codec {
72   CDR_Endianness host_endian;
73   CDR_Endianness data_endian;
74   CORBA_octet *buffer;
75   unsigned int buf_len;
76   unsigned int wptr_max;
77   unsigned int wptr;
78   unsigned int rptr;
79   CORBA_boolean readonly;
80   CORBA_boolean release_buffer;
81 } CDR_Codec;
82
83 #define HEXDIGIT(c) (isdigit((guchar)(c)) ? (c)-'0' : tolower((guchar)(c))-'a'+10)
84 #define HEXOCTET(a, b) ((HEXDIGIT((a)) << 4) | HEXDIGIT((b)))
85
86 extern CORBA_boolean
87 CDR_buffer_init(CDR_Codec *codec, const unsigned int size);
88 extern CDR_Codec *
89 CDR_codec_init(void);
90 extern CDR_Codec *
91 CDR_codec_init_static(CDR_Codec *codec);
92 extern void
93 CDR_codec_release_buffer(CDR_Codec *codec);
94 extern void
95 CDR_codec_free(CDR_Codec *);
96
97 extern CORBA_boolean
98 CDR_buffer_puts(CDR_Codec *codec, const void *data, const unsigned int len);
99 extern CORBA_boolean
100 CDR_buffer_gets(CDR_Codec *codec, void *dest, const unsigned int len);
101
102 extern CORBA_boolean
103 CDR_put_short(CDR_Codec *codec, CORBA_short s);
104 extern CORBA_boolean
105 CDR_put_ushort(CDR_Codec *codec, CORBA_unsigned_short us);
106 extern CORBA_boolean
107 CDR_put_long(CDR_Codec *codec, CORBA_long l);
108 extern CORBA_boolean
109 CDR_put_ulong(CDR_Codec *codec, CORBA_unsigned_long ul);
110 #ifdef HAVE_CORBA_LONG_LONG
111 extern CORBA_boolean
112 CDR_put_long_long(CDR_Codec *codec, CORBA_long_long ll);
113 extern CORBA_boolean
114 CDR_put_ulong_long(CDR_Codec *codec, CORBA_unsigned_long_long ull);
115 extern CORBA_boolean
116 CDR_get_ulong_long(CDR_Codec *codec, CORBA_unsigned_long_long *ul);
117 extern CORBA_boolean
118 CDR_get_long_long(CDR_Codec *codec, CORBA_long_long *ul);
119 #endif
120 extern CORBA_boolean
121 CDR_put_float(CDR_Codec *codec, CORBA_float f);
122 extern CORBA_boolean
123 CDR_put_double(CDR_Codec *codec, CORBA_double d);
124 extern CORBA_boolean
125 CDR_put_long_double(CDR_Codec *codec, CORBA_long_double ld);
126 extern CORBA_boolean
127 CDR_put_octet(CDR_Codec *codec, CORBA_octet datum);
128 extern CORBA_boolean
129 CDR_put_octets(CDR_Codec *codec, void *data, unsigned long len);
130 extern CORBA_boolean
131 CDR_put_char(CDR_Codec *codec, CORBA_char c);
132 extern CORBA_boolean
133 CDR_put_boolean(CDR_Codec *codec, CORBA_boolean datum);
134 extern CORBA_boolean
135 CDR_put_string(CDR_Codec *codec, const char *str);
136 extern CORBA_boolean
137 CDR_buffer_gets(CDR_Codec *codec, void *dest, const unsigned int len);
138 extern CORBA_boolean
139 CDR_get_short(CDR_Codec *codec, CORBA_short *us);
140 extern CORBA_boolean
141 CDR_get_ushort(CDR_Codec *codec, CORBA_unsigned_short *us);
142 extern CORBA_boolean
143 CDR_get_long(CDR_Codec *codec, CORBA_long *l);
144 extern CORBA_boolean
145 CDR_get_ulong(CDR_Codec *codec, CORBA_unsigned_long *ul);
146 extern CORBA_boolean
147 CDR_get_octet(CDR_Codec *codec, CORBA_octet *datum);
148 extern CORBA_boolean
149 CDR_get_boolean(CDR_Codec *codec, CORBA_boolean *b);
150 extern CORBA_boolean
151 CDR_get_char(CDR_Codec *codec, CORBA_char *c);
152 extern CORBA_boolean
153 CDR_get_string(CDR_Codec *codec, CORBA_char **str);
154 extern CORBA_boolean
155 CDR_get_string_buff(CDR_Codec *codec, CORBA_char *str);
156 extern CORBA_boolean
157 CDR_get_string_static(CDR_Codec *codec, CORBA_char **str);
158 extern CORBA_boolean
159 CDR_get_seq_begin(CDR_Codec *codec, CORBA_unsigned_long *ul);
160 extern CORBA_boolean
161 CDR_get_float(CDR_Codec *codec, CORBA_float *f);
162 extern CORBA_boolean
163 CDR_get_double(CDR_Codec *codec, CORBA_double *d);
164
165
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))
178
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))
191
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)
215
216 #endif /* !_ORTE_CDR_H_ */