00001
00002
00003 #include "tao/AnyTypeCode/Null_RefCount_Policy.h"
00004 #include "tao/AnyTypeCode/Alias_TypeCode_Static.h"
00005 #include "tao/AnyTypeCode/Value_TypeCode_Static.h"
00006 #include "tao/AnyTypeCode/TypeCode_Constants.h"
00007
00008 #include "tao/Valuetype/ValueBase.h"
00009 #include "tao/Valuetype/ValueFactory.h"
00010
00011 #include "tao/CDR.h"
00012 #include "tao/ORB.h"
00013 #include "tao/ORB_Core.h"
00014 #include "tao/debug.h"
00015 #include "tao/SystemException.h"
00016
00017 #include "ace/OS_NS_string.h"
00018
00019 #if !defined (__ACE_INLINE__)
00020 # include "tao/Valuetype/ValueBase.inl"
00021 #endif
00022
00023 ACE_RCSID (Valuetype,
00024 ValueBase,
00025 "$Id: ValueBase.cpp 88308 2009-12-23 09:13:09Z johnnyw $")
00026
00027 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00028
00029 #define DEFAULT_INDIRECTION_MAP_SIZE 10
00030
00031 #define VERIFY_MAP(CDR, MAPNAME, MAPCLASSNAME) \
00032 if (strm.get_##MAPNAME ().is_nil ()) \
00033 { \
00034 CDR::MAPCLASSNAME##_Handle handle ( \
00035 new CDR::RC_##MAPCLASSNAME (new CDR::MAPCLASSNAME (DEFAULT_INDIRECTION_MAP_SIZE)));\
00036 strm.set_##MAPNAME (handle); \
00037 }
00038
00039
00040
00041 void
00042 CORBA::add_ref (CORBA::ValueBase *val)
00043 {
00044 if (val)
00045 {
00046 val->_add_ref ();
00047 }
00048 }
00049
00050 void
00051 CORBA::remove_ref (CORBA::ValueBase *val)
00052 {
00053 if (val)
00054 {
00055 val->_remove_ref ();
00056 }
00057 }
00058
00059
00060
00061 TAO_ChunkInfo::TAO_ChunkInfo (CORBA::Boolean do_chunking,
00062 CORBA::Long init_level)
00063 : chunking_(do_chunking),
00064 value_nesting_level_(init_level),
00065 chunk_size_pos_ (0),
00066 length_to_chunk_octets_pos_ (0),
00067 chunk_octets_end_pos_ (0)
00068 {
00069 }
00070
00071 CORBA::ValueBase::ValueBase (void)
00072 : is_truncatable_(0),
00073 chunking_(0)
00074 {
00075 }
00076
00077 CORBA::ValueBase::ValueBase (const ValueBase& val)
00078 : is_truncatable_ (val.is_truncatable_),
00079 chunking_ (val.chunking_)
00080 {
00081 }
00082
00083 CORBA::ValueBase::~ValueBase (void)
00084 {
00085 }
00086
00087 CORBA::ValueBase*
00088 CORBA::ValueBase::_downcast (CORBA::ValueBase *vt)
00089 {
00090
00091 return vt;
00092 }
00093
00094 void
00095 CORBA::ValueBase::_tao_any_destructor (void *x)
00096 {
00097 CORBA::ValueBase *tmp = static_cast<CORBA::ValueBase *> (x);
00098 CORBA::remove_ref (tmp);
00099 }
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151 CORBA::Boolean
00152 CORBA::ValueBase::_tao_marshal (TAO_OutputCDR &strm,
00153 const CORBA::ValueBase *this_,
00154 ptrdiff_t formal_type_id)
00155 {
00156 if ( ! _tao_write_special_value (strm, this_))
00157 {
00158 return _tao_write_value (strm, this_, formal_type_id);
00159 }
00160 else
00161 return 1;
00162 }
00163
00164
00165 CORBA::Boolean
00166 CORBA::ValueBase::_tao_unmarshal (TAO_InputCDR &strm,
00167 CORBA::ValueBase *&new_object)
00168 {
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182 CORBA::Boolean is_null_object = false;
00183 CORBA::Boolean is_indirected = false;
00184 CORBA::Boolean const retval =
00185 CORBA::ValueBase::_tao_unmarshal_pre (strm,
00186 new_object,
00187 0,
00188 is_null_object,
00189 is_indirected);
00190
00191 if (!retval)
00192 {
00193 return false;
00194 }
00195
00196 if (is_null_object || is_indirected)
00197 {
00198 return true;
00199 }
00200
00201
00202
00203 if (new_object && ! new_object->_tao_unmarshal_v (strm))
00204 {
00205 return false;
00206 }
00207
00208 return retval;
00209 }
00210
00211
00212 CORBA::Boolean
00213 CORBA::ValueBase::_tao_unmarshal_pre (TAO_InputCDR &strm,
00214 CORBA::ValueBase *&valuetype,
00215 const char * const repo_id,
00216 CORBA::Boolean& is_null_object,
00217 CORBA::Boolean& is_indirected)
00218 {
00219 void* pos = strm.rd_ptr();
00220
00221
00222
00223 CORBA::ValueFactory_var factory;
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247 CORBA::Long valuetag;
00248 Repository_Id_List ids;
00249 ACE_CString codebase_url;
00250
00251 is_indirected = false;
00252 is_null_object = false;
00253
00254 if (! strm.read_long (valuetag))
00255 {
00256 return false;
00257 }
00258
00259 if (TAO_OBV_GIOP_Flags::is_indirection_tag (valuetag))
00260 {
00261 is_indirected = true;
00262
00263
00264 return _tao_unmarshal_value_indirection (strm, valuetype);
00265 }
00266
00267 if (TAO_OBV_GIOP_Flags::is_null_ref (valuetag))
00268 {
00269
00270 valuetype = 0;
00271 is_null_object = true;
00272 return true;
00273 }
00274
00275 if (TAO_OBV_GIOP_Flags::has_codebase_url (valuetag))
00276 {
00277 ACE_CString codebase_url;
00278 if (! _tao_read_codebase_url (strm, codebase_url))
00279 {
00280 return false;
00281 }
00282 }
00283
00284 if (TAO_OBV_GIOP_Flags::has_single_type_info (valuetag))
00285 {
00286 ACE_CString id;
00287 if (! _tao_read_repository_id(strm, id))
00288 {
00289 return false;
00290 }
00291
00292 ids.push_back (id);
00293 }
00294 else if (TAO_OBV_GIOP_Flags::has_list_type_info (valuetag))
00295 {
00296 if (! _tao_read_repository_id_list(strm, ids))
00297 {
00298 return false;
00299 }
00300 }
00301 else if (TAO_OBV_GIOP_Flags::has_no_type_info (valuetag))
00302 {
00303 ids.push_back (repo_id);
00304 }
00305 else
00306 {
00307 if (TAO_debug_level > 0)
00308 {
00309 ACE_ERROR ((LM_ERROR,
00310 ACE_TEXT ("TAO (%P|%t) - ValueBase::_tao_unmarshal_pre, ")
00311 ACE_TEXT ("unknown value tag: %x\n"),
00312 valuetag));
00313 }
00314
00315 return 0;
00316 }
00317
00318 TAO_ORB_Core *orb_core = strm.orb_core ();
00319
00320 if (orb_core == 0)
00321 {
00322 orb_core = TAO_ORB_Core_instance ();
00323
00324 if (TAO_debug_level > 0)
00325 {
00326 ACE_DEBUG ((LM_WARNING,
00327 ACE_TEXT ("TAO (%P|%t) - ValueBase::_tao_unmarshal_pre, ")
00328 ACE_TEXT ("WARNING: extracting valuetype using ")
00329 ACE_TEXT ("default ORB_Core\n")));
00330 }
00331 }
00332
00333 CORBA::Boolean require_truncation = false;
00334 CORBA::Boolean const chunking =
00335 TAO_OBV_GIOP_Flags::is_chunked (valuetag);
00336 CORBA::ULong const num_ids = ids.size ();
00337
00338
00339
00340
00341 for (CORBA::ULong i = 0; i < num_ids; ++i)
00342 {
00343 factory = orb_core->orb ()->lookup_value_factory (ids[i].c_str ());
00344
00345 if (factory.in() != 0)
00346 {
00347 if (i != 0 && chunking)
00348 {
00349 require_truncation = true;
00350 }
00351 break;
00352 }
00353 }
00354
00355 if (factory.in() == 0)
00356 {
00357 if (TAO_debug_level > 0)
00358 {
00359 ACE_ERROR ((LM_ERROR,
00360 ACE_TEXT ("TAO (%P|%t) - ValueBase::_tao_unmarshal_pre, ")
00361 ACE_TEXT ("OBV factory is null, id = %C\n"),
00362 repo_id));
00363 }
00364
00365 throw ::CORBA::MARSHAL (CORBA::OMGVMCID | 1, CORBA::COMPLETED_MAYBE);
00366 }
00367
00368 valuetype = factory->create_for_unmarshal ();
00369
00370 if (require_truncation)
00371 {
00372 valuetype->truncation_hook ();
00373 }
00374
00375 if (valuetype == 0)
00376 {
00377 return 0;
00378 }
00379
00380 valuetype->chunking_ = chunking;
00381
00382 VERIFY_MAP(TAO_InputCDR, value_map, Value_Map)
00383
00384 if (strm.get_value_map ()->get()->bind (pos, valuetype ) != 0)
00385 throw CORBA::INTERNAL ();
00386 else if (TAO_debug_level > 0)
00387 {
00388 ACE_DEBUG ((LM_DEBUG,
00389 ACE_TEXT ("TAO (%P|%t) - ValueBase::_tao_unmarshal_pre, bound value %X - %X\n"),
00390 pos, valuetype));
00391 }
00392 return true;
00393 }
00394
00395 CORBA::Boolean
00396 CORBA::ValueBase::_tao_unmarshal_post (TAO_InputCDR &)
00397 {
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411 return true;
00412 }
00413
00414
00415 CORBA::Boolean
00416 CORBA::ValueBase::_tao_validate_box_type (TAO_InputCDR &strm,
00417 TAO_InputCDR &indirected_strm,
00418 const char * const repo_id_expected,
00419 CORBA::Boolean & null_object,
00420 CORBA::Boolean & is_indirected)
00421 {
00422 CORBA::Long value_tag;
00423 null_object = false;
00424 is_indirected = false;
00425
00426 if (!strm.read_long (value_tag))
00427 {
00428 return false;
00429 }
00430
00431 if (TAO_OBV_GIOP_Flags::is_null_ref (value_tag))
00432 {
00433 null_object = true;
00434 return true;
00435 }
00436
00437 if (TAO_OBV_GIOP_Flags::is_indirection_tag (value_tag))
00438 {
00439 is_indirected = true;
00440
00441
00442 return _tao_unmarshal_value_indirection_pre (strm, indirected_strm);
00443 }
00444
00445 if (!TAO_OBV_GIOP_Flags::is_value_tag (value_tag))
00446 {
00447 ACE_DEBUG ((LM_DEBUG,
00448 ACE_TEXT ("TAO (%P|%t) - CORBA::ValueBase::_tao_validate_box_type, ")
00449 ACE_TEXT ("not value_tag\n")));
00450 return false;
00451 }
00452
00453
00454 if (TAO_OBV_GIOP_Flags::has_codebase_url (value_tag))
00455 {
00456
00457 ACE_CString codebase_url;
00458 if (! _tao_read_codebase_url (strm, codebase_url))
00459 {
00460 return false;
00461 }
00462 }
00463
00464 if (TAO_OBV_GIOP_Flags::has_no_type_info (value_tag))
00465 {
00466
00467 return true;
00468 }
00469
00470 if (TAO_OBV_GIOP_Flags::has_single_type_info (value_tag))
00471 {
00472
00473 ACE_CString id;
00474 if (! _tao_read_repository_id (strm, id))
00475 {
00476 return false;
00477 }
00478
00479 if (!ACE_OS::strcmp (id.c_str(), repo_id_expected))
00480 {
00481 return true;
00482 }
00483 }
00484
00485 if (TAO_OBV_GIOP_Flags::has_list_type_info (value_tag))
00486 {
00487
00488
00489 return false;
00490 }
00491
00492 return false;
00493 }
00494
00495 CORBA::Boolean
00496 CORBA::ValueBase::_tao_unmarshal_value_indirection_pre (TAO_InputCDR &strm,
00497 TAO_InputCDR &indirected_strm)
00498 {
00499 CORBA::Long offset = 0;
00500 if (!strm.read_long (offset) || offset >= 0)
00501 {
00502 return false;
00503 }
00504
00505 size_t const buffer_size = -(offset) + sizeof (CORBA::Long);
00506
00507 indirected_strm = TAO_InputCDR (strm.rd_ptr () + offset - sizeof (CORBA::Long),
00508 buffer_size,
00509 strm.byte_order ());
00510
00511 indirected_strm.set_repo_id_map (strm.get_repo_id_map ());
00512 indirected_strm.set_codebase_url_map (strm.get_codebase_url_map ());
00513 indirected_strm.set_value_map (strm.get_value_map ());
00514 return indirected_strm.good_bit ();
00515 }
00516
00517 CORBA::Boolean
00518 CORBA::ValueBase::_tao_unmarshal_value_indirection (TAO_InputCDR &strm,
00519 CORBA::ValueBase *&value)
00520 {
00521 if (strm.get_value_map().is_nil ())
00522 throw CORBA::INTERNAL ();
00523
00524 CORBA::Long offset = 0;
00525 if (!strm.read_long (offset) || offset >= 0)
00526 {
00527 return 0;
00528 }
00529
00530 void* pos = strm.rd_ptr () + offset - sizeof (CORBA::Long);
00531
00532 if (TAO_debug_level > 9)
00533 {
00534 ACE_DEBUG ((LM_DEBUG,
00535 ACE_TEXT ("TAO (%P|%t) ValueBase::_tao_unmarshal_value_indirection, pos %X \n"), pos));
00536 TAO_InputCDR::Value_Map* map = strm.get_value_map()->get ();
00537 for (TAO_InputCDR::Value_Map::ITERATOR it = map->begin (); it != map->end (); ++ it)
00538 {
00539 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("TAO (%P|%t) ValueBase::_tao_unmarshal_value_indirection, %X - %X \n"), it->ext_id_, it->int_id_));
00540 }
00541 }
00542 void * v = 0;
00543 if (strm.get_value_map()->get()->find (pos, v) != 0)
00544 {
00545 throw CORBA::INTERNAL ();
00546 }
00547 else if (TAO_debug_level > 0)
00548 {
00549 ACE_DEBUG ((LM_DEBUG,
00550 ACE_TEXT ("TAO (%P|%t) - ValueBase::_tao_unmarshal_value_indirection, found %X - %X\n"),
00551 pos,v));
00552 }
00553
00554 value = reinterpret_cast<CORBA::ValueBase *>(v);
00555 return true;
00556 }
00557
00558
00559 CORBA::Boolean
00560 CORBA::ValueBase::_tao_unmarshal_repo_id_indirection (TAO_InputCDR &strm,
00561 ACE_CString& id)
00562 {
00563 CORBA::Long offset = 0;
00564 if (!strm.read_long (offset) || offset >= 0)
00565 {
00566 return false;
00567 }
00568
00569 void* pos = strm.rd_ptr () + offset - sizeof (CORBA::Long);
00570 if (strm.get_repo_id_map()->get()->find (pos, id) != 0)
00571 {
00572 throw CORBA::INTERNAL ();
00573 }
00574 else if (TAO_debug_level > 0)
00575 {
00576 ACE_DEBUG ((LM_DEBUG,
00577 ACE_TEXT ("TAO (%P|%t) - ValueBase::_tao_unmarshal_repo_id_indirection, found %X - %C\n"),
00578 pos, id.c_str ()));
00579 }
00580
00581 return 1;
00582 }
00583
00584 CORBA::Boolean
00585 CORBA::ValueBase::_tao_unmarshal_codebase_url_indirection (TAO_InputCDR &strm,
00586 ACE_CString& codebase_url)
00587 {
00588 CORBA::Long offset = 0;
00589 if (!strm.read_long (offset) || offset >= 0)
00590 {
00591 return false;
00592 }
00593
00594 void* pos = strm.rd_ptr () + offset - sizeof (CORBA::Long);
00595
00596 if (strm.get_codebase_url_map()->get()->find (pos, codebase_url) != 0)
00597 {
00598 throw CORBA::INTERNAL ();
00599 }
00600 else if (TAO_debug_level > 0)
00601 {
00602 ACE_DEBUG ((LM_DEBUG,
00603 ACE_TEXT ("TAO (%P|%t) - ValueBase::_tao_unmarshal_codebase_url_indirection, found %X - %C\n"),
00604 pos, codebase_url.c_str ()));
00605 }
00606
00607 return 1;
00608 }
00609
00610
00611 #if defined (GEN_OSTREAM_OPS)
00612
00613 std::ostream &
00614 CORBA::ValueBase::_tao_stream (std::ostream &strm,
00615 const CORBA::ValueBase *value)
00616 {
00617 return value->_tao_stream_v (strm);
00618 }
00619
00620 std::ostream &
00621 CORBA::ValueBase::_tao_stream_v (std::ostream &strm) const
00622 {
00623 return strm << "CORBA::ValueBase";
00624 }
00625
00626 #endif
00627
00628
00629
00630
00631 CORBA::Boolean
00632 CORBA::ValueBase::_tao_write_special_value (TAO_OutputCDR &strm,
00633 const CORBA::ValueBase *value)
00634 {
00635
00636 if (value == 0)
00637 {
00638 return strm.write_long (TAO_OBV_GIOP_Flags::Null_tag);
00639 }
00640 else
00641 {
00642 #ifdef TAO_HAS_VALUETYPE_OUT_INDIRECTION
00643
00644
00645 VERIFY_MAP(TAO_OutputCDR, value_map, Value_Map)
00646
00647 char* pos = 0;
00648 if (strm.get_value_map ()->get()->find (
00649 reinterpret_cast<void*>(const_cast <CORBA::ValueBase *> (value)), pos) == 0)
00650 {
00651 if (TAO_debug_level > 0)
00652 {
00653 ACE_DEBUG ((LM_DEBUG,
00654 ACE_TEXT ("(%P|%t)ValueBase::_tao_write_special_value found value %X - %X\n"),
00655 value, pos));
00656 }
00657
00658 if (! strm.write_long (TAO_OBV_GIOP_Flags::Indirection_tag))
00659 {
00660 return false;
00661 }
00662
00663 CORBA::Long const offset = - strm.offset (pos);
00664 if (TAO_debug_level > 0)
00665 {
00666 ACE_DEBUG ((LM_DEBUG,
00667 ACE_TEXT ("TAO (%P|%t) - ValueBase::_tao_write_special_value value, indirection %d\n"), offset));
00668 }
00669
00670 return strm.write_long (offset);
00671 }
00672 else {
00673 if (strm.align_write_ptr (ACE_CDR::LONG_SIZE) != 0)
00674 {
00675 throw CORBA::INTERNAL ();
00676 }
00677 if (strm.get_value_map ()->get()->bind (
00678 reinterpret_cast<void*>(const_cast <CORBA::ValueBase *> (value)),
00679 strm.current()->wr_ptr() ) != 0)
00680 {
00681 throw CORBA::INTERNAL ();
00682 }
00683 else if (TAO_debug_level > 0)
00684 {
00685 ACE_DEBUG ((LM_DEBUG,
00686 ACE_TEXT ("(%P|%t)ValueBase::_tao_marshal bound value %X - %X \n"),
00687 value, strm.current()->wr_ptr()));
00688 }
00689
00690 return false;
00691 }
00692 #endif
00693
00694 return false;
00695 }
00696 }
00697
00698
00699 CORBA::Boolean
00700 CORBA::ValueBase::_tao_write_value (TAO_OutputCDR &strm,
00701 const CORBA::ValueBase * value,
00702 ptrdiff_t formal_type_id)
00703 {
00704 if (! value->_tao_write_value_header (strm, formal_type_id))
00705 {
00706 return false;
00707 }
00708
00709 if (! value->_tao_marshal_v (strm))
00710 {
00711 return false;
00712 }
00713
00714 return true;
00715 }
00716
00717
00718 CORBA::Boolean
00719 CORBA::ValueBase::_tao_write_value_header (TAO_OutputCDR &strm,
00720 ptrdiff_t formal_type_id) const
00721 {
00722 #ifdef TAO_HAS_OPTIMIZED_VALUETYPE_MARSHALING
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732 CORBA::Boolean const is_formal_type =
00733 this->_tao_match_formal_type (formal_type_id);
00734 #else
00735
00736
00737
00738
00739 CORBA::Boolean const is_formal_type = 0;
00740 ACE_UNUSED_ARG (formal_type_id);
00741 #endif
00742
00743
00744 Repository_Id_List repository_ids;
00745 this->_tao_obv_truncatable_repo_ids (repository_ids);
00746 CORBA::Long const num_ids =
00747 static_cast <CORBA::Long> (repository_ids.size ());
00748
00749
00750
00751
00752
00753 CORBA::Long valuetag = TAO_OBV_GIOP_Flags::Value_tag_base;
00754
00755
00756
00757 if (this->is_truncatable_ || this->chunking_)
00758 valuetag |= TAO_OBV_GIOP_Flags::Chunking_tag_sigbits;
00759
00760 if (!is_formal_type || this->is_truncatable_)
00761 valuetag |= TAO_OBV_GIOP_Flags::Type_info_single;
00762
00763 if (num_ids > 1)
00764 {
00765 valuetag |= TAO_OBV_GIOP_Flags::Type_info_list;
00766 }
00767
00768 if (! strm.write_long (valuetag)
00769 || (num_ids > 1 && !strm.write_long (num_ids)))
00770 {
00771 return false;
00772 }
00773
00774 #ifndef TAO_HAS_OPTIMIMIZED_VALUETYPE_MARSHALING
00775 if (this->is_truncatable_
00776 || !is_formal_type
00777
00778
00779 || num_ids > 1)
00780 {
00781 #endif
00782
00783 for (CORBA::Long i = 0; i < num_ids; ++i )
00784 {
00785 if (! _tao_write_repository_id (strm, repository_ids[i]))
00786 {
00787 return false;
00788 }
00789 }
00790 #ifndef TAO_HAS_OPTIMIMIZED_VALUETYPE_MARSHALING
00791 }
00792 #endif
00793
00794 return true;
00795 }
00796
00797
00798 CORBA::Boolean
00799 CORBA::ValueBase::_tao_write_repository_id (TAO_OutputCDR &strm,
00800 ACE_CString& id)
00801 {
00802 #ifdef TAO_HAS_VALUETYPE_OUT_INDIRECTION
00803
00804 VERIFY_MAP(TAO_OutputCDR, repo_id_map, Repo_Id_Map)
00805
00806 if (strm.get_repo_id_map().is_nil ())
00807 {
00808 throw CORBA::INTERNAL ();
00809 }
00810
00811 char* pos = 0;
00812 if (strm.get_repo_id_map ()->get()->find (id, pos) == 0)
00813 {
00814 if (! strm.write_long (TAO_OBV_GIOP_Flags::Indirection_tag))
00815 return 0;
00816
00817 CORBA::Long offset = - strm.offset (pos);
00818
00819 if (TAO_debug_level > 0)
00820 {
00821 ACE_DEBUG ((LM_DEBUG,
00822 ACE_TEXT ("TAO (%P|%t) - ValueBase::_tao_write_repository_id, id %C indirection %d\n"),
00823 id.c_str(), offset));
00824 }
00825
00826 if (! strm.write_long (offset))
00827 return false;
00828 }
00829 else
00830 {
00831 if (strm.align_write_ptr (ACE_CDR::LONG_SIZE) != 0)
00832 {
00833 throw CORBA::INTERNAL ();
00834 }
00835
00836 if (strm.get_repo_id_map ()->get ()->bind (id, strm.current()->wr_ptr ()) != 0)
00837 {
00838 throw CORBA::INTERNAL ();
00839 }
00840 else if (TAO_debug_level > 0)
00841 {
00842 ACE_DEBUG ((LM_DEBUG,
00843 ACE_TEXT ("TAO (%P|%t) - ValueBase::_tao_write_repository_id, bound %C - %X\n"),
00844 id.c_str (), strm.current()->wr_ptr ()));
00845 }
00846 if (! strm.write_string (id.c_str ()))
00847 return false;
00848 }
00849 #else
00850 if (! strm.write_string (id.c_str ()))
00851 return 0;
00852 #endif
00853
00854 return 1;
00855 }
00856
00857
00858 CORBA::Boolean
00859 TAO_ChunkInfo::start_chunk(TAO_OutputCDR &strm)
00860 {
00861
00862
00863 if (this->chunking_)
00864 {
00865 if (! reserve_chunk_size(strm))
00866 {
00867 return false;
00868 }
00869
00870 ++this->value_nesting_level_;
00871 }
00872
00873 return true;
00874 }
00875
00876
00877 CORBA::Boolean
00878 TAO_ChunkInfo::end_chunk(TAO_OutputCDR &strm)
00879 {
00880 if (this->chunking_)
00881 {
00882
00883 if (! this->write_previous_chunk_size(strm))
00884 {
00885 return false;
00886 }
00887
00888
00889 if (! strm.write_long(- this->value_nesting_level_))
00890 {
00891 return false;
00892 }
00893
00894
00895 if ( -- this->value_nesting_level_ == 0 )
00896 {
00897
00898 this->chunking_ = 0;
00899 }
00900 }
00901 return true;
00902 }
00903
00904
00905 CORBA::Boolean
00906 TAO_ChunkInfo::write_previous_chunk_size(TAO_OutputCDR &strm)
00907 {
00908 if (this->chunk_size_pos_ != 0)
00909 {
00910
00911 CORBA::Long const chunk_size = strm.total_length () - this->length_to_chunk_octets_pos_;
00912
00913
00914
00915
00916
00917 if (chunk_size == 0)
00918 {
00919 return false;
00920 }
00921
00922
00923
00924 if (!strm.replace (chunk_size, this->chunk_size_pos_))
00925 {
00926 return false;
00927 }
00928
00929
00930 this->chunk_size_pos_ = 0;
00931 this->length_to_chunk_octets_pos_ = 0;
00932 }
00933
00934 return true;
00935 }
00936
00937
00938 CORBA::Boolean
00939 TAO_ChunkInfo::reserve_chunk_size(TAO_OutputCDR &strm)
00940 {
00941
00942
00943
00944
00945
00946
00947 if (this->chunk_size_pos_ == 0)
00948 {
00949
00950 strm.align_write_ptr (ACE_CDR::LONG_SIZE);
00951
00952
00953 this->chunk_size_pos_ = strm.current ()->wr_ptr ();
00954
00955
00956
00957 if (! strm.write_long (0))
00958 {
00959 return 0;
00960 }
00961
00962
00963
00964 this->length_to_chunk_octets_pos_ = strm.total_length ();
00965 }
00966
00967 return 1;
00968 }
00969
00970 CORBA::Boolean
00971 TAO_ChunkInfo::handle_chunking (TAO_InputCDR &strm)
00972 {
00973 if (!this->chunking_)
00974 {
00975 return 1;
00976 }
00977
00978 char* the_rd_ptr = strm.start()->rd_ptr ();
00979
00980
00981
00982
00983
00984
00985 if (the_rd_ptr < this->chunk_octets_end_pos_)
00986 {
00987 ++this->value_nesting_level_;
00988 return 1;
00989 }
00990
00991
00992 if (this->chunk_octets_end_pos_ != 0
00993 && the_rd_ptr > this->chunk_octets_end_pos_)
00994 {
00995 return 0;
00996 }
00997
00998
00999
01000 CORBA::Long tag;
01001
01002 if (!strm.read_long (tag))
01003 {
01004 return 0;
01005 }
01006
01007 if (tag < 0)
01008 {
01009
01010 if (-tag > this->value_nesting_level_)
01011 {
01012 ACE_ERROR_RETURN ((LM_ERROR,
01013 ACE_TEXT ("TAO (%P|%t) - TAO_ChunkInfo::handle_chunking, received end tag ")
01014 ACE_TEXT ("%d > value_nesting_level %d\n"),
01015 -tag,
01016 this->value_nesting_level_),
01017 0);
01018 }
01019
01020 this->value_nesting_level_ = - tag;
01021 --this->value_nesting_level_;
01022
01023 this->chunk_octets_end_pos_ = 0;
01024
01025
01026
01027 if (this->value_nesting_level_ > 0)
01028 {
01029 this->handle_chunking(strm);
01030 }
01031 }
01032 else if (tag < TAO_OBV_GIOP_Flags::Value_tag_base)
01033 {
01034
01035 this->chunk_octets_end_pos_ = strm.rd_ptr () + tag;
01036 ++this->value_nesting_level_;
01037 }
01038 else
01039 {
01040
01041
01042
01043 return 0;
01044 }
01045
01046 return 1;
01047 }
01048
01049
01050 CORBA::Boolean
01051 TAO_ChunkInfo::skip_chunks (TAO_InputCDR &strm)
01052 {
01053 if (!this->chunking_)
01054 {
01055 return 1;
01056 }
01057
01058
01059
01060
01061 CORBA::Long tag;
01062 if (!strm.read_long(tag))
01063 {
01064 return 0;
01065 }
01066
01067
01068 if (tag == -1)
01069 {
01070 return 1;
01071 }
01072 else if (tag < 0)
01073 {
01074
01075 return this->skip_chunks (strm);
01076 }
01077 else if (tag < TAO_OBV_GIOP_Flags::Value_tag_base)
01078 {
01079
01080 ACE_Message_Block* current =
01081 const_cast<ACE_Message_Block*>(strm.start ());
01082 current->rd_ptr (tag);
01083 return this->skip_chunks (strm);
01084 }
01085 else
01086 return 0;
01087 }
01088
01089 CORBA::Boolean
01090 CORBA::ValueBase::_tao_read_repository_id_list (TAO_InputCDR& strm,
01091 Repository_Id_List& ids)
01092 {
01093 CORBA::Long num_ids = 0;
01094
01095 if (!strm.read_long (num_ids))
01096 {
01097 return 0;
01098 }
01099
01100 if (num_ids == TAO_OBV_GIOP_Flags::Indirection_tag)
01101 {
01102
01103 return 0;
01104 }
01105 else
01106 {
01107 for (CORBA::Long i = 0; i < num_ids; ++i)
01108 {
01109 ACE_CString id;
01110 if (!_tao_read_repository_id (strm, id))
01111 {
01112 return 0;
01113 }
01114 ids.push_back (id);
01115 }
01116 }
01117
01118 return 1;
01119 }
01120
01121 CORBA::Boolean
01122 CORBA::ValueBase::_tao_read_repository_id (TAO_InputCDR& strm,
01123 ACE_CString& id)
01124 {
01125 CORBA::ULong length = 0;
01126
01127 size_t buffer_size = strm.length();
01128
01129 if (!strm.read_ulong (length))
01130 {
01131 return 0;
01132 }
01133
01134 VERIFY_MAP(TAO_InputCDR, repo_id_map, Repo_Id_Map)
01135
01136 if (strm.get_repo_id_map ().is_nil ())
01137 throw CORBA::INTERNAL ();
01138
01139 char * pos = strm.rd_ptr();
01140
01141
01142
01143
01144
01145
01146 if (TAO_OBV_GIOP_Flags::is_indirection_tag (length))
01147 {
01148 return _tao_unmarshal_repo_id_indirection (strm, id);
01149 }
01150
01151 pos -= sizeof (CORBA::ULong);
01152
01153
01154 TAO_InputCDR id_stream (pos,
01155 buffer_size,
01156 strm.byte_order ());
01157
01158 if (!id_stream.good_bit ())
01159 {
01160 return 0;
01161 }
01162
01163 if (! id_stream.read_string (id))
01164 return 0;
01165
01166
01167
01168 ACE_CString mapped_id;
01169 if (strm.get_repo_id_map ()->get()->find (pos, mapped_id) == 0)
01170 {
01171 if (TAO_debug_level > 0)
01172 {
01173 ACE_DEBUG ((LM_DEBUG,
01174 ACE_TEXT ("TAO (%P|%t) - ValueBase::_tao_read_repository_id, found %X - %C\n"),
01175 pos, mapped_id.c_str ()));
01176 }
01177
01178 if (ACE_OS::strcmp (mapped_id.c_str (), id.c_str ()) != 0)
01179 throw CORBA::INTERNAL ();
01180 }
01181 else if (strm.get_repo_id_map ()->get ()->bind (pos, id) != 0)
01182 {
01183 throw CORBA::INTERNAL ();
01184 }
01185 else if (TAO_debug_level > 0)
01186 {
01187 ACE_DEBUG ((LM_DEBUG,
01188 ACE_TEXT ("TAO (%P|%t) - ValueBase::_tao_read_repository_id, bound %X - %C\n"),
01189 pos, id.c_str ()));
01190 }
01191
01192
01193
01194
01195
01196 strm.skip_bytes (length);
01197
01198 return 1;
01199 }
01200
01201
01202 CORBA::Boolean
01203 CORBA::ValueBase::_tao_read_codebase_url (TAO_InputCDR& strm,
01204 ACE_CString& codebase_url)
01205 {
01206 CORBA::ULong length = 0;
01207
01208 size_t buffer_size = strm.length();
01209
01210 if (!strm.read_ulong (length))
01211 {
01212 return 0;
01213 }
01214
01215 VERIFY_MAP(TAO_InputCDR, codebase_url_map, Codebase_URL_Map)
01216
01217 char * pos = strm.rd_ptr();
01218
01219
01220
01221
01222
01223
01224 if (TAO_OBV_GIOP_Flags::is_indirection_tag (length))
01225 {
01226 return _tao_unmarshal_codebase_url_indirection (strm, codebase_url);
01227 }
01228
01229 pos -= sizeof (CORBA::ULong);
01230
01231
01232 TAO_InputCDR url_stream (pos,
01233 buffer_size,
01234 strm.byte_order ());
01235
01236 if (!url_stream.good_bit ())
01237 {
01238 return 0;
01239 }
01240
01241 if (! url_stream.read_string (codebase_url))
01242 return 0;
01243
01244
01245
01246 ACE_CString mapped_url;
01247 if (strm.get_codebase_url_map ()->get()->find (pos, mapped_url) == 0)
01248 {
01249 if (TAO_debug_level > 0)
01250 {
01251 ACE_DEBUG ((LM_DEBUG,
01252 ACE_TEXT ("TAO (%P|%t) - ValueBase::_tao_read_codebase_url, found %X - %C\n"),
01253 pos, mapped_url.c_str ()));
01254 }
01255 if (ACE_OS::strcmp (mapped_url.c_str (), codebase_url.c_str ()) != 0)
01256 throw CORBA::INTERNAL ();
01257 }
01258 else if (strm.get_codebase_url_map ()->get()->bind (pos, codebase_url) != 0)
01259 {
01260 throw CORBA::INTERNAL ();
01261 }
01262 else
01263 {
01264 if (TAO_debug_level > 0)
01265 {
01266 ACE_DEBUG ((LM_DEBUG,
01267 ACE_TEXT ("TAO (%P|%t) - ValueBase::_tao_read_codebase_url, bound %X - %C\n"),
01268 pos, codebase_url.c_str ()));
01269 }
01270 }
01271
01272
01273
01274
01275
01276 strm.skip_bytes (length);
01277
01278 return 1;
01279 }
01280
01281
01282 void
01283 CORBA::ValueBase::truncation_hook ()
01284 {
01285 throw ::CORBA::INTERNAL ();
01286 }
01287
01288
01289
01290
01291 namespace TAO
01292 {
01293 namespace TypeCode
01294 {
01295 char const tc_value_base_id[] = "IDL:omg.org/CORBA/ValueBase:1.0";
01296 char const tc_value_base_name[] = "ValueBase";
01297 Value<char const *,
01298 CORBA::TypeCode_ptr const *,
01299 Value_Field<char const *, CORBA::TypeCode_ptr const *> const *,
01300 TAO::Null_RefCount_Policy> tc_ValueBase (CORBA::tk_value,
01301 tc_value_base_id,
01302 tc_value_base_name,
01303 CORBA::VM_NONE,
01304 &CORBA::_tc_null,
01305 0,
01306 0);
01307
01308 char const tc_event_base_id[] = "IDL:omg.org/CORBA/EventBase:1.0";
01309 char const tc_event_base_name[] = "EventBase";
01310 Value<char const *,
01311 CORBA::TypeCode_ptr const *,
01312 Value_Field<char const *, CORBA::TypeCode_ptr const *> const *,
01313 TAO::Null_RefCount_Policy> tc_EventBase (CORBA::tk_event,
01314 tc_event_base_id,
01315 tc_event_base_name,
01316 CORBA::VM_NONE,
01317 &CORBA::_tc_null,
01318 0,
01319 0);
01320 }
01321 }
01322
01323 namespace CORBA
01324 {
01325 TypeCode_ptr const _tc_ValueBase = &TAO::TypeCode::tc_ValueBase;
01326 TypeCode_ptr const _tc_EventBase = &TAO::TypeCode::tc_EventBase;
01327 }
01328
01329
01330
01331
01332 CORBA::DefaultValueRefCountBase::~DefaultValueRefCountBase (void)
01333 {
01334 }
01335
01336 void
01337 CORBA::DefaultValueRefCountBase::_add_ref (void)
01338 {
01339 this->_tao_add_ref ();
01340 }
01341
01342 void
01343 CORBA::DefaultValueRefCountBase::_remove_ref (void)
01344 {
01345 this->_tao_remove_ref ();
01346 }
01347
01348 CORBA::ULong
01349 CORBA::DefaultValueRefCountBase::_refcount_value (void)
01350 {
01351 return this->_tao_refcount_value ();
01352 }
01353
01354
01355
01356 CORBA::DefaultValueRefCountBase::DefaultValueRefCountBase (void)
01357 : refcount_ (1)
01358 {
01359 }
01360
01361
01362
01363 CORBA::DefaultValueRefCountBase::DefaultValueRefCountBase
01364 (const DefaultValueRefCountBase& rhs)
01365 : ValueBase (rhs),
01366 refcount_ (1)
01367
01368 {
01369 }
01370
01371
01372 void
01373 CORBA::DefaultValueRefCountBase::_tao_add_ref (void)
01374 {
01375 ++this->refcount_;
01376 }
01377
01378 void
01379 CORBA::DefaultValueRefCountBase::_tao_remove_ref (void)
01380 {
01381 CORBA::ULong const new_count = --this->refcount_;
01382
01383 if (new_count == 0)
01384 delete this;
01385 }
01386
01387 CORBA::ULong
01388 CORBA::DefaultValueRefCountBase::_tao_refcount_value (void)
01389 {
01390 return this->refcount_.value ();
01391 }
01392
01393
01394
01395 CORBA::Boolean
01396 operator<< (TAO_OutputCDR &strm,
01397 const CORBA::ValueBase *_tao_valuetype)
01398 {
01399 return CORBA::ValueBase::_tao_marshal (
01400 strm,
01401 _tao_valuetype,
01402 reinterpret_cast<ptrdiff_t> (&CORBA::ValueBase::_downcast)
01403 );
01404 }
01405
01406 CORBA::Boolean
01407 operator>> (TAO_InputCDR &strm,
01408 CORBA::ValueBase *&_tao_valuetype)
01409 {
01410 return CORBA::ValueBase::_tao_unmarshal (strm, _tao_valuetype);
01411 }
01412
01413 #if defined (GEN_OSTREAM_OPS)
01414
01415 std::ostream&
01416 operator<< (std::ostream &strm,
01417 CORBA::ValueBase *_tao_valuetype)
01418 {
01419 return CORBA::ValueBase::_tao_stream (strm, _tao_valuetype);
01420 }
01421
01422 #endif
01423
01424
01425 namespace TAO
01426 {
01427 void
01428 Value_Traits<CORBA::ValueBase>::add_ref (
01429 CORBA::ValueBase *p)
01430 {
01431 CORBA::add_ref (p);
01432 }
01433
01434 void
01435 Value_Traits<CORBA::ValueBase>::remove_ref (
01436 CORBA::ValueBase * p)
01437 {
01438 CORBA::remove_ref (p);
01439 }
01440
01441 void
01442 Value_Traits<CORBA::ValueBase>::release (
01443 CORBA::ValueBase * p)
01444 {
01445 CORBA::remove_ref (p);
01446 }
01447 }
01448
01449 TAO_END_VERSIONED_NAMESPACE_DECL