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

Adapter.cpp

Go to the documentation of this file.
00001 #include "tao_pch.h"
00002 // $Id: Adapter.cpp,v 1.1.1.2.2.1 2003/03/14 16:05:12 chad Exp $
00003 
00004 
00005 #include "tao/Adapter.h"
00006 #include "tao/Object.h"
00007 #include "tao/Object_KeyC.h"
00008 #include "tao/ORB_Core.h"
00009 #include "tao/ORB.h"
00010 #include "ace/Dynamic_Service.h"
00011 #include "debug.h"
00012 
00013 #if !defined (__ACE_INLINE__)
00014 # include "Adapter.i"
00015 #endif /* __ACE_INLINE__ */
00016 
00017 ACE_RCSID (tao,
00018            Adapter,
00019            "$Id: Adapter.cpp,v 1.1.1.2.2.1 2003/03/14 16:05:12 chad Exp $")
00020 
00021 TAO_Adapter::~TAO_Adapter (void)
00022 {
00023 }
00024 
00025 // ****************************************************************
00026 
00027 TAO_Adapter_Registry::TAO_Adapter_Registry (TAO_ORB_Core *oc)
00028   : orb_core_ (oc)
00029   , adapters_capacity_ (16) // @@ Make it configurable
00030   , adapters_count_ (0)
00031   , adapters_ (0)
00032 {
00033   ACE_NEW (this->adapters_,
00034            TAO_Adapter*[this->adapters_capacity_]);
00035 }
00036 
00037 TAO_Adapter_Registry::~TAO_Adapter_Registry (void)
00038 {
00039   for (size_t i = 0; i != this->adapters_count_; ++i)
00040     {
00041       delete this->adapters_[i];
00042     }
00043 
00044   delete[] this->adapters_;
00045 }
00046 
00047 void
00048 TAO_Adapter_Registry::close (int wait_for_completion
00049                              ACE_ENV_ARG_DECL)
00050   ACE_THROW_SPEC (())
00051 {
00052   ACE_TRY
00053     {
00054       for (size_t i = 0; i != this->adapters_count_; ++i)
00055         {
00056           this->adapters_[i]->close (wait_for_completion
00057                                      ACE_ENV_ARG_PARAMETER);
00058           ACE_TRY_CHECK;
00059         }
00060     }
00061   ACE_CATCHANY
00062     {
00063       if (TAO_debug_level > 3)
00064         ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
00065                              "Exception in TAO_Adapter_Registry::close () \n");
00066       return;
00067     }
00068   ACE_ENDTRY;
00069 
00070   return;
00071 }
00072 
00073 void
00074 TAO_Adapter_Registry::check_close (int wait_for_completion
00075                                    ACE_ENV_ARG_DECL)
00076   ACE_THROW_SPEC (())
00077 {
00078   ACE_TRY
00079     {
00080       for (size_t i = 0; i != this->adapters_count_; ++i)
00081         {
00082           this->adapters_[i]->check_close (wait_for_completion
00083                                            ACE_ENV_ARG_PARAMETER);
00084           ACE_TRY_CHECK;
00085         }
00086     }
00087   ACE_CATCHALL
00088     {
00089       if (TAO_debug_level > 3)
00090         ACE_DEBUG ((LM_DEBUG,
00091                     ACE_LIB_TEXT ("(%P|%t) Exception in TAO_Adapter_Registry::check_close () \n")));
00092       return;
00093     }
00094   ACE_ENDTRY;
00095 
00096   return;
00097 }
00098 void
00099 TAO_Adapter_Registry::insert (TAO_Adapter *adapter
00100                               ACE_ENV_ARG_DECL)
00101 {
00102   if (this->adapters_capacity_ == this->adapters_count_)
00103     {
00104       this->adapters_capacity_ *= 2;
00105       TAO_Adapter **tmp;
00106       ACE_NEW_THROW_EX (tmp,
00107                         TAO_Adapter*[this->adapters_capacity_],
00108                         CORBA::NO_MEMORY ());
00109       ACE_CHECK;
00110 
00111       for (size_t i = 0; i != this->adapters_count_; ++i)
00112         tmp[i] = this->adapters_[i];
00113       delete[] this->adapters_;
00114       this->adapters_ = tmp;
00115     }
00116 
00117   int priority = adapter->priority ();
00118   for (size_t i = 0; i != this->adapters_count_; ++i)
00119     {
00120       if (this->adapters_[i]->priority () >= priority)
00121         {
00122           for (size_t j = this->adapters_count_ + 1;
00123                j > i;
00124                --j)
00125             {
00126               this->adapters_[j] = this->adapters_[j - 1];
00127             }
00128           this->adapters_[i] = adapter;
00129           this->adapters_count_++;
00130           return;
00131         }
00132     }
00133   this->adapters_[this->adapters_count_++] = adapter;
00134 }
00135 
00136 void
00137 TAO_Adapter_Registry::dispatch (TAO_ObjectKey &key,
00138                                 TAO_ServerRequest &request,
00139                                 CORBA::Object_out forward_to
00140                                 ACE_ENV_ARG_DECL)
00141   ACE_THROW_SPEC ((CORBA::SystemException))
00142 {
00143   for (size_t i = 0; i != this->adapters_count_; ++i)
00144     {
00145       int r = this->adapters_[i]->dispatch (key,
00146                                             request,
00147                                             forward_to
00148                                              ACE_ENV_ARG_PARAMETER);
00149       ACE_CHECK;
00150 
00151       if (r != TAO_Adapter::DS_MISMATCHED_KEY)
00152         {
00153           return;
00154         }
00155     }
00156 
00157   if (CORBA::is_nil (forward_to))
00158     {
00159       ACE_THROW (CORBA::OBJECT_NOT_EXIST ());
00160     }
00161 }
00162 
00163 CORBA::Object_ptr
00164 TAO_Adapter_Registry::create_collocated_object (TAO_Stub *stub,
00165                                                 const TAO_MProfile &mprofile)
00166 {
00167   for (size_t i = 0; i != this->adapters_count_; ++i)
00168     {
00169       CORBA::Object_ptr x =
00170         this->adapters_[i]->create_collocated_object (stub,
00171                                                       mprofile);
00172       if (x != 0)
00173         return x;
00174     }
00175   return 0;
00176 }
00177 
00178 TAO_Adapter *
00179 TAO_Adapter_Registry::find_adapter (const char *name) const
00180 {
00181   for (TAO_Adapter **i = this->adapters_;
00182        i != this->adapters_ + this->adapters_count_;
00183        ++i)
00184     {
00185       if (ACE_OS::strcmp ((*i)->name (), name) == 0)
00186         return *i;
00187     }
00188   return 0;
00189 
00190 }
00191 
00192 // ****************************************************************
00193 
00194 TAO_Adapter_Factory::~TAO_Adapter_Factory (void)
00195 {
00196 }
00197 
00198 #if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
00199 
00200 template class ACE_Dynamic_Service<TAO_Adapter_Factory>;
00201 
00202 #elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
00203 
00204 #pragma instantiate ACE_Dynamic_Service<TAO_Adapter_Factory>
00205 
00206 #endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */

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