Go to the documentation of this file.00001
00002
00003 #include "tao/Valuetype/AbstractBase.h"
00004 #include "tao/Valuetype/ValueBase.h"
00005 #include "tao/Valuetype/ValueFactory.h"
00006 #include "tao/AnyTypeCode/Objref_TypeCode_Static.h"
00007 #include "tao/Stub.h"
00008 #include "tao/ORB_Core.h"
00009 #include "tao/Profile.h"
00010 #include "tao/debug.h"
00011 #include "tao/CDR.h"
00012
00013 #if !defined (__ACE_INLINE__)
00014 # include "tao/Valuetype/AbstractBase.inl"
00015 #endif
00016
00017 ACE_RCSID (Valuetype,
00018 AbstractBase,
00019 "$Id: AbstractBase.cpp 90662 2010-06-17 11:09:20Z vzykov $")
00020
00021 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00022
00023
00024
00025
00026 void
00027 CORBA::release (CORBA::AbstractBase_ptr obj)
00028 {
00029 if (obj)
00030 {
00031 obj->_remove_ref ();
00032 }
00033 }
00034
00035 CORBA::Boolean
00036 CORBA::is_nil (CORBA::AbstractBase_ptr obj)
00037 {
00038 return (obj == 0);
00039 }
00040
00041
00042
00043 CORBA::AbstractBase::AbstractBase (void)
00044 : is_objref_ (false)
00045 , concrete_stubobj_ (0)
00046 , is_collocated_ (false)
00047 , servant_ (0)
00048 , is_local_ (false)
00049 , equivalent_obj_ (0)
00050 {
00051 }
00052
00053 CORBA::AbstractBase::AbstractBase (const CORBA::AbstractBase &rhs)
00054 : is_objref_ (rhs.is_objref_)
00055 , concrete_stubobj_ (rhs.concrete_stubobj_)
00056 , is_collocated_ (rhs.is_collocated_)
00057 , servant_ (rhs.servant_)
00058 , is_local_ (rhs.is_local_)
00059 , equivalent_obj_ (0)
00060 {
00061 if (rhs.concrete_stubobj_ != 0)
00062 {
00063 rhs.concrete_stubobj_->_incr_refcnt ();
00064 }
00065
00066 if (!CORBA::is_nil (rhs.equivalent_obj_.in ()))
00067 {
00068 this->equivalent_obj_ =
00069 CORBA::Object::_duplicate (rhs.equivalent_obj_);
00070 }
00071 }
00072
00073 CORBA::AbstractBase::AbstractBase (TAO_Stub * protocol_proxy,
00074 CORBA::Boolean collocated,
00075 TAO_Abstract_ServantBase * servant)
00076 : is_objref_ (true)
00077 , concrete_stubobj_ (protocol_proxy)
00078 , is_collocated_ (collocated)
00079 , servant_ (servant)
00080 , is_local_ (protocol_proxy == 0 ? true : false)
00081 , equivalent_obj_ (0)
00082 {
00083 if (this->concrete_stubobj_ != 0)
00084 {
00085 TAO_Stub *stub = this->concrete_stubobj_;
00086
00087 stub->_incr_refcnt ();
00088
00089 this->equivalent_obj_ =
00090 stub->orb_core ()->create_object (stub);
00091 }
00092
00093 }
00094
00095 CORBA::AbstractBase::~AbstractBase (void)
00096 {
00097 if (this->concrete_stubobj_ != 0)
00098 {
00099 this->concrete_stubobj_->_decr_refcnt ();
00100 }
00101 }
00102
00103 CORBA::AbstractBase_ptr
00104 CORBA::AbstractBase::_duplicate (CORBA::AbstractBase_ptr obj)
00105 {
00106 if (obj)
00107 {
00108 obj->_add_ref ();
00109 }
00110
00111 if (!CORBA::is_nil (obj->equivalent_obj_.in ()))
00112 {
00113 obj->equivalent_obj_->_add_ref ();
00114 }
00115
00116 return obj;
00117 }
00118
00119
00120
00121
00122 void
00123 CORBA::AbstractBase::_add_ref (void)
00124 {
00125 }
00126
00127 void
00128 CORBA::AbstractBase::_remove_ref (void)
00129 {
00130 }
00131
00132 void
00133 CORBA::AbstractBase::_tao_any_destructor (void *x)
00134 {
00135 CORBA::AbstractBase_ptr tmp = static_cast<CORBA::AbstractBase_ptr> (x);
00136 ::CORBA::release (tmp);
00137 }
00138
00139 CORBA::Object_ptr
00140 CORBA::AbstractBase::_to_object (void)
00141 {
00142 if (!CORBA::is_nil (this->equivalent_obj_.in ()))
00143 return CORBA::Object::_duplicate (this->equivalent_obj_.in ());
00144
00145 if (this->concrete_stubobj_ == 0)
00146 {
00147 return CORBA::Object::_nil ();
00148 }
00149
00150 TAO_ORB_Core *orb_core = this->concrete_stubobj_->orb_core ();
00151 this->concrete_stubobj_->_incr_refcnt ();
00152
00153 return orb_core->create_object (this->concrete_stubobj_);
00154 }
00155
00156 CORBA::ValueBase *
00157 CORBA::AbstractBase::_to_value (void)
00158 {
00159 if (this->is_objref_)
00160 {
00161 return 0;
00162 }
00163
00164 CORBA::ValueBase *retval = this->_tao_to_value ();
00165
00166 if (retval != 0)
00167 {
00168 retval->_add_ref ();
00169 }
00170
00171 return retval;
00172 }
00173
00174 CORBA::Boolean
00175 CORBA::AbstractBase::_is_a (const char *type_id)
00176 {
00177 if (! CORBA::is_nil (this->equivalent_obj_.in ()))
00178 {
00179 return this->equivalent_obj_->_is_a (type_id);
00180 }
00181
00182 return (ACE_OS::strcmp (type_id, "IDL:omg.org/CORBA/AbstractBase:1.0") == 0);
00183 }
00184
00185 const char *
00186 CORBA::AbstractBase::_interface_repository_id (void) const
00187 {
00188 return "IDL:omg.org/CORBA/AbstractBase:1.0";
00189 }
00190
00191 const char *
00192 CORBA::AbstractBase::_tao_obv_repository_id (void) const
00193 {
00194 return "IDL:omg.org/CORBA/AbstractBase:1.0";
00195 }
00196
00197 CORBA::Boolean
00198 operator<< (TAO_OutputCDR &strm, const CORBA::AbstractBase_ptr abs)
00199 {
00200 CORBA::Boolean discriminator = true;
00201
00202
00203
00204
00205 if (CORBA::is_nil (abs))
00206 {
00207
00208 strm << ACE_OutputCDR::from_boolean (discriminator);
00209 strm.write_ulong (1);
00210 strm.write_char ('\0');
00211 strm.write_ulong (0);
00212 return (CORBA::Boolean) strm.good_bit ();
00213 }
00214
00215 if (abs->_is_objref ())
00216 {
00217 if (strm << ACE_OutputCDR::from_boolean (discriminator))
00218 {
00219 TAO_Stub *stubobj = abs->_stubobj ();
00220
00221 if (stubobj == 0)
00222 {
00223 return false;
00224 }
00225
00226
00227 if ((strm << stubobj->type_id.in ()) == 0)
00228 {
00229 return false;
00230 }
00231
00232 const TAO_MProfile& mprofile = stubobj->base_profiles ();
00233
00234 CORBA::ULong const profile_count = mprofile.profile_count ();
00235
00236 if ((strm << profile_count) == 0)
00237 {
00238 return false;
00239 }
00240
00241
00242
00243 for (CORBA::ULong i = 0; i < profile_count; ++i)
00244 {
00245 const TAO_Profile *p = mprofile.get_profile (i);
00246
00247 if (p->encode (strm) == 0)
00248 {
00249 return false;
00250 }
00251 }
00252
00253 return (CORBA::Boolean) strm.good_bit ();
00254 }
00255 }
00256 else
00257 {
00258 discriminator = false;
00259
00260 if (strm << ACE_OutputCDR::from_boolean (discriminator))
00261 {
00262 CORBA::Boolean retval = true;
00263
00264 CORBA::ULong value_tag = TAO_OBV_GIOP_Flags::Value_tag_base
00265 | TAO_OBV_GIOP_Flags::Type_info_single;
00266
00267 retval = strm.write_ulong (value_tag);
00268
00269 if (retval == 0)
00270 {
00271 return retval;
00272 }
00273
00274 retval = strm << abs->_tao_obv_repository_id ();
00275
00276 if (retval == 0)
00277 {
00278 return retval;
00279 }
00280
00281 return abs->_tao_marshal_v (strm);
00282 }
00283 }
00284
00285 return false;
00286 }
00287
00288 CORBA::Boolean
00289 operator>> (TAO_InputCDR &strm, CORBA::AbstractBase_ptr &abs)
00290 {
00291 abs = 0;
00292 CORBA::Boolean discriminator = false;
00293 ACE_InputCDR::to_boolean tb (discriminator);
00294 TAO_ORB_Core *orb_core = 0;
00295
00296 if (strm >> tb)
00297 {
00298 if (!discriminator)
00299 {
00300 CORBA::ULong value_tag;
00301
00302 if (!strm.read_ulong (value_tag))
00303 {
00304 return false;
00305 }
00306
00307 if (TAO_OBV_GIOP_Flags::is_null_ref (value_tag))
00308 {
00309
00310 return true;
00311 }
00312
00313 if (!TAO_OBV_GIOP_Flags::is_value_tag (value_tag))
00314 {
00315 ACE_DEBUG ((LM_DEBUG,
00316 ACE_TEXT ("operator>> CORBA::AbstractBase ")
00317 ACE_TEXT ("not value_tag\n")));
00318 return false;
00319 }
00320
00321 CORBA::String_var repo_id_stream;
00322
00323
00324 if (strm.read_string (repo_id_stream.inout ()) == 0)
00325 {
00326 return false;
00327 }
00328
00329 orb_core = strm.orb_core ();
00330
00331 if (orb_core == 0)
00332 {
00333 orb_core = TAO_ORB_Core_instance ();
00334
00335 if (TAO_debug_level > 0)
00336 {
00337 ACE_DEBUG ((LM_WARNING,
00338 "TAO (%P|%t) WARNING: extracting "
00339 "valuetype using default ORB_Core\n"));
00340 }
00341 }
00342
00343 CORBA::ValueFactory_var factory =
00344 orb_core->orb ()->lookup_value_factory (repo_id_stream.in ());
00345
00346
00347 if (factory.in() == 0)
00348 {
00349 ACE_ERROR ((LM_ERROR,
00350 ACE_TEXT ("(%N:%l): The following unknown type was received: `%s'."),
00351 repo_id_stream.in ()));
00352 return false;
00353 }
00354
00355 abs = factory->create_for_unmarshal_abstract ();
00356
00357 return (abs == 0 ? false : abs->_tao_unmarshal_v (strm));
00358 }
00359 else
00360 {
00361 CORBA::Object_var generic_objref;
00362
00363 if (strm >> generic_objref.inout ())
00364 {
00365 TAO_Stub *concrete_stubobj = generic_objref->_stubobj ();
00366
00367 CORBA::Boolean const stores_orb =
00368 ! CORBA::is_nil (concrete_stubobj->servant_orb_var ().in ());
00369
00370 if (stores_orb)
00371 {
00372 orb_core =
00373 concrete_stubobj->servant_orb_var ()->orb_core ();
00374 }
00375
00376 CORBA::Boolean const collocated =
00377 orb_core != 0
00378 && orb_core->optimize_collocation_objects ()
00379 && generic_objref->_is_collocated ();
00380
00381 ACE_NEW_RETURN (abs,
00382 CORBA::AbstractBase (
00383 concrete_stubobj,
00384 collocated,
00385 generic_objref->_servant ()),
00386 false);
00387 return true;
00388 }
00389 }
00390 }
00391
00392 return false;
00393 }
00394
00395 #if defined (GEN_OSTREAM_OPS)
00396
00397 std::ostream&
00398 operator<< (std::ostream &strm,
00399 CORBA::AbstractBase_ptr _tao_objref)
00400 {
00401 return CORBA::AbstractBase::_tao_stream (strm, _tao_objref);
00402 }
00403
00404 #endif
00405
00406 CORBA::Boolean
00407 CORBA::AbstractBase::_tao_marshal_v (TAO_OutputCDR &) const
00408 {
00409 return false;
00410 }
00411
00412 CORBA::Boolean
00413 CORBA::AbstractBase::_tao_unmarshal_v (TAO_InputCDR &)
00414 {
00415 return false;
00416 }
00417
00418 CORBA::Boolean
00419 CORBA::AbstractBase::_tao_match_formal_type (ptrdiff_t ) const
00420 {
00421 return false;
00422 }
00423
00424 #if defined (GEN_OSTREAM_OPS)
00425
00426 std::ostream &
00427 CORBA::AbstractBase::_tao_stream (std::ostream &strm,
00428 const CORBA::AbstractBase_ptr _tao_objref)
00429 {
00430 return _tao_objref->_tao_stream_v (strm);
00431 }
00432
00433 std::ostream &
00434 CORBA::AbstractBase::_tao_stream_v (std::ostream &strm) const
00435 {
00436 return strm << "\"IDL:omg.org/CORBA/AbstractBase:1.0\"";
00437 }
00438
00439 #endif
00440
00441 CORBA::ValueBase *
00442 CORBA::AbstractBase::_tao_to_value (void)
00443 {
00444 return 0;
00445 }
00446
00447 CORBA::Object_ptr
00448 CORBA::AbstractBase::equivalent_objref (void)
00449 {
00450 if (CORBA::is_nil (this->equivalent_obj_.in ()))
00451 {
00452 if (this->concrete_stubobj_ != 0)
00453 {
00454 TAO_ORB_Core *orb_core =
00455 this->concrete_stubobj_->orb_core ();
00456
00457 this->concrete_stubobj_->_incr_refcnt ();
00458
00459 this->equivalent_obj_ =
00460 orb_core->create_object (this->concrete_stubobj_);
00461 }
00462 }
00463
00464 return this->equivalent_obj_.in ();
00465 }
00466
00467
00468
00469 namespace TAO
00470 {
00471 namespace TypeCode
00472 {
00473 char const tc_object_id[] = "IDL:omg.org/CORBA/AbstractBase:1.0";
00474 char const tc_object_name[] = "AbstractBase";
00475 Objref<char const *,
00476 TAO::Null_RefCount_Policy>
00477 tc_AbstractBase (CORBA::tk_abstract_interface,
00478 tc_object_id,
00479 tc_object_name);
00480 }
00481 }
00482
00483 namespace CORBA
00484 {
00485 TypeCode_ptr const _tc_AbstractBase = &TAO::TypeCode::tc_AbstractBase;
00486 }
00487
00488 TAO_END_VERSIONED_NAMESPACE_DECL