Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tao / CDR.cpp
blobc0c383ae746f3bc82e4731053ed5e573932a13bb
1 #include "tao/CDR.h"
2 #include "tao/Timeprobe.h"
3 #include "tao/ORB_Core.h"
4 #include "tao/SystemException.h"
5 #include "tao/GIOP_Fragmentation_Strategy.h"
7 #include "ace/Truncate.h"
9 #if !defined (__ACE_INLINE__)
10 # include "tao/CDR.inl"
11 #endif /* ! __ACE_INLINE__ */
13 #if defined (ACE_ENABLE_TIMEPROBES)
15 static const char *TAO_CDR_Timeprobe_Description[] =
17 "OutputCDR::ctor[1] - enter",
18 "OutputCDR::ctor[1] - leave",
19 "OutputCDR::ctor[2] - enter",
20 "OutputCDR::ctor[2] - leave",
21 "OutputCDR::ctor[3] - enter",
22 "OutputCDR::ctor[3] - leave",
23 "OutputCDR::ctor[4] - enter",
24 "OutputCDR::ctor[4] - leave",
25 "OutputCDR::ctor[5] - enter",
26 "OutputCDR::ctor[5] - leave"
29 enum
31 TAO_OUTPUT_CDR_CTOR1_ENTER = 2000,
32 TAO_OUTPUT_CDR_CTOR1_LEAVE,
33 TAO_OUTPUT_CDR_CTOR2_ENTER,
34 TAO_OUTPUT_CDR_CTOR2_LEAVE,
35 TAO_OUTPUT_CDR_CTOR3_ENTER,
36 TAO_OUTPUT_CDR_CTOR3_LEAVE,
37 TAO_OUTPUT_CDR_CTOR4_ENTER,
38 TAO_OUTPUT_CDR_CTOR4_LEAVE,
39 TAO_OUTPUT_CDR_CTOR5_ENTER,
40 TAO_OUTPUT_CDR_CTOR5_LEAVE
43 // Setup Timeprobes
44 ACE_TIMEPROBE_EVENT_DESCRIPTIONS (TAO_CDR_Timeprobe_Description,
45 TAO_OUTPUT_CDR_CTOR1_ENTER);
47 #endif /* ACE_ENABLE_TIMEPROBES */
49 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
51 TAO_OutputCDR::TAO_OutputCDR (size_t size,
52 int byte_order,
53 ACE_Allocator *buffer_allocator,
54 ACE_Allocator *data_block_allocator,
55 ACE_Allocator* message_block_allocator,
56 size_t memcpy_tradeoff,
57 ACE_CDR::Octet major_version,
58 ACE_CDR::Octet minor_version)
59 : ACE_OutputCDR (size,
60 byte_order,
61 buffer_allocator,
62 data_block_allocator,
63 message_block_allocator,
64 memcpy_tradeoff,
65 major_version,
66 minor_version)
67 , fragmentation_strategy_ (nullptr)
68 , more_fragments_ (false)
69 , request_id_ (0)
70 , stub_ (nullptr)
71 , message_semantics_ (TAO_Message_Semantics::TAO_TWOWAY_REQUEST)
72 , timeout_ (nullptr)
74 ACE_FUNCTION_TIMEPROBE (TAO_OUTPUT_CDR_CTOR1_ENTER);
76 #if defined (TAO_ZERO_TAO_OUTPUTCDR_ALLOCATED_BUFFERS)
77 // Zero out the buffer if we allocated the buffer.
78 if (size == 0)
79 (void) ACE_OS::memset (this->current()->wr_ptr(),
81 this->current()->space());
82 #endif /* TAO_ZERO_TAO_OUTPUTCDR_ALLOCATED_BUFFERS */
85 TAO_OutputCDR::TAO_OutputCDR (char *data,
86 size_t size,
87 int byte_order,
88 ACE_Allocator *buffer_allocator,
89 ACE_Allocator *data_block_allocator,
90 ACE_Allocator* message_block_allocator,
91 size_t memcpy_tradeoff,
92 ACE_CDR::Octet major_version,
93 ACE_CDR::Octet minor_version)
94 : ACE_OutputCDR (data,
95 size,
96 byte_order,
97 buffer_allocator,
98 data_block_allocator,
99 message_block_allocator,
100 memcpy_tradeoff,
101 major_version,
102 minor_version)
103 , fragmentation_strategy_ (nullptr)
104 , more_fragments_ (false)
105 , request_id_ (0)
106 , stub_ (nullptr)
107 , message_semantics_ (TAO_Message_Semantics::TAO_TWOWAY_REQUEST)
108 , timeout_ (nullptr)
110 ACE_FUNCTION_TIMEPROBE (TAO_OUTPUT_CDR_CTOR2_ENTER);
113 TAO_OutputCDR::TAO_OutputCDR (char *data,
114 size_t size,
115 int byte_order,
116 ACE_Allocator* buffer_allocator,
117 ACE_Allocator* data_block_allocator,
118 ACE_Allocator* message_block_allocator,
119 size_t memcpy_tradeoff,
120 TAO_GIOP_Fragmentation_Strategy * fs,
121 ACE_CDR::Octet major_version,
122 ACE_CDR::Octet minor_version)
123 : ACE_OutputCDR (data,
124 size,
125 byte_order,
126 buffer_allocator,
127 data_block_allocator,
128 message_block_allocator,
129 memcpy_tradeoff,
130 major_version,
131 minor_version)
132 , fragmentation_strategy_ (fs)
133 , more_fragments_ (false)
134 , request_id_ (0)
135 , stub_ (nullptr)
136 , message_semantics_ (TAO_Message_Semantics::TAO_TWOWAY_REQUEST)
137 , timeout_ (nullptr)
139 ACE_FUNCTION_TIMEPROBE (TAO_OUTPUT_CDR_CTOR3_ENTER);
142 TAO_OutputCDR::TAO_OutputCDR (ACE_Message_Block *data,
143 int byte_order,
144 size_t memcpy_tradeoff,
145 ACE_CDR::Octet major_version,
146 ACE_CDR::Octet minor_version)
147 : ACE_OutputCDR (data,
148 byte_order,
149 memcpy_tradeoff,
150 major_version,
151 minor_version)
152 , fragmentation_strategy_ (nullptr)
153 , more_fragments_ (false)
154 , request_id_ (0)
155 , stub_ (nullptr)
156 , message_semantics_ (TAO_Message_Semantics::TAO_TWOWAY_REQUEST)
157 , timeout_ (nullptr)
159 ACE_FUNCTION_TIMEPROBE (TAO_OUTPUT_CDR_CTOR4_ENTER);
162 TAO_OutputCDR::TAO_OutputCDR (ACE_Data_Block *data_block,
163 int byte_order,
164 ACE_Allocator* message_block_allocator,
165 size_t memcpy_tradeoff,
166 TAO_GIOP_Fragmentation_Strategy * fs,
167 ACE_CDR::Octet major_version,
168 ACE_CDR::Octet minor_version)
169 : ACE_OutputCDR (data_block,
170 byte_order,
171 message_block_allocator,
172 memcpy_tradeoff,
173 major_version,
174 minor_version)
175 , fragmentation_strategy_ (fs)
176 , more_fragments_ (false)
177 , request_id_ (0)
178 , stub_ (nullptr)
179 , message_semantics_ (TAO_Message_Semantics::TAO_TWOWAY_REQUEST)
180 , timeout_ (nullptr)
182 ACE_FUNCTION_TIMEPROBE (TAO_OUTPUT_CDR_CTOR5_ENTER);
185 void
186 TAO_OutputCDR::throw_stub_exception (int error_num)
188 switch (error_num)
190 case EINVAL : // wchar from a GIOP 1.0
191 throw ::CORBA::MARSHAL (CORBA::OMGVMCID | 5, CORBA::COMPLETED_NO);
192 ACE_NOTREACHED (break);
193 #if (ERANGE != EINVAL)
194 case ERANGE : // untranslatable character
195 throw ::CORBA::DATA_CONVERSION (CORBA::OMGVMCID | 1,
196 CORBA::COMPLETED_NO);
197 ACE_NOTREACHED (break);
198 #endif
199 case EACCES : // wchar but no codeset
200 throw ::CORBA::INV_OBJREF (CORBA::OMGVMCID | 2, CORBA::COMPLETED_NO);
201 ACE_NOTREACHED (break);
202 default :
203 throw ::CORBA::MARSHAL ();
207 void
208 TAO_OutputCDR::throw_skel_exception (int error_num )
210 switch (error_num)
212 case EINVAL : // wchar from a GIOP 1.0
213 throw ::CORBA::MARSHAL (CORBA::OMGVMCID | 5, CORBA::COMPLETED_YES);
214 ACE_NOTREACHED (break);
216 case EACCES : // wchar but no codeset
217 throw ::CORBA::BAD_PARAM (CORBA::OMGVMCID | 23, CORBA::COMPLETED_YES);
218 ACE_NOTREACHED (break);
220 #if (ERANGE != EINVAL)
221 case ERANGE : // untranslatable character
222 throw ::CORBA::DATA_CONVERSION (CORBA::OMGVMCID | 1,
223 CORBA::COMPLETED_YES);
224 ACE_NOTREACHED (break);
225 #endif
227 default :
228 throw ::CORBA::MARSHAL (0, CORBA::COMPLETED_YES);
232 bool
233 TAO_OutputCDR::fragment_stream (ACE_CDR::ULong pending_alignment,
234 ACE_CDR::ULong pending_length)
236 if (this->fragmentation_strategy_)
238 return (this->fragmentation_strategy_->fragment (*this,
239 pending_alignment,
240 pending_length) == 0);
243 return true; // Success.
248 TAO_OutputCDR::offset (char* pos)
250 int offset = 0;
251 const ACE_Message_Block * cur_mb = this->begin ();
252 char* wr_ptr = this->current ()->wr_ptr ();
253 bool found = false;
255 while (cur_mb != this->end ())
257 if (pos >= cur_mb->rd_ptr () && pos <= cur_mb->wr_ptr ())
259 offset += ACE_Utils::truncate_cast<int> (cur_mb->wr_ptr () - pos);
260 found = true;
262 else if (found)
264 offset += ACE_Utils::truncate_cast<int> (cur_mb->length ());
267 if (wr_ptr == cur_mb->wr_ptr ())
268 break;
270 cur_mb = cur_mb->cont();
273 if (!found || wr_ptr != cur_mb->wr_ptr ())
275 throw ::CORBA::INTERNAL ();
278 return offset;
282 // ****************************************************************
284 TAO_InputCDR::TAO_InputCDR (const TAO_OutputCDR& rhs,
285 ACE_Allocator* buffer_allocator,
286 ACE_Allocator* data_block_allocator,
287 ACE_Allocator* message_block_allocator,
288 TAO_ORB_Core* orb_core)
289 : ACE_InputCDR (rhs,
290 buffer_allocator
291 ? buffer_allocator
292 : (orb_core ? orb_core->output_cdr_buffer_allocator () : nullptr),
293 data_block_allocator
294 ? data_block_allocator
295 : (orb_core ? orb_core->output_cdr_dblock_allocator () :
296 nullptr),
297 message_block_allocator
298 ? message_block_allocator
299 : (orb_core ?
300 orb_core->output_cdr_msgblock_allocator () : nullptr)),
301 orb_core_ (orb_core)
305 void
306 TAO_InputCDR::throw_stub_exception (int error_num )
308 switch (error_num)
310 case EINVAL : // wchar from a GIOP 1.0
311 throw ::CORBA::MARSHAL (CORBA::OMGVMCID | 6, CORBA::COMPLETED_YES);
312 ACE_NOTREACHED(break);
313 #if (ERANGE != EINVAL)
314 case ERANGE : // untranslatable character
315 throw ::CORBA::DATA_CONVERSION (CORBA::OMGVMCID | 1, CORBA::COMPLETED_YES);
316 ACE_NOTREACHED(break);
317 #endif
318 case EACCES : // wchar but no codeset
319 throw ::CORBA::INV_OBJREF (CORBA::OMGVMCID | 2, CORBA::COMPLETED_YES);
320 ACE_NOTREACHED(break);
321 default :
322 throw ::CORBA::MARSHAL (0, CORBA::COMPLETED_YES);
326 void
327 TAO_InputCDR::throw_skel_exception (int error_num )
329 switch (error_num)
331 case EINVAL : // wchar from a GIOP 1.0
332 throw ::CORBA::MARSHAL(CORBA::OMGVMCID | 5, CORBA::COMPLETED_NO);
333 ACE_NOTREACHED(break);
335 case EACCES : // wchar but no codeset
336 throw ::CORBA::BAD_PARAM(CORBA::OMGVMCID | 23, CORBA::COMPLETED_NO);
337 ACE_NOTREACHED(break);
339 #if (ERANGE != EINVAL)
340 case ERANGE : // untranslatable character
341 throw ::CORBA::DATA_CONVERSION(CORBA::OMGVMCID | 1, CORBA::COMPLETED_NO);
342 ACE_NOTREACHED(break);
343 #endif
345 default :
346 throw ::CORBA::MARSHAL();
350 ACE_Message_Block::Message_Flags
351 TAO_InputCDR::clr_mb_flags( ACE_Message_Block::Message_Flags less_flags )
353 return start_.clr_self_flags( less_flags );
357 TAO_END_VERSIONED_NAMESPACE_DECL