PICurrent.cpp

Go to the documentation of this file.
00001 #include "tao/PI/PICurrent.h"
00002 
00003 #if TAO_HAS_INTERCEPTORS == 1
00004 
00005 ACE_RCSID (tao,
00006            PICurrent,
00007            "$Id: PICurrent.cpp 77151 2007-02-15 13:24:41Z johnnyw $")
00008 
00009 #if !defined (__ACE_INLINE__)
00010 # include "tao/PI/PICurrent.inl"
00011 #endif /* __ACE_INLINE__ */
00012 
00013 #include "tao/PI/PICurrent_Impl.h"
00014 
00015 #include "tao/ORB_Core.h"
00016 #include "tao/ORB_Core_TSS_Resources.h"
00017 #include "tao/TAO_Server_Request.h"
00018 #include "ace/CORBA_macros.h"
00019 
00020 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00021 
00022 TAO::PICurrent::PICurrent (TAO_ORB_Core &orb_core)
00023   : orb_core_ (orb_core),
00024     tss_slot_ (0), // Call initialize() before use.
00025     slot_count_ (0) // Call initialize() before use.
00026 {
00027 }
00028 
00029 TAO::PICurrent::~PICurrent (void)
00030 {
00031 }
00032 
00033 CORBA::Any *
00034 TAO::PICurrent::get_slot (PortableInterceptor::SlotId identifier)
00035 {
00036   this->check_validity (identifier);
00037 
00038   return this->tsc ()->get_slot (identifier);
00039 }
00040 
00041 void
00042 TAO::PICurrent::set_slot (PortableInterceptor::SlotId identifier,
00043                          const CORBA::Any &data)
00044 {
00045   this->check_validity (identifier);
00046 
00047   this->tsc ()->set_slot (identifier, data);
00048 }
00049 
00050 namespace
00051 {
00052   extern "C" void CleanUpPICurrent(void *object, void *)
00053   {
00054     delete static_cast<TAO::PICurrent_Impl *> (object);
00055   }
00056 }
00057 
00058 TAO::PICurrent_Impl *
00059 TAO::PICurrent::tsc (void)
00060 {
00061   TAO::PICurrent_Impl *impl =
00062     static_cast<TAO::PICurrent_Impl *> (
00063       this->orb_core_.get_tss_resource (this->tss_slot_));
00064 
00065   // If this TSS has not yet been set-up, give it it's own PICurrent_Impl.
00066   if (0 == impl)
00067   {
00068     ACE_NEW_THROW_EX (impl,
00069                       TAO::PICurrent_Impl,
00070                       CORBA::NO_MEMORY (
00071                         CORBA::SystemException::_tao_minor_code (
00072                           TAO::VMCID,
00073                           ENOMEM),
00074                         CORBA::COMPLETED_NO));
00075 
00076     this->orb_core_.set_tss_resource (this->tss_slot_, impl);
00077   }
00078 
00079   return impl;
00080 }
00081 
00082 void
00083 TAO::PICurrent::check_validity (const PortableInterceptor::SlotId &identifier)
00084 {
00085   // If the slot_count is zero, no initialization has been done (if there are
00086   // no slots, then the PICurrent_impl object is not created as there is no
00087   // data to copy).
00088   if (0 == this->slot_count_)
00089     throw ::CORBA::BAD_INV_ORDER (CORBA::OMGVMCID | 14, CORBA::COMPLETED_NO);
00090 
00091   // No need to acquire a lock for this check.  At this point, these
00092   // attributes are read only.
00093   if (identifier >= this->slot_count_)
00094     throw PortableInterceptor::InvalidSlot ();
00095 }
00096 
00097 CORBA::ORB_ptr
00098 TAO::PICurrent::_get_orb (void)
00099 {
00100   return CORBA::ORB::_duplicate (this->orb_core_.orb ());
00101 }
00102 
00103 void
00104 TAO::PICurrent::initialize (PortableInterceptor::SlotId sc)
00105 {
00106   // Only allow a single initialization; sc is the number of
00107   // allocated PICurrent data slots the end user wants. If 0
00108   // PICurrent is not used, as no data is to be stored.
00109   if ((0 == this->slot_count_) && (0 != sc))
00110   {
00111     // NOTE: This function not only adds the cleanup function
00112     // but ALSO allocates the TSS slot PICurrent is to use.
00113     // It MUST be called BEFORE we attempt to get/set any
00114     // PICurrent slot data.
00115     if (0 != orb_core_.add_tss_cleanup_func (CleanUpPICurrent, this->tss_slot_))
00116       throw ::CORBA::NO_MEMORY (
00117                    CORBA::SystemException::_tao_minor_code (
00118                      TAO::VMCID,
00119                      ENOMEM),
00120                    CORBA::COMPLETED_NO);
00121 
00122     this->slot_count_ = sc;
00123   }
00124 }
00125 
00126 TAO_END_VERSIONED_NAMESPACE_DECL
00127 
00128 #endif  /* TAO_HAS_INTERCEPTORS == 1 */

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