Storable_Naming_Context_Activator.cpp

Go to the documentation of this file.
00001 // Storable_Naming_Context_Activator.cpp,v 1.4 2006/03/14 06:14:34 jtc Exp
00002 // ============================================================================
00003 //
00004 // = LIBRARY
00005 //    cos
00006 //
00007 // = FILENAME
00008 //   Storable_Naming_Context_Activator.h
00009 //
00010 // = AUTHOR
00011 //    Byron Harris <harris_b@ociweb.com>
00012 //
00013 // ============================================================================
00014 
00015 #include "orbsvcs/Naming/Storable_Naming_Context_Activator.h"
00016 
00017 #if (TAO_HAS_MINIMUM_POA == 0)
00018 #include "orbsvcs/Naming/Naming_Context_Interface.h"
00019 #include "orbsvcs/Naming/Storable_Naming_Context.h"
00020 #include "orbsvcs/Naming/Storable.h"
00021 #include "ace/Auto_Ptr.h"
00022 
00023 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00024 
00025 TAO_Storable_Naming_Context_Activator::TAO_Storable_Naming_Context_Activator (
00026   CORBA::ORB_ptr orb,
00027   TAO_Naming_Service_Persistence_Factory *factory,
00028   const ACE_TCHAR *persistence_directory,
00029   size_t context_size)
00030   : orb_(orb),
00031     factory_(factory),
00032     persistence_directory_(persistence_directory),
00033     context_size_(context_size)
00034 {
00035 }
00036 
00037 TAO_Storable_Naming_Context_Activator::~TAO_Storable_Naming_Context_Activator ()
00038 {
00039   delete factory_;
00040 }
00041 
00042 PortableServer::Servant
00043 TAO_Storable_Naming_Context_Activator::incarnate (
00044     const PortableServer::ObjectId &oid,
00045     PortableServer::POA_ptr poa
00046     ACE_ENV_ARG_DECL)
00047   ACE_THROW_SPEC ((CORBA::SystemException,
00048                    PortableServer::ForwardRequest))
00049 {
00050 
00051   // Make sure complete initialization has been done
00052   ACE_ASSERT (factory_ != 0);
00053 
00054   CORBA::String_var poa_id = PortableServer::ObjectId_to_string (oid);
00055 
00056   // The approached used is to simply verify that there is a
00057   // persistence element that exists that corresponds to the
00058   // poa_id. If so, an empty context is created. Later, when the
00059   // context is accessed it will be determined that the contents of
00060   // the persistence elment needs to be read in.
00061 
00062   // Does this already exist on disk?
00063   ACE_TString file_name(persistence_directory_);
00064   file_name += ACE_TEXT("/");
00065   file_name += ACE_TEXT_CHAR_TO_TCHAR(poa_id.in());
00066   TAO_Storable_Base * fl = factory_->create_stream(ACE_TEXT_ALWAYS_CHAR(file_name.c_str()), ACE_TEXT("rw"));
00067   if (!fl->exists()) {
00068     ACE_THROW_RETURN (CORBA::OBJECT_NOT_EXIST (),
00069                       0);
00070   }
00071 
00072   // Store the stub we will return here.
00073   CosNaming::NamingContext_var result (CosNaming::NamingContext::_nil());
00074 
00075   // Put together a servant for the new Naming Context.
00076 
00077   TAO_Storable_Naming_Context *context_impl = 0;
00078   ACE_NEW_THROW_EX (context_impl,
00079                     TAO_Storable_Naming_Context (orb_,
00080                                                  poa,
00081                                                  poa_id.in (),
00082                                                  factory_,
00083                                                  persistence_directory_,
00084                                                  context_size_),
00085                                                  CORBA::NO_MEMORY ());
00086   ACE_CHECK_RETURN (0);
00087 
00088   // Put <context_impl> into the auto pointer temporarily, in case next
00089   // allocation fails.
00090   ACE_Auto_Basic_Ptr<TAO_Storable_Naming_Context> temp (context_impl);
00091 
00092   TAO_Naming_Context *context = 0;
00093   ACE_NEW_THROW_EX (context,
00094                     TAO_Naming_Context (context_impl),
00095                     CORBA::NO_MEMORY ());
00096   ACE_CHECK_RETURN (0);
00097 
00098   // Let <implementation> know about it's <interface>.
00099   context_impl->interface (context);
00100 
00101   // Release auto pointer, and start using reference counting to
00102   // control our servant.
00103   temp.release ();
00104 
00105   return context;
00106 }
00107 
00108 void
00109 TAO_Storable_Naming_Context_Activator::etherealize (
00110     const PortableServer::ObjectId &/*oid*/,
00111     PortableServer::POA_ptr /*adapter*/,
00112     PortableServer::Servant servant,
00113     CORBA::Boolean /*cleanup_in_progress*/,
00114     CORBA::Boolean remaining_activations
00115     ACE_ENV_ARG_DECL_NOT_USED)
00116   ACE_THROW_SPEC ((CORBA::SystemException))
00117 {
00118   if (!remaining_activations) {
00119     delete servant;
00120   }
00121 }
00122 
00123 TAO_END_VERSIONED_NAMESPACE_DECL
00124 
00125 #endif /* TAO_HAS_MINIMUM_POA */

Generated on Thu Nov 9 13:57:03 2006 for TAO_CosNaming by doxygen 1.3.6