Table_Adapter.cpp

Go to the documentation of this file.
00001 /**
00002  * @file Table_Adapter.cpp
00003  *
00004  * Table_Adapter.cpp,v 1.16 2006/04/19 09:38:06 jwillemsen Exp
00005  *
00006  * @author Carlos O'Ryan <coryan@uci.edu>
00007  *
00008  */
00009 
00010 #include "tao/IORTable/Table_Adapter.h"
00011 #include "tao/IORTable/IOR_Table_Impl.h"
00012 #include "tao/ORB_Core.h"
00013 #include "tao/Object.h"
00014 #include "tao/Stub.h"
00015 #include "tao/ORB.h"
00016 #include "tao/Profile.h"
00017 
00018 ACE_RCSID (IORTable,
00019            Table_Adapter,
00020            "Table_Adapter.cpp,v 1.16 2006/04/19 09:38:06 jwillemsen Exp")
00021 
00022 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00023 
00024 TAO_Table_Adapter::TAO_Table_Adapter (TAO_ORB_Core *orb_core)
00025   :  orb_core_ (orb_core)
00026   ,  root_ (0)
00027 {
00028 }
00029 
00030 TAO_Table_Adapter::~TAO_Table_Adapter (void)
00031 {
00032   ::CORBA::release (this->root_);
00033 }
00034 
00035 void
00036 TAO_Table_Adapter::open (ACE_ENV_SINGLE_ARG_DECL)
00037 {
00038   ACE_NEW_THROW_EX (this->root_,
00039                     TAO_IOR_Table_Impl (),
00040                     CORBA::NO_MEMORY ());
00041   ACE_CHECK;
00042 }
00043 
00044 void
00045 TAO_Table_Adapter::close (int  ACE_ENV_ARG_DECL_NOT_USED)
00046 {
00047   ::CORBA::release (this->root_);
00048   this->root_ = 0;
00049 }
00050 
00051 void
00052 TAO_Table_Adapter::check_close (int  ACE_ENV_ARG_DECL_NOT_USED)
00053 {
00054 }
00055 
00056 int
00057 TAO_Table_Adapter::priority (void) const
00058 {
00059   return 16; // @@
00060 }
00061 
00062 int
00063 TAO_Table_Adapter::dispatch (TAO::ObjectKey &key,
00064                              TAO_ServerRequest &,
00065                              CORBA::Object_out forward_to
00066                              ACE_ENV_ARG_DECL)
00067     ACE_THROW_SPEC ((CORBA::SystemException))
00068 {
00069   return this->find_object (key, forward_to) ? TAO_Adapter::DS_FORWARD
00070                                              : TAO_Adapter::DS_MISMATCHED_KEY;
00071 }
00072 
00073 const char *
00074 TAO_Table_Adapter::name (void) const
00075 {
00076   return "IORTable";
00077 }
00078 
00079 CORBA::Object_ptr
00080 TAO_Table_Adapter::root (void)
00081 {
00082   return CORBA::Object::_duplicate (this->root_);
00083 }
00084 
00085 CORBA::Object_ptr
00086 TAO_Table_Adapter::create_collocated_object (TAO_Stub *stub,
00087                                              const TAO_MProfile &)
00088 {
00089   CORBA::Object_ptr result = CORBA::Object::_nil ();
00090 
00091   if (! this->initialize_collocated_object (stub)) // 0 == success
00092     {
00093       // A reference was found in the table. The stub has been forwarded
00094       // to this. The collocation indicators are now correct on the stub
00095       // (although they may well now indicate that the stub is not in fact
00096       // collocated at all).
00097       ACE_NEW_RETURN (result,
00098                       CORBA::Object (stub,
00099                                      stub->is_collocated (),
00100                                      stub->collocated_servant ()),
00101                       CORBA::Object::_nil ());
00102 
00103     }
00104 
00105   return result;
00106 }
00107 
00108 CORBA::Long
00109 TAO_Table_Adapter::initialize_collocated_object (TAO_Stub * stub)
00110 {
00111   // Get the effective profile set.
00112   const TAO_MProfile &mp = stub->forward_profiles () ? *(stub->forward_profiles ())
00113                                                      : stub->base_profiles ();
00114   TAO_PHandle j = 0;
00115   // We only look at the key from the 0th profile but we only really care about
00116   // corbaloc's here where all profiles share a single object key
00117   TAO::ObjectKey_var key = mp.get_profile (j)->_key ();
00118 
00119   CORBA::Object_var forward_to = CORBA::Object::_nil ();
00120   CORBA::Boolean found = false;
00121 
00122   ACE_TRY_NEW_ENV
00123     {
00124       found = this->find_object (key, forward_to.out ());
00125     }
00126   ACE_CATCHANY
00127     {
00128     }
00129   ACE_ENDTRY;
00130 
00131   if (found)
00132     {
00133       // This call will set the appropriate collocation values
00134       // to correspond to the reference we found in the table.
00135       stub->add_forward_profiles (forward_to->_stubobj ()->base_profiles ());
00136       stub->next_profile ();
00137     }
00138 
00139   // 0 for success
00140   return ! found;
00141 }
00142 
00143 CORBA::Long
00144 TAO_Table_Adapter::find_object (TAO::ObjectKey &key,
00145                                 CORBA::Object_out forward_to
00146                                 ACE_ENV_ARG_DECL)
00147   ACE_THROW_SPEC ((CORBA::SystemException))
00148 {
00149   CORBA::String_var object_key;
00150   TAO::ObjectKey::encode_sequence_to_string (object_key.out (),
00151                                             key);
00152   ACE_TRY
00153     {
00154       CORBA::String_var ior =
00155         this->root_->find (object_key.in () ACE_ENV_ARG_PARAMETER);
00156       ACE_TRY_CHECK;
00157 
00158       forward_to =
00159         this->orb_core_->orb ()->string_to_object (ior.in ()
00160                                                    ACE_ENV_ARG_PARAMETER);
00161       ACE_TRY_CHECK;
00162     }
00163   ACE_CATCH (IORTable::NotFound, nf_ex)
00164     {
00165       return 0;
00166     }
00167   ACE_ENDTRY;
00168   return 1;
00169 }
00170 
00171 // ****************************************************************
00172 
00173 TAO_Table_Adapter_Factory::TAO_Table_Adapter_Factory (void)
00174 {
00175 }
00176 
00177 TAO_Adapter*
00178 TAO_Table_Adapter_Factory::create (TAO_ORB_Core *oc)
00179 {
00180   return new TAO_Table_Adapter (oc);
00181 }
00182 
00183 TAO_END_VERSIONED_NAMESPACE_DECL
00184 
00185 ACE_FACTORY_DEFINE (TAO_IORTable, TAO_Table_Adapter_Factory)
00186 ACE_STATIC_SVC_DEFINE (TAO_Table_Adapter_Factory,
00187                        ACE_TEXT ("TAO_IORTable"),
00188                        ACE_SVC_OBJ_T,
00189                        &ACE_SVC_NAME (TAO_Table_Adapter_Factory),
00190                        ACE_Service_Type::DELETE_THIS | ACE_Service_Type::DELETE_OBJ,
00191                        0)

Generated on Thu Nov 9 13:07:06 2006 for TAO_IORTable by doxygen 1.3.6