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