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

Generated on Sun Jan 27 13:29:59 2008 for TAO_PI by doxygen 1.3.6