Updated logging to include the class/method so that it is more obvious where these...
[ACE_TAO.git] / TAO / tao / CDR.cpp
blob79835eacf2c052c71431cced8f8b735e68ee57c1
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);
233 bool
234 TAO_OutputCDR::fragment_stream (ACE_CDR::ULong pending_alignment,
235 ACE_CDR::ULong pending_length)
237 if (this->fragmentation_strategy_)
239 return (this->fragmentation_strategy_->fragment (*this,
240 pending_alignment,
241 pending_length) == 0);
244 return true; // Success.
250 TAO_OutputCDR::offset (char* pos)
252 int offset = 0;
253 const ACE_Message_Block * cur_mb = this->begin ();
254 char* wr_ptr = this->current ()->wr_ptr ();
255 bool found = false;
257 while (cur_mb != this->end ())
259 if (pos >= cur_mb->rd_ptr () && pos <= cur_mb->wr_ptr ())
261 offset += ACE_Utils::truncate_cast<int> (cur_mb->wr_ptr () - pos);
262 found = true;
264 else if (found)
266 offset += ACE_Utils::truncate_cast<int> (cur_mb->length ());
269 if (wr_ptr == cur_mb->wr_ptr ())
270 break;
272 cur_mb = cur_mb->cont();
275 if (!found || wr_ptr != cur_mb->wr_ptr ())
277 throw ::CORBA::INTERNAL ();
280 return offset;
284 // ****************************************************************
286 TAO_InputCDR::TAO_InputCDR (const TAO_OutputCDR& rhs,
287 ACE_Allocator* buffer_allocator,
288 ACE_Allocator* data_block_allocator,
289 ACE_Allocator* message_block_allocator,
290 TAO_ORB_Core* orb_core)
291 : ACE_InputCDR (rhs,
292 buffer_allocator
293 ? buffer_allocator
294 : (orb_core ? orb_core->output_cdr_buffer_allocator () : nullptr),
295 data_block_allocator
296 ? data_block_allocator
297 : (orb_core ? orb_core->output_cdr_dblock_allocator () :
298 nullptr),
299 message_block_allocator
300 ? message_block_allocator
301 : (orb_core ?
302 orb_core->output_cdr_msgblock_allocator () : nullptr)),
303 orb_core_ (orb_core)
307 void
308 TAO_InputCDR::throw_stub_exception (int error_num )
310 switch (error_num)
312 case EINVAL : // wchar from a GIOP 1.0
313 throw ::CORBA::MARSHAL (CORBA::OMGVMCID | 6, CORBA::COMPLETED_YES);
314 ACE_NOTREACHED(break);
315 #if (ERANGE != EINVAL)
316 case ERANGE : // untranslatable character
317 throw ::CORBA::DATA_CONVERSION (CORBA::OMGVMCID | 1, CORBA::COMPLETED_YES);
318 ACE_NOTREACHED(break);
319 #endif
320 case EACCES : // wchar but no codeset
321 throw ::CORBA::INV_OBJREF (CORBA::OMGVMCID | 2, CORBA::COMPLETED_YES);
322 ACE_NOTREACHED(break);
323 default :
324 throw ::CORBA::MARSHAL (0, CORBA::COMPLETED_YES);
328 void
329 TAO_InputCDR::throw_skel_exception (int error_num )
331 switch (error_num)
333 case EINVAL : // wchar from a GIOP 1.0
334 throw ::CORBA::MARSHAL(CORBA::OMGVMCID | 5, CORBA::COMPLETED_NO);
335 ACE_NOTREACHED(break);
337 case EACCES : // wchar but no codeset
338 throw ::CORBA::BAD_PARAM(CORBA::OMGVMCID | 23, CORBA::COMPLETED_NO);
339 ACE_NOTREACHED(break);
341 #if (ERANGE != EINVAL)
342 case ERANGE : // untranslatable character
343 throw ::CORBA::DATA_CONVERSION(CORBA::OMGVMCID | 1, CORBA::COMPLETED_NO);
344 ACE_NOTREACHED(break);
345 #endif
347 default :
348 throw ::CORBA::MARSHAL();
353 ACE_Message_Block::Message_Flags
354 TAO_InputCDR::clr_mb_flags( ACE_Message_Block::Message_Flags less_flags )
356 return start_.clr_self_flags( less_flags );
360 TAO_END_VERSIONED_NAMESPACE_DECL