PICurrent_Impl.cpp

Go to the documentation of this file.
00001 #include "tao/PI/PICurrent_Impl.h"
00002 
00003 #if TAO_HAS_INTERCEPTORS == 1
00004 
00005 ACE_RCSID (tao,
00006            PICurrent,
00007            "PICurrent_Impl.cpp,v 1.10 2006/06/26 09:24:20 sma Exp")
00008 
00009 
00010 #if !defined (__ACE_INLINE__)
00011 # include "tao/PI/PICurrent_Impl.inl"
00012 #endif /* __ACE_INLINE__ */
00013 
00014 #include "tao/TAO_Server_Request.h"
00015 #include "tao/SystemException.h"
00016 #include "ace/Log_Msg.h"
00017 #include "tao/debug.h"
00018 
00019 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00020 
00021 CORBA::Any *
00022 TAO::PICurrent_Impl::get_slot (PortableInterceptor::SlotId identifier
00023                                ACE_ENV_ARG_DECL)
00024   ACE_THROW_SPEC ((CORBA::SystemException,
00025                    PortableInterceptor::InvalidSlot))
00026 {
00027   // No need to check validity of SlotId.  It is validated before this
00028   // method is invoked.
00029 
00030   // The active slot table should never be a lazy copy of itself!
00031   if ( (0 != this->lazy_copy_)
00032       && (&this->lazy_copy_->current_slot_table () == &this->slot_table_))
00033   {
00034     if (TAO_debug_level > 0)
00035       ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("TAO (%P|%t) Lazy copy of self detected at %N,%l\n")));
00036     ACE_THROW (CORBA::INTERNAL ());
00037   }
00038 
00039   // Get the slot table that is currently active
00040   PICurrent_Impl::Table & table = this->current_slot_table ();
00041   CORBA::Any * any = 0;
00042 
00043   if (identifier < table.size ())
00044     {
00045       ACE_NEW_THROW_EX (any,
00046                         CORBA::Any (table[identifier]), // Make a copy.
00047                         CORBA::NO_MEMORY (
00048                           CORBA::SystemException::_tao_minor_code (
00049                             0,
00050                             ENOMEM),
00051                           CORBA::COMPLETED_NO));
00052       ACE_CHECK_RETURN (any);
00053     }
00054   else
00055     {
00056       // In accordance with the Portable Interceptor specification,
00057       // return an Any with a TCKind of tk_null.  A default
00058       // constructed Any has that TCKind.
00059       ACE_NEW_THROW_EX (any,
00060                         CORBA::Any,
00061                         CORBA::NO_MEMORY (
00062                           CORBA::SystemException::_tao_minor_code (
00063                             0,
00064                             ENOMEM),
00065                           CORBA::COMPLETED_NO));
00066       ACE_CHECK_RETURN (any);
00067     }
00068 
00069   return any;
00070 }
00071 
00072 void
00073 TAO::PICurrent_Impl::set_slot (PortableInterceptor::SlotId identifier,
00074                                const CORBA::Any & data
00075                                ACE_ENV_ARG_DECL)
00076   ACE_THROW_SPEC ((CORBA::SystemException,
00077                    PortableInterceptor::InvalidSlot))
00078 {
00079   // No need to check validity of SlotId.  It is validated before this
00080   // method is invoked.
00081 
00082   // Break any existing ties that another PICurrent has with our table
00083   // since our table is changing.
00084   if (0 != this->impending_change_callback_)
00085     this->impending_change_callback_->convert_from_lazy_to_real_copy ();
00086 
00087   // Ensure that we have a real physical copy of the table before
00088   // making any changes to it.
00089   this->convert_from_lazy_to_real_copy ();
00090 
00091   // If the slot table array isn't large enough, then increase its
00092   // size.  We're guaranteed not to exceed the number of allocated
00093   // slots for the reason stated above.
00094   if (identifier >= this->slot_table_.size ()
00095       && this->slot_table_.size (identifier + 1) != 0)
00096     ACE_THROW (CORBA::INTERNAL ());
00097 
00098   this->slot_table_[identifier] = CORBA::Any (data);
00099 }
00100 
00101 void
00102 TAO::PICurrent_Impl::take_lazy_copy (
00103   TAO::PICurrent_Impl * p)
00104 {
00105   // Check that we are being told to actually change which table we are
00106   // copying from. (If it is the same as before OR it would ultimately be
00107   // the same table, we are already correctly setup and we do nothing.)
00108   if ( (p != this->lazy_copy_)
00109       && ((0 == p) || (&p->current_slot_table () != &this->current_slot_table ()))
00110       )
00111     {
00112       // Break any existing ties that another PICurrent has with our table
00113       // since our table is changing.
00114       if (0 != this->impending_change_callback_)
00115         this->impending_change_callback_->convert_from_lazy_to_real_copy ();
00116 
00117       // If we have previously logically copied another table, ensure it is
00118       // told that we are no longer interested in it so that it will not
00119       // call our conver_from_lazy_to_real_copy() when it changes/destructs.
00120       if (0 != this->lazy_copy_)
00121         this->lazy_copy_->set_callback_for_impending_change (0);
00122 
00123       // Are we being asked to copy ourself (or nothing)
00124       if ((0 == p) || (this == p))
00125         {
00126           this->lazy_copy_ = 0; // Use our own physical slot_table_
00127         }
00128       else
00129         {
00130           this->lazy_copy_ = p;
00131 
00132           // Must tell the newly copied PICurrent_Impl that we want to
00133           // be told when/if it is going to be changed or destroyed.
00134           this->lazy_copy_->set_callback_for_impending_change (this);
00135         }
00136     }
00137 }
00138 
00139 TAO_END_VERSIONED_NAMESPACE_DECL
00140 
00141 #endif  /* TAO_HAS_INTERCEPTORS == 1 */

Generated on Thu Nov 9 12:51:39 2006 for TAO_PI by doxygen 1.3.6