Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

AbstractBase.cpp

Go to the documentation of this file.
00001 #include "tao_pch.h"
00002 // $Id: AbstractBase.cpp,v 1.1.1.1.2.1 2003/03/14 16:05:11 chad Exp $
00003 
00004 // ============================================================================
00005 //
00006 // = LIBRARY
00007 //     TAO
00008 //
00009 // = FILENAME
00010 //     AbstractBase.cpp
00011 //
00012 // = AUTHOR
00013 //     Jeff Parsons  <parsons@cs.wustl.edu>
00014 //
00015 // ============================================================================
00016 
00017 #include "tao/AbstractBase.h"
00018 #include "tao/Any.h"
00019 #include "tao/Stub.h"
00020 #include "tao/Profile.h"
00021 #include "tao/ValueFactory.h"
00022 #include "tao/debug.h"
00023 
00024 #if !defined (__ACE_INLINE__)
00025 # include "tao/AbstractBase.inl"
00026 #endif /* ! __ACE_INLINE__ */
00027 
00028 ACE_RCSID (tao,
00029            AbstractBase,
00030            "$Id: AbstractBase.cpp,v 1.1.1.1.2.1 2003/03/14 16:05:11 chad Exp $")
00031 
00032 int CORBA_AbstractBase::_tao_class_id = 0;
00033 
00034 CORBA_AbstractBase::CORBA_AbstractBase (void)
00035   : is_objref_ (0),
00036     concrete_stubobj_ (0),
00037     is_collocated_ (0),
00038     servant_ (0),
00039     is_local_ (0)
00040 {
00041 }
00042 
00043 CORBA_AbstractBase::CORBA_AbstractBase (const CORBA_AbstractBase &rhs)
00044   : is_objref_ (rhs.is_objref_),
00045     concrete_stubobj_ (rhs.concrete_stubobj_),
00046     is_collocated_ (rhs.is_collocated_),
00047     servant_ (rhs.servant_),
00048     is_local_ (rhs.is_local_)
00049 {
00050   if (this->concrete_stubobj_ != 0)
00051     {
00052       (void) this->concrete_stubobj_->_incr_refcnt ();
00053     }
00054 }
00055 
00056 CORBA_AbstractBase::CORBA_AbstractBase (TAO_Stub * protocol_proxy,
00057                                         CORBA::Boolean collocated,
00058                                         TAO_Abstract_ServantBase * servant)
00059   : is_objref_ (1),
00060     concrete_stubobj_ (protocol_proxy),
00061     is_collocated_ (collocated),
00062     servant_ (servant),
00063     is_local_ (protocol_proxy == 0 ? 1 : 0)
00064 {
00065   if (this->concrete_stubobj_ != 0)
00066     {
00067       (void) this->concrete_stubobj_->_incr_refcnt ();
00068     }
00069 }
00070 
00071 CORBA_AbstractBase::~CORBA_AbstractBase (void)
00072 {
00073   if (this->concrete_stubobj_ != 0)
00074     {
00075       (void) this->concrete_stubobj_->_decr_refcnt ();
00076     }
00077 }
00078 
00079 void *
00080 CORBA_AbstractBase::_tao_QueryInterface (ptr_arith_t type)
00081 {
00082   void *retv = 0;
00083 
00084   if (type == ACE_reinterpret_cast (
00085               ptr_arith_t,
00086               &CORBA_AbstractBase::_tao_class_id)
00087             )
00088     {
00089       retv = ACE_reinterpret_cast (void*, this);
00090     }
00091 
00092   if (retv != 0)
00093     {
00094       this->_add_ref ();
00095     }
00096 
00097   return retv;
00098 }
00099 
00100 // These are non-pure virtual no-ops so we can instantiate the
00101 // class in the CDR extraction operator. The actual management
00102 // of the refcount will always be done in the derived class.
00103 void
00104 CORBA_AbstractBase::_add_ref (void)
00105 {
00106 }
00107 
00108 void
00109 CORBA_AbstractBase::_remove_ref (void)
00110 {
00111 }
00112 
00113 CORBA::Object_ptr
00114 CORBA_AbstractBase::_to_object (void)
00115 {
00116   if (this->concrete_stubobj_ == 0)
00117     {
00118       return CORBA::Object::_nil ();
00119     }
00120 
00121   TAO_ORB_Core *orb_core = this->concrete_stubobj_->orb_core ();
00122   this->concrete_stubobj_->_incr_refcnt ();
00123 
00124   return orb_core->create_object (this->concrete_stubobj_);
00125 }
00126 
00127 CORBA::ValueBase *
00128 CORBA_AbstractBase::_to_value (void)
00129 {
00130   if (this->is_objref_)
00131     {
00132       return 0;
00133     }
00134 
00135   CORBA::ValueBase *retval = this->_tao_to_value ();
00136 
00137   if (retval == 0)
00138     {
00139       return retval;
00140     }
00141 
00142   retval->_add_ref ();
00143   return retval;
00144 }
00145 
00146 CORBA::Boolean
00147 operator<< (TAO_OutputCDR &strm, const CORBA_AbstractBase_ptr abs)
00148 {
00149   CORBA::Boolean discriminator = 0;
00150 
00151   if (abs->_is_objref ())
00152     {
00153       discriminator = 1;
00154 
00155       if (strm << ACE_OutputCDR::from_boolean (discriminator))
00156         {
00157           TAO_Stub *stubobj = abs->_stubobj ();
00158 
00159           if (stubobj == 0)
00160             {
00161               return 0;
00162             }
00163 
00164           // STRING, a type ID hint
00165           if ((strm << stubobj->type_id.in ()) == 0)
00166             {
00167               return 0;
00168             }
00169 
00170           const TAO_MProfile& mprofile = stubobj->base_profiles ();
00171 
00172           CORBA::ULong profile_count = mprofile.profile_count ();
00173 
00174           if ((strm << profile_count) == 0)
00175             {
00176               return 0;
00177             }
00178 
00179           // @@ The MProfile should be locked during this iteration, is there
00180           // anyway to achieve that?
00181           for (CORBA::ULong i = 0; i < profile_count; ++i)
00182             {
00183               const TAO_Profile *p = mprofile.get_profile (i);
00184 
00185               if (p->encode (strm) == 0)
00186                 {
00187                   return 0;
00188                 }
00189             }
00190 
00191           return (CORBA::Boolean) strm.good_bit ();
00192         }
00193     }
00194   else
00195     {
00196       discriminator = 0;
00197 
00198       if (strm << ACE_OutputCDR::from_boolean (discriminator))
00199         {
00200           CORBA::Boolean retval = 1;
00201 
00202           CORBA::ULong value_tag = TAO_OBV_GIOP_Flags::Value_tag_base
00203                                    | TAO_OBV_GIOP_Flags::Type_info_single;
00204 
00205           retval = strm.write_ulong (value_tag);
00206 
00207           if (retval == 0)
00208             {
00209               return retval;
00210             }
00211 
00212           retval = strm << abs->_tao_obv_repository_id ();
00213 
00214           if (retval == 0)
00215             {
00216               return retval;
00217             }
00218 
00219           return abs->_tao_marshal_v (strm);
00220         }
00221     }
00222 
00223   return 0;
00224 }
00225 
00226 CORBA::Boolean
00227 operator>> (TAO_InputCDR &strm, CORBA_AbstractBase_ptr &abs)
00228 {
00229   abs = 0;
00230   CORBA::Boolean discriminator = 0;
00231   ACE_InputCDR::to_boolean tb (discriminator);
00232   TAO_ORB_Core *orb_core = 0;
00233 
00234   if (strm >> tb)
00235     {
00236       if (discriminator == 0)
00237         {
00238           CORBA::ULong value_tag;
00239 
00240           if (!strm.read_ulong (value_tag))
00241             {
00242               return 0;
00243             }
00244 
00245           if (TAO_OBV_GIOP_Flags::is_null_ref (value_tag))
00246             {
00247               // Ok, null reference unmarshaled.
00248               return 1;
00249             }
00250 
00251           if (!TAO_OBV_GIOP_Flags::is_value_tag (value_tag))
00252             {
00253               ACE_DEBUG ((LM_DEBUG,
00254                           ACE_TEXT ("operator>> CORBA::AbstractBase ")
00255                           ACE_TEXT ("not value_tag\n")));
00256               return 0;
00257             }
00258 
00259           CORBA::String_var repo_id_stream;
00260 
00261           // It would be more efficient not to copy the string)
00262           if (strm.read_string (repo_id_stream.inout ()) == 0)
00263             {
00264               return 0;
00265             }
00266 
00267           orb_core = strm.orb_core ();
00268 
00269           if (orb_core == 0)
00270             {
00271               orb_core = TAO_ORB_Core_instance ();
00272 
00273               if (TAO_debug_level > 0)
00274                 {
00275                   ACE_DEBUG ((LM_WARNING,
00276                               "TAO (%P|%t) WARNING: extracting valuetype using "
00277                               "default ORB_Core\n"));
00278                 }
00279             }
00280 
00281           CORBA::ValueFactory_var factory =
00282             orb_core->orb ()->lookup_value_factory (repo_id_stream.in ());
00283 
00284           // We should throw an exception, if there were an appropriate one.
00285           if (factory.in() == 0)
00286             {
00287               ACE_DEBUG ((LM_ERROR,
00288                           ACE_TEXT ("(%N:%l) OBV factory is null !!!\n")));
00289               return 0;
00290             }
00291 
00292           abs = factory->create_for_unmarshal_abstract ();
00293 
00294           return abs->_tao_unmarshal_v (strm);
00295         }
00296       else
00297         {
00298           CORBA::Object_var generic_objref;
00299 
00300           if (strm >> generic_objref.inout ())
00301             {
00302               TAO_Stub *concrete_stubobj = generic_objref->_stubobj ();
00303 
00304               CORBA::Boolean stores_orb =
00305                 ! CORBA::is_nil (concrete_stubobj->servant_orb_var ().ptr ());
00306 
00307               if (stores_orb)
00308                 {
00309                   orb_core =
00310                     concrete_stubobj->servant_orb_var ()->orb_core ();
00311                 }
00312 
00313               CORBA::Boolean collocated =
00314                 orb_core != 0
00315                 && orb_core->optimize_collocation_objects ()
00316                 && generic_objref->_is_collocated ();
00317 
00318               ACE_NEW_RETURN (abs,
00319                               CORBA_AbstractBase (concrete_stubobj,
00320                                                   collocated,
00321                                                   generic_objref->_servant ()),
00322                               0);
00323               return 1;
00324             }
00325         }
00326     }
00327 
00328   return 0;
00329 }
00330 
00331 CORBA::Boolean
00332 CORBA_AbstractBase::_tao_marshal_v (TAO_OutputCDR &)
00333 {
00334   return 0;
00335 }
00336 
00337 CORBA::Boolean
00338 CORBA_AbstractBase::_tao_unmarshal_v (TAO_InputCDR &)
00339 {
00340   return 0;
00341 }
00342 
00343 CORBA::ValueBase *
00344 CORBA_AbstractBase::_tao_to_value (void)
00345 {
00346   return 0;
00347 }
00348 

Generated on Mon Jun 16 13:47:56 2003 for TAO by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002