Go to the documentation of this file.00001 #include "tao/GIOP_Message_Generator_Parser_12.h"
00002 #include "tao/GIOPC.h"
00003 #include "tao/GIOP_Utils.h"
00004 #include "tao/GIOP_Message_Locate_Header.h"
00005 #include "tao/operation_details.h"
00006 #include "tao/debug.h"
00007 #include "tao/Pluggable_Messaging_Utils.h"
00008 #include "tao/GIOP_Message_State.h"
00009 #include "tao/TAO_Server_Request.h"
00010 #include "tao/TAOC.h"
00011 #include "tao/ORB_Core.h"
00012 #include "tao/Transport.h"
00013 #include "tao/CDR.h"
00014
00015 ACE_RCSID (tao,
00016 GIOP_Message_Gen_Parser_12,
00017 "$Id: GIOP_Message_Generator_Parser_12.cpp 87026 2009-10-09 08:33:09Z vzykov $")
00018
00019
00020
00021
00022 static const size_t TAO_GIOP_MESSAGE_ALIGN_PTR = 8;
00023
00024 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00025
00026 bool
00027 TAO_GIOP_Message_Generator_Parser_12::write_request_header (
00028 const TAO_Operation_Details &opdetails,
00029 TAO_Target_Specification &spec,
00030 TAO_OutputCDR &msg)
00031 {
00032
00033 if (!(msg << opdetails.request_id ()))
00034 return false;
00035
00036 CORBA::Octet const response_flags = opdetails.response_flags ();
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 if (response_flags == TAO_TWOWAY_RESPONSE_FLAG)
00050 msg << ACE_OutputCDR::from_octet (3);
00051
00052
00053 else if (response_flags == CORBA::Octet (Messaging::SYNC_NONE)
00054 || response_flags == CORBA::Octet (Messaging::SYNC_WITH_TRANSPORT)
00055 || response_flags == CORBA::Octet (TAO::SYNC_DELAYED_BUFFERING))
00056
00057 msg << ACE_OutputCDR::from_octet (0);
00058
00059 else if (response_flags == CORBA::Octet (Messaging::SYNC_WITH_SERVER))
00060
00061 msg << ACE_OutputCDR::from_octet (1);
00062
00063 else if (response_flags == CORBA::Octet (Messaging::SYNC_WITH_TARGET))
00064
00065 msg << ACE_OutputCDR::from_octet (3);
00066 else
00067
00068 return false;
00069
00070
00071 CORBA::Octet reserved[3] = {0, 0, 0};
00072
00073 msg.write_octet_array (reserved, 3);
00074
00075 if (!this->marshall_target_spec (spec, msg))
00076 return false;
00077
00078
00079 msg.write_string (opdetails.opname_len (),
00080 opdetails.opname ());
00081
00082
00083 if (!(msg << opdetails.request_service_info ()))
00084 return false;
00085
00086
00087 if (opdetails.argument_flag ()
00088 && msg.align_write_ptr (TAO_GIOP_MESSAGE_ALIGN_PTR) == -1)
00089 {
00090 return false;
00091 }
00092
00093 return true;
00094 }
00095
00096 bool
00097 TAO_GIOP_Message_Generator_Parser_12::write_locate_request_header (
00098 CORBA::ULong request_id,
00099 TAO_Target_Specification &spec,
00100 TAO_OutputCDR &msg)
00101 {
00102
00103 if (!(msg << request_id))
00104 return false;
00105
00106
00107 if (!(this->marshall_target_spec (spec, msg)))
00108 return false;
00109
00110
00111
00112
00113
00114
00115
00116
00117 return true;
00118 }
00119
00120 bool
00121 TAO_GIOP_Message_Generator_Parser_12::write_reply_header (
00122 TAO_OutputCDR & output,
00123 TAO_Pluggable_Reply_Params_Base &reply)
00124 {
00125
00126 if (!(output.write_ulong (reply.request_id_)))
00127 return false;
00128
00129
00130 if (!(output.write_ulong (reply.reply_status ())))
00131 return false;
00132
00133 if (!(output << reply.service_context_notowned ()))
00134 return false;
00135
00136 if (reply.argument_flag_)
00137 {
00138
00139
00140 if (output.align_write_ptr (TAO_GIOP_MESSAGE_ALIGN_PTR) == -1)
00141 {
00142 return false;
00143 }
00144 }
00145 return true;
00146 }
00147
00148 bool
00149 TAO_GIOP_Message_Generator_Parser_12::write_locate_reply_mesg (
00150 TAO_OutputCDR & output,
00151 CORBA::ULong request_id,
00152 TAO_GIOP_Locate_Status_Msg &status_info)
00153 {
00154 if (!(output.write_ulong (request_id)))
00155 return false;
00156
00157
00158 if (!(output.write_ulong (status_info.status)))
00159 return false;
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176 switch (status_info.status)
00177 {
00178 case GIOP::OBJECT_FORWARD:
00179
00180
00181 case GIOP::OBJECT_FORWARD_PERM:
00182 {
00183 CORBA::Object_ptr object_ptr =
00184 status_info.forward_location_var.in ();
00185
00186 if (!(output << object_ptr))
00187 {
00188 if (TAO_debug_level > 0)
00189 {
00190 ACE_ERROR ((
00191 LM_ERROR,
00192 ACE_TEXT ("TAO (%P|%t|%N|%l) write_locate_reply_mesg-")
00193 ACE_TEXT (" cannot marshal object reference\n")
00194 ));
00195 }
00196 }
00197 }
00198 break;
00199 case GIOP::LOC_SYSTEM_EXCEPTION:
00200 case GIOP::LOC_NEEDS_ADDRESSING_MODE:
00201
00202
00203
00204 break;
00205 default:
00206 break;
00207 }
00208
00209 return true;
00210 }
00211
00212 bool
00213 TAO_GIOP_Message_Generator_Parser_12::write_fragment_header (
00214 TAO_OutputCDR & cdr,
00215 CORBA::ULong request_id)
00216 {
00217 return (cdr << request_id);
00218
00219
00220
00221
00222 }
00223
00224 int
00225 TAO_GIOP_Message_Generator_Parser_12::parse_request_header (
00226 TAO_ServerRequest &request)
00227 {
00228
00229 TAO_InputCDR & input = *request.incoming ();
00230
00231 CORBA::Boolean hdr_status = (CORBA::Boolean) input.good_bit ();
00232
00233 CORBA::ULong req_id = 0;
00234
00235 hdr_status = hdr_status && input.read_ulong (req_id);
00236
00237 request.request_id (req_id);
00238
00239 CORBA::Octet response_flags = CORBA::Octet();
00240 hdr_status = hdr_status && input.read_octet (response_flags);
00241
00242 request.response_expected ((response_flags > 0));
00243
00244
00245
00246 request.sync_with_server ((response_flags == 1));
00247
00248
00249 input.skip_bytes (3);
00250
00251
00252 hdr_status =
00253 hdr_status && request.profile ().unmarshall_target_address(input);
00254
00255 CORBA::ULong length = 0;
00256 hdr_status = hdr_status && input.read_ulong (length);
00257
00258 if (hdr_status)
00259 {
00260
00261
00262
00263
00264
00265
00266 request.operation (input.rd_ptr (),
00267 length - 1,
00268 0 );
00269 hdr_status = input.skip_bytes (length);
00270 }
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280 IOP::ServiceContextList &req_service_info = request.request_service_info ();
00281
00282 if (!(input >> req_service_info))
00283 {
00284 if (TAO_debug_level)
00285 {
00286 ACE_ERROR ((LM_ERROR,
00287 ACE_TEXT ("TAO (%P|%t) parse_request_header, ")
00288 ACE_TEXT ("extracting context\n")));
00289 }
00290
00291 return -1;
00292 }
00293
00294 if (req_service_info.length() > 0)
00295 {
00296 request.orb_core ()->service_context_registry ().
00297 process_service_contexts (req_service_info, *(request.transport ()));
00298 }
00299
00300 if (input.length () > 0)
00301 {
00302
00303 input.align_read_ptr (TAO_GIOP_MESSAGE_ALIGN_PTR);
00304 }
00305
00306 return hdr_status ? 0 : -1;
00307 }
00308
00309
00310 int
00311 TAO_GIOP_Message_Generator_Parser_12::parse_locate_header (
00312 TAO_GIOP_Locate_Request_Header &request)
00313 {
00314
00315 TAO_InputCDR &msg = request.incoming_stream ();
00316
00317
00318 CORBA::ULong req_id = 0;
00319 CORBA::Boolean hdr_status = msg.read_ulong (req_id);
00320
00321
00322 request.request_id (req_id);
00323
00324
00325 hdr_status =
00326 hdr_status && request.profile ().unmarshall_target_address(msg);
00327
00328
00329 msg.align_read_ptr (TAO_GIOP_MESSAGE_ALIGN_PTR);
00330
00331 return hdr_status ? 0 : -1;
00332 }
00333
00334 int
00335 TAO_GIOP_Message_Generator_Parser_12::parse_reply (
00336 TAO_InputCDR &cdr,
00337 TAO_Pluggable_Reply_Params ¶ms)
00338 {
00339 if (TAO_GIOP_Message_Generator_Parser::parse_reply (cdr, params) == -1)
00340 return -1;
00341
00342 if (!(cdr >> params.svc_ctx_))
00343 {
00344 if (TAO_debug_level)
00345 {
00346 ACE_ERROR ((LM_ERROR,
00347 ACE_TEXT ("TAO (%P|%t) parse_reply, ")
00348 ACE_TEXT ("extracting context\n")));
00349 }
00350
00351 return -1;
00352 }
00353
00354 if (cdr.length () > 0)
00355 {
00356
00357 cdr.align_read_ptr (TAO_GIOP_MESSAGE_ALIGN_PTR);
00358 }
00359
00360 return 0;
00361 }
00362
00363 int
00364 TAO_GIOP_Message_Generator_Parser_12::parse_locate_reply (
00365 TAO_InputCDR &cdr,
00366 TAO_Pluggable_Reply_Params ¶ms)
00367 {
00368 if (TAO_GIOP_Message_Generator_Parser::parse_locate_reply (cdr, params) == -1)
00369 return -1;
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381 return 0;
00382 }
00383
00384
00385 CORBA::Octet
00386 TAO_GIOP_Message_Generator_Parser_12::major_version (void) const
00387 {
00388 return static_cast<CORBA::Octet> (1);
00389 }
00390
00391
00392 CORBA::Octet
00393 TAO_GIOP_Message_Generator_Parser_12::minor_version (void) const
00394 {
00395 return static_cast<CORBA::Octet> (2);
00396 }
00397
00398 bool
00399 TAO_GIOP_Message_Generator_Parser_12::is_ready_for_bidirectional (void) const
00400 {
00401
00402 return true;
00403 }
00404
00405 bool
00406 TAO_GIOP_Message_Generator_Parser_12::marshall_target_spec (
00407 TAO_Target_Specification &spec,
00408 TAO_OutputCDR &msg)
00409 {
00410 switch (spec.specifier ())
00411 {
00412 case TAO_Target_Specification::Key_Addr:
00413 {
00414
00415 if (!(msg << GIOP::KeyAddr))
00416 return false;
00417
00418
00419 const TAO::ObjectKey *key = spec.object_key ();
00420
00421 if (key)
00422 {
00423
00424 if (!(msg << *key))
00425 return false;
00426 }
00427 else
00428 {
00429 if (TAO_debug_level)
00430 {
00431 ACE_DEBUG ((LM_DEBUG,
00432 ACE_TEXT ("(%N |%l) Unable to handle this request\n")));
00433 }
00434 return false;
00435 }
00436 break;
00437 }
00438 case TAO_Target_Specification::Profile_Addr:
00439 {
00440
00441 if (!(msg << GIOP::ProfileAddr))
00442 return false;
00443
00444
00445 const IOP::TaggedProfile *pfile = spec.profile ();
00446
00447 if (pfile)
00448 {
00449
00450 if (!(msg << *pfile))
00451 return false;
00452 }
00453 else
00454 {
00455 if (TAO_debug_level)
00456 {
00457 ACE_DEBUG ((LM_DEBUG,
00458 ACE_TEXT ("(%N |%l) Unable to handle this request\n")));
00459 }
00460 return false;
00461 }
00462 break;
00463 }
00464 case TAO_Target_Specification::Reference_Addr:
00465 {
00466
00467 if (!(msg << GIOP::ReferenceAddr))
00468 return false;
00469
00470
00471 IOP::IOR *ior = 0;
00472 CORBA::ULong const index = spec.iop_ior (ior);
00473
00474 if (ior)
00475 {
00476
00477
00478
00479 if (!(msg << index))
00480 return false;
00481 if (!(msg << *ior))
00482 return false;;
00483 }
00484 else
00485 {
00486 if (TAO_debug_level)
00487 {
00488 ACE_DEBUG ((LM_DEBUG,
00489 ACE_TEXT ("(%N |%l) Unable to handle this request\n")));
00490 }
00491 return false;
00492 }
00493 break;
00494 }
00495 default:
00496 if (TAO_debug_level)
00497 {
00498 ACE_DEBUG ((LM_DEBUG,
00499 ACE_TEXT ("(%N |%l) Unable to handle this request\n")));
00500 }
00501 return false;
00502 }
00503
00504 return true;
00505 }
00506
00507 size_t
00508 TAO_GIOP_Message_Generator_Parser_12::fragment_header_length (void) const
00509 {
00510 return TAO_GIOP_MESSAGE_FRAGMENT_HEADER;
00511 }
00512
00513 TAO_END_VERSIONED_NAMESPACE_DECL