Naming_Server.cpp

Go to the documentation of this file.
00001 // Naming_Server.cpp,v 1.14 2006/03/14 06:14:33 jtc Exp
00002 
00003 #include "orbsvcs/Naming/Naming_Server.h"
00004 #include "orbsvcs/Naming/Transient_Naming_Context.h"
00005 #include "orbsvcs/Naming/Persistent_Context_Index.h"
00006 #include "orbsvcs/Naming/Storable_Naming_Context.h"
00007 #include "orbsvcs/Naming/Storable_Naming_Context_Activator.h"
00008 #include "orbsvcs/Naming/Flat_File_Persistence.h"
00009 #include "orbsvcs/CosNamingC.h"
00010 
00011 #include "tao/debug.h"
00012 #include "tao/default_ports.h"
00013 #include "tao/ORB_Core.h"
00014 
00015 #include "tao/IORTable/IORTable.h"
00016 
00017 #if defined (TAO_HAS_CORBA_MESSAGING) && TAO_HAS_CORBA_MESSAGING != 0
00018 #include "tao/Messaging/Messaging.h"
00019 #endif
00020 
00021 #include "tao/AnyTypeCode/Any.h"
00022 
00023 #include "ace/Arg_Shifter.h"
00024 #include "ace/Auto_Ptr.h"
00025 #include "ace/Get_Opt.h"
00026 #include "ace/OS_NS_unistd.h"
00027 
00028 ACE_RCSID (Naming,
00029            Naming_Server,
00030            "Naming_Server.cpp,v 1.14 2006/03/14 06:14:33 jtc Exp")
00031 
00032 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00033 
00034 TAO_Naming_Server::TAO_Naming_Server (void)
00035   : naming_context_ (),
00036     ior_multicast_ (0),
00037     naming_service_ior_ (),
00038     context_index_ (0),
00039     ior_file_name_ (0),
00040     pid_file_name_ (0),
00041     context_size_ (ACE_DEFAULT_MAP_SIZE),
00042     persistence_file_name_ (0),
00043     base_address_ (TAO_NAMING_BASE_ADDR),
00044     multicast_ (0),
00045     use_storable_context_ (0),
00046     use_servant_activator_ (0),
00047     servant_activator_ (0),
00048     use_redundancy_(0),
00049     round_trip_timeout_ (0),
00050     use_round_trip_timeout_ (0)
00051 {
00052 }
00053 
00054 TAO_Naming_Server::TAO_Naming_Server (CORBA::ORB_ptr orb,
00055                                       PortableServer::POA_ptr poa,
00056                                       size_t context_size,
00057                                       ACE_Time_Value *timeout,
00058                                       int resolve_for_existing_naming_service,
00059                                       const ACE_TCHAR *persistence_location,
00060                                       void *base_addr,
00061                                       int enable_multicast,
00062                                       int use_storable_context,
00063                                       int round_trip_timeout,
00064                                       int use_round_trip_timeout)
00065   : naming_context_ (),
00066     ior_multicast_ (0),
00067     naming_service_ior_ (),
00068     context_index_ (0),
00069     ior_file_name_ (0),
00070     pid_file_name_ (0),
00071     context_size_ (ACE_DEFAULT_MAP_SIZE),
00072     persistence_file_name_ (0),
00073     base_address_ (TAO_NAMING_BASE_ADDR),
00074     multicast_ (0),
00075     use_storable_context_ (use_storable_context),
00076     use_servant_activator_ (0),
00077     servant_activator_ (0),
00078     use_redundancy_(0),
00079     round_trip_timeout_ (0),
00080     use_round_trip_timeout_ (0)
00081 {
00082   if (this->init (orb,
00083                   poa,
00084                   context_size,
00085                   timeout,
00086                   resolve_for_existing_naming_service,
00087                   persistence_location,
00088                   base_addr,
00089                   enable_multicast,
00090                   use_storable_context,
00091                   round_trip_timeout,
00092                   use_round_trip_timeout) == -1)
00093     ACE_ERROR ((LM_ERROR,
00094                 "(%P|%t) %p\n",
00095                 "TAO_Naming_Server::init"));
00096 }
00097 
00098 
00099 int
00100 TAO_Naming_Server::init (CORBA::ORB_ptr orb,
00101                          PortableServer::POA_ptr poa,
00102                          size_t context_size,
00103                          ACE_Time_Value *timeout,
00104                          int resolve_for_existing_naming_service,
00105                          const ACE_TCHAR *persistence_location,
00106                          void *base_addr,
00107                          int enable_multicast,
00108                          int use_storable_context,
00109                          int round_trip_timeout,
00110                          int use_round_trip_timeout)
00111 {
00112   if (resolve_for_existing_naming_service)
00113     {
00114       ACE_DECLARE_NEW_CORBA_ENV;
00115       ACE_TRY
00116         {
00117           // Try to find an existing Naming Service.
00118           CORBA::Object_var naming_obj =
00119             orb->resolve_initial_references ("NameService",
00120                                              timeout
00121                                              ACE_ENV_ARG_PARAMETER);
00122           ACE_TRY_CHECK;
00123 
00124           if (!CORBA::is_nil (naming_obj.in ()))
00125             {
00126               //
00127               // Success in finding a Naming Service.
00128               //
00129               if (TAO_debug_level > 0)
00130                 ACE_DEBUG ((LM_DEBUG,
00131                             "\nNameService found!\n"));
00132 
00133               this->naming_context_ =
00134                 CosNaming::NamingContext::_narrow (naming_obj.in ()
00135                                                    ACE_ENV_ARG_PARAMETER);
00136               ACE_TRY_CHECK;
00137 
00138               this->naming_service_ior_ =
00139                 orb->object_to_string (naming_obj.in ()
00140                                        ACE_ENV_ARG_PARAMETER);
00141               ACE_TRY_CHECK;
00142 
00143               return 0;
00144             }
00145         }
00146       ACE_CATCHANY
00147         {
00148           ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "TAO_Naming_Server::init");
00149         }
00150       ACE_ENDTRY;
00151       ACE_CHECK_RETURN (-1);
00152     }
00153 
00154   if (TAO_debug_level > 0)
00155     ACE_DEBUG ((LM_DEBUG,
00156                 "\nWe'll become a NameService\n"));
00157 
00158   // Become a Naming Service.
00159   return this->init_new_naming (orb,
00160                                 poa,
00161                                 persistence_location,
00162                                 base_addr,
00163                                 context_size,
00164                                 enable_multicast,
00165                                 use_storable_context,
00166                                 round_trip_timeout,
00167                                 use_round_trip_timeout);
00168 }
00169 
00170 int
00171 TAO_Naming_Server::parse_args (int argc,
00172                                ACE_TCHAR *argv[])
00173 {
00174   ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("b:do:p:s:f:m:u:r:z:"));
00175 
00176   int c;
00177   int size, result;
00178 
00179   // This is declared this way to avoid warnings from
00180   // some compilers that complain about mismatching types
00181   // in the sscanf.
00182 #if ACE_SIZEOF_VOID_P == ACE_SIZEOF_LONG_LONG
00183   ptrdiff_t address;
00184 #else
00185   long int address;
00186 #endif /* ACE_SIZEOF_VOID_P */
00187 
00188   // Make sure only one persistence option is specified
00189   int f_opt_used = 0;
00190   int u_opt_used = 0;
00191   int r_opt_used = 0;
00192 
00193   while ((c = get_opts ()) != -1)
00194     switch (c)
00195       {
00196       case 'd':  // debug flag.
00197         TAO_debug_level++;
00198         break;
00199       case 'o': // outputs the naming service ior to a file.
00200         this->ior_file_name_ = get_opts.opt_arg ();
00201         break;
00202       case 'p':
00203         this->pid_file_name_ = get_opts.opt_arg ();
00204         break;
00205       case 's':
00206         size = ACE_OS::atoi (get_opts.opt_arg ());
00207         if (size >= 0)
00208           this->context_size_ = size;
00209         break;
00210       case 'b':
00211         result = ::sscanf (ACE_TEXT_ALWAYS_CHAR (get_opts.opt_arg ()),
00212 #if ACE_SIZEOF_VOID_P == ACE_SIZEOF_LONG_LONG
00213                            ACE_INT64_FORMAT_SPECIFIER,
00214 #else
00215                            "%ld",
00216 #endif /* ACE_SIZEOF_VOID_P */
00217                            &address);
00218         if (result == 0 || result == EOF)
00219           ACE_ERROR_RETURN ((LM_ERROR,
00220                              "Unable to process <-b> option"),
00221                             -1);
00222         this->base_address_ = (void *) address;
00223         break;
00224       case 'm':
00225         this->multicast_ = ACE_OS::atoi(get_opts.opt_arg ());
00226         break;
00227       case 'f':
00228         this->persistence_file_name_ = get_opts.opt_arg ();
00229         f_opt_used = 1;
00230         break;
00231       case 'r':
00232         this->use_redundancy_ = 1;
00233         this->use_storable_context_ = 1;
00234         this->persistence_file_name_ = get_opts.opt_arg ();
00235         r_opt_used = 1;
00236         break;
00237       case 'u':
00238         this->use_storable_context_ = 1;
00239         this->persistence_file_name_ = get_opts.opt_arg ();
00240         u_opt_used = 1;
00241         break;
00242       case 'z':
00243         this->use_round_trip_timeout_ = 1;
00244         this->round_trip_timeout_ = (int)1.0e7 * ACE_OS::atoi (get_opts.opt_arg ());
00245         break;
00246       case '?':
00247       default:
00248         ACE_ERROR_RETURN ((LM_ERROR,
00249                            ACE_TEXT ("usage:  %s ")
00250                            ACE_TEXT ("-d ")
00251                            ACE_TEXT ("-o <ior_output_file> ")
00252                            ACE_TEXT ("-p <pid_file_name> ")
00253                            ACE_TEXT ("-s <context_size> ")
00254                            ACE_TEXT ("-b <base_address> ")
00255                            ACE_TEXT ("-m <1=enable multicast, 0=disable multicast(default) ")
00256                            ACE_TEXT ("-f <persistence_file_name> ")
00257                            ACE_TEXT ("-u <storable_persistence_directory (not used with -f)> ")
00258                            ACE_TEXT ("-r <redundant_persistence_directory> ")
00259                            ACE_TEXT ("-z <relative round trip timeout> ")
00260                            ACE_TEXT ("\n"),
00261                            argv [0]),
00262                           -1);
00263       }
00264 
00265   if (f_opt_used + u_opt_used + r_opt_used > 1)
00266     ACE_ERROR_RETURN ((LM_ERROR,
00267                        ACE_TEXT ("Only one persistence option can be passed")
00268                        ACE_TEXT ("\n")),
00269                       -1);
00270 
00271   return 0;
00272 }
00273 
00274 int
00275 TAO_Naming_Server::init_with_orb (int argc,
00276                                   ACE_TCHAR *argv [],
00277                                   CORBA::ORB_ptr orb)
00278 {
00279   int result;
00280 
00281   ACE_DECLARE_NEW_CORBA_ENV;
00282   ACE_TRY
00283     {
00284       // Duplicate the ORB
00285       this->orb_ = CORBA::ORB::_duplicate (orb);
00286 
00287       // Get the POA from the ORB.
00288       CORBA::Object_var poa_object =
00289         orb->resolve_initial_references ("RootPOA" ACE_ENV_ARG_PARAMETER);
00290       ACE_TRY_CHECK;
00291 
00292       if (CORBA::is_nil (poa_object.in ()))
00293         {
00294           ACE_ERROR_RETURN ((LM_ERROR,
00295                              ACE_TEXT(" (%P|%t) Unable to initialize the POA.\n")),
00296                             -1);
00297         }
00298 
00299       // Check the non-ORB arguments.  this needs to come before we
00300       // initialize my_naming_server so that we can pass on some of
00301       // the command-line arguments.
00302       result = this->parse_args (argc, argv);
00303 
00304       if (result < 0)
00305         return result;
00306 
00307       // Get the POA object.
00308       this->root_poa_ = PortableServer::POA::_narrow (poa_object.in ()
00309                                                       ACE_ENV_ARG_PARAMETER);
00310       ACE_TRY_CHECK;
00311 
00312       // Get the POA_Manager.
00313       PortableServer::POAManager_var poa_manager =
00314         this->root_poa_->the_POAManager (ACE_ENV_SINGLE_ARG_PARAMETER);
00315       ACE_TRY_CHECK;
00316 
00317       poa_manager->activate (ACE_ENV_SINGLE_ARG_PARAMETER);
00318       ACE_TRY_CHECK;
00319 
00320       int numPolicies = 2;
00321 #if (TAO_HAS_MINIMUM_POA == 0)
00322       if (this->use_storable_context_)
00323         {
00324           this->use_servant_activator_ = 1;
00325         }
00326 
00327       if (this->use_servant_activator_) {
00328         numPolicies += 2;
00329       }
00330 #endif /* TAO_HAS_MINIMUM_POA */
00331 
00332       CORBA::PolicyList policies (numPolicies);
00333       policies.length (numPolicies);
00334 
00335       // Id Assignment policy
00336       policies[0] =
00337         this->root_poa_->create_id_assignment_policy (PortableServer::USER_ID
00338                                                       ACE_ENV_ARG_PARAMETER);
00339       ACE_TRY_CHECK;
00340 
00341       // Lifespan policy
00342       policies[1] =
00343         this->root_poa_->create_lifespan_policy (PortableServer::PERSISTENT
00344                                                  ACE_ENV_ARG_PARAMETER);
00345       ACE_TRY_CHECK;
00346 
00347 #if (TAO_HAS_MINIMUM_POA == 0)
00348       if (this->use_servant_activator_)
00349         {
00350           // Request Processing Policy
00351           policies[2] =
00352             this->root_poa_->create_request_processing_policy (PortableServer::USE_SERVANT_MANAGER
00353                                                                ACE_ENV_ARG_PARAMETER);
00354           ACE_TRY_CHECK;
00355 
00356           // Servant Retention Policy
00357           policies[3] =
00358             this->root_poa_->create_servant_retention_policy (PortableServer::RETAIN
00359                                                               ACE_ENV_ARG_PARAMETER);
00360           ACE_TRY_CHECK;
00361         }
00362 #endif /* TAO_HAS_MINIMUM_POA */
00363 
00364       // We use a different POA, otherwise the user would have to change
00365       // the object key each time it invokes the server.
00366       this->ns_poa_ = this->root_poa_->create_POA ("NameService",
00367                                                    poa_manager.in (),
00368                                                    policies
00369                                                    ACE_ENV_ARG_PARAMETER);
00370       // Warning!  If create_POA fails, then the policies won't be
00371       // destroyed and there will be hell to pay in memory leaks!
00372       ACE_TRY_CHECK;
00373 
00374       // Creation of the new POAs over, so destroy the Policy_ptr's.
00375       for (CORBA::ULong i = 0;
00376            i < policies.length ();
00377            ++i)
00378         {
00379           CORBA::Policy_ptr policy = policies[i];
00380           policy->destroy (ACE_ENV_SINGLE_ARG_PARAMETER);
00381           ACE_TRY_CHECK;
00382         }
00383 
00384       result = this->init (orb,
00385                            this->ns_poa_.in (),
00386                            this->context_size_,
00387                            0,
00388                            0,
00389                            this->persistence_file_name_,
00390                            this->base_address_,
00391                            this->multicast_,
00392                            this->use_storable_context_,
00393                            this->round_trip_timeout_,
00394                            this->use_round_trip_timeout_);
00395       if (result == -1)
00396         return result;
00397     }
00398   ACE_CATCHANY
00399     {
00400       ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "TAO_Naming_Server::init_with_orb");
00401       return -1;
00402     }
00403   ACE_ENDTRY;
00404   ACE_CHECK_RETURN (-1);
00405 
00406   if (this->ior_file_name_ != 0)
00407     {
00408       FILE *iorf = ACE_OS::fopen (this->ior_file_name_, ACE_TEXT("w"));
00409       if (iorf == 0)
00410         {
00411           ACE_ERROR_RETURN ((LM_ERROR,
00412                              ACE_TEXT("Unable to open %s for writing:(%u) %p\n"),
00413                              this->ior_file_name_,
00414                              errno,
00415                              ACE_TEXT("TAO_Naming_Server::init_with_orb")),
00416                             -1);
00417         }
00418 
00419       CORBA::String_var str = this->naming_service_ior ();
00420 
00421       ACE_OS::fprintf (iorf, "%s\n", str.in ());
00422       ACE_OS::fclose (iorf);
00423     }
00424 
00425   if (this->pid_file_name_ != 0)
00426     {
00427       FILE *pidf = ACE_OS::fopen (this->pid_file_name_, ACE_TEXT("w"));
00428       if (pidf != 0)
00429         {
00430           ACE_OS::fprintf (pidf,
00431                            "%ld\n",
00432                            static_cast<long> (ACE_OS::getpid ()));
00433           ACE_OS::fclose (pidf);
00434         }
00435     }
00436 
00437   return 0;
00438 }
00439 
00440 int
00441 TAO_Naming_Server::init_new_naming (CORBA::ORB_ptr orb,
00442                                     PortableServer::POA_ptr poa,
00443                                     const ACE_TCHAR *persistence_location,
00444                                     void *base_addr,
00445                                     size_t context_size,
00446                                     int enable_multicast,
00447                                     int use_storable_context,
00448                                     int round_trip_timeout,
00449                                     int use_round_trip_timeout)
00450 {
00451   ACE_DECLARE_NEW_CORBA_ENV;
00452   ACE_TRY
00453     {
00454       if (use_storable_context)
00455         {
00456           // In lieu of a fully implemented service configurator version
00457           // of this Reader and Writer, let's just take something off the
00458           // command line for now.
00459           TAO_Naming_Service_Persistence_Factory* pf = 0;
00460           ACE_NEW_RETURN(pf, TAO_NS_FlatFileFactory, -1);
00461           auto_ptr<TAO_Naming_Service_Persistence_Factory> persFactory(pf);
00462           // This instance will either get deleted after recreate all or,
00463           // in the case of a servant activator's use, on destruction of the
00464           // activator.
00465 
00466           // Was a location specified?
00467           if (persistence_location == 0)
00468             {
00469               // No, assign the default location "NameService"
00470               persistence_location = ACE_TEXT("NameService");
00471             }
00472 
00473           // Now make sure this directory exists
00474           if (ACE_OS::access (persistence_location, W_OK|X_OK))
00475             {
00476               ACE_ERROR ((LM_ERROR, "Invalid persistence directory\n"));
00477               return -1;
00478             }
00479 
00480 #if (TAO_HAS_MINIMUM_POA == 0)
00481           if (this->use_servant_activator_)
00482             {
00483               ACE_NEW_THROW_EX (this->servant_activator_,
00484                                 TAO_Storable_Naming_Context_Activator (orb,
00485                                                                        persFactory.get(),
00486                                                                        persistence_location,
00487                                                                        context_size),
00488                                 CORBA::NO_MEMORY ());
00489               this->ns_poa_->set_servant_manager(this->servant_activator_);
00490             }
00491 #endif /* TAO_HAS_MINIMUM_POA */
00492 
00493           this->naming_context_ =
00494             TAO_Storable_Naming_Context::recreate_all (orb,
00495                                                        poa,
00496                                                        TAO_ROOT_NAMING_CONTEXT,
00497                                                        context_size,
00498                                                        0,
00499                                                        persFactory.get(),
00500                                                        persistence_location,
00501                                                        use_redundancy_
00502                                                        ACE_ENV_ARG_PARAMETER);
00503           ACE_TRY_CHECK;
00504 
00505           if (this->use_servant_activator_)
00506             persFactory.release();
00507         }
00508       else if (persistence_location != 0)
00509         //
00510         // Initialize Persistent Naming Service.
00511         //
00512         {
00513           // Allocate and initialize Persistent Context Index.
00514           ACE_NEW_RETURN (this->context_index_,
00515                           TAO_Persistent_Context_Index (orb, poa),
00516                           -1);
00517 
00518           if (this->context_index_->open (persistence_location,
00519                                           base_addr) == -1
00520               || this->context_index_->init (context_size) == -1)
00521             {
00522               if (TAO_debug_level >0)
00523                 ACE_DEBUG ((LM_DEBUG,
00524                             "TAO_Naming_Server: context_index initialization failed\n"));
00525               return -1;
00526             }
00527 
00528           // Set the root Naming Context reference.
00529           this->naming_context_ =
00530             this->context_index_->root_context ();
00531         }
00532       else
00533         {
00534           //
00535           // Initialize Transient Naming Service.
00536           //
00537           this->naming_context_ =
00538             TAO_Transient_Naming_Context::make_new_context (poa,
00539                                                             TAO_ROOT_NAMING_CONTEXT,
00540                                                             context_size
00541                                                             ACE_ENV_ARG_PARAMETER);
00542           ACE_TRY_CHECK;
00543 
00544         }
00545 
00546       // Register with the ORB's resolve_initial_references()
00547       // mechanism.  Primarily useful for dynamically loaded Name
00548       // Services.
00549       orb->register_initial_reference ("NameService",
00550                                        this->naming_context_.in ()
00551                                        ACE_ENV_ARG_PARAMETER);
00552       ACE_TRY_CHECK;
00553 
00554       // Set the ior of the root Naming Context.
00555       this->naming_service_ior_=
00556         orb->object_to_string (this->naming_context_.in ()
00557                                ACE_ENV_ARG_PARAMETER);
00558       ACE_TRY_CHECK;
00559 
00560       CORBA::Object_var table_object =
00561         orb->resolve_initial_references ("IORTable" ACE_ENV_ARG_PARAMETER);
00562       ACE_TRY_CHECK;
00563 
00564       IORTable::Table_var adapter =
00565         IORTable::Table::_narrow (table_object.in () ACE_ENV_ARG_PARAMETER);
00566       ACE_TRY_CHECK;
00567       if (CORBA::is_nil (adapter.in ()))
00568         {
00569           ACE_ERROR ((LM_ERROR, "Nil IORTable\n"));
00570         }
00571       else
00572         {
00573           CORBA::String_var ior =
00574             orb->object_to_string (this->naming_context_.in ()
00575                                    ACE_ENV_ARG_PARAMETER);
00576           ACE_TRY_CHECK;
00577           adapter->bind ("NameService", ior.in () ACE_ENV_ARG_PARAMETER);
00578           ACE_TRY_CHECK;
00579         }
00580 
00581 #if defined (ACE_HAS_IP_MULTICAST)
00582       if (enable_multicast)
00583         {
00584           // @@ Marina: is there anyway to implement this stuff
00585           // without using ORB_Core_instance()? For example can you
00586           // pass the ORB as an argument?
00587 
00588           //
00589           // Install ior multicast handler.
00590           //
00591           // Get reactor instance from TAO.
00592           ACE_Reactor *reactor = orb->orb_core()->reactor ();
00593 
00594           // See if the -ORBMulticastDiscoveryEndpoint option was specified.
00595           ACE_CString mde (orb->orb_core ()->orb_params ()->mcast_discovery_endpoint ());
00596 
00597           // First, see if the user has given us a multicast port number
00598           // on the command-line;
00599           u_short port =
00600             orb->orb_core ()->orb_params ()->service_port (TAO::MCAST_NAMESERVICE);
00601 
00602           if (port == 0)
00603             {
00604               // Check environment var. for multicast port.
00605               const char *port_number =
00606                 ACE_OS::getenv ("NameServicePort");
00607 
00608               if (port_number != 0)
00609                 port = static_cast<u_short> (ACE_OS::atoi (port_number));
00610             }
00611 
00612           // Port wasn't specified on the command-line or in environment -
00613           // use the default.
00614           if (port == 0)
00615             port = TAO_DEFAULT_NAME_SERVER_REQUEST_PORT;
00616 
00617           // Instantiate a handler which will handle client requests for
00618           // the root Naming Context ior, received on the multicast port.
00619           ACE_NEW_RETURN (this->ior_multicast_,
00620                           TAO_IOR_Multicast (),
00621                           -1);
00622 
00623           if (mde.length () != 0)
00624             {
00625               if (this->ior_multicast_->init (this->naming_service_ior_.in (),
00626                                               mde.c_str (),
00627                                               TAO_SERVICEID_NAMESERVICE) == -1)
00628                 return -1;
00629             }
00630           else
00631             {
00632               if (this->ior_multicast_->init (this->naming_service_ior_.in (),
00633                                               port,
00634                                               ACE_DEFAULT_MULTICAST_ADDR,
00635                                               TAO_SERVICEID_NAMESERVICE) == -1)
00636                 return -1;
00637             }
00638 
00639           // Register event handler for the ior multicast.
00640           if (reactor->register_handler (this->ior_multicast_,
00641                                          ACE_Event_Handler::READ_MASK) == -1)
00642             {
00643               if (TAO_debug_level > 0)
00644                 ACE_DEBUG ((LM_DEBUG,
00645                             "TAO_Naming_Server: cannot register Event handler\n"));
00646               return -1;
00647             }
00648 
00649           if (TAO_debug_level > 0)
00650             ACE_DEBUG ((LM_DEBUG,
00651                         "TAO_Naming_Server: The multicast server setup is done.\n"));
00652         }
00653 #else
00654   ACE_UNUSED_ARG (enable_multicast);
00655 #endif /* ACE_HAS_IP_MULTICAST */
00656 
00657 #if defined (TAO_HAS_CORBA_MESSAGING) && TAO_HAS_CORBA_MESSAGING != 0  
00658       if (use_round_trip_timeout == 1)
00659       {
00660         TimeBase::TimeT roundTripTimeoutVal = round_trip_timeout;
00661         CORBA::Any anyObjectVal;
00662         anyObjectVal <<= roundTripTimeoutVal;
00663         CORBA::PolicyList polList (1);
00664         polList.length (1);
00665         polList[0] = orb->create_policy (Messaging::RELATIVE_RT_TIMEOUT_POLICY_TYPE,
00666                                          anyObjectVal);
00667         ACE_TRY_CHECK;
00668 
00669         // set a timeout on the orb
00670         //
00671         CORBA::Object_var orbPolicyManagerObj =
00672           orb->resolve_initial_references ("ORBPolicyManager"
00673                                            ACE_ENV_ARG_PARAMETER);
00674         ACE_TRY_CHECK;
00675 
00676         CORBA::PolicyManager_var orbPolicyManager =
00677           CORBA::PolicyManager::_narrow (orbPolicyManagerObj.in ());
00678         ACE_TRY_CHECK;
00679         orbPolicyManager->set_policy_overrides (polList, CORBA::SET_OVERRIDE);
00680 
00681         polList[0]->destroy ();
00682         ACE_TRY_CHECK;
00683         polList[0] = CORBA::Policy::_nil ();
00684       }
00685 #else
00686   ACE_UNUSED_ARG (use_round_trip_timeout);
00687 #endif /* TAO_HAS_CORBA_MESSAGING */
00688     }
00689   ACE_CATCHANY
00690     {
00691       ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "TAO_Naming_Server::init_new_naming");
00692       return -1;
00693     }
00694   ACE_ENDTRY;
00695   ACE_CHECK_RETURN (-1);
00696 
00697   return 0;
00698 }
00699 
00700 int
00701 TAO_Naming_Server::fini (void)
00702 {
00703   // Destroy the child POA ns_poa that is created when initializing
00704   // the Naming Service
00705   ACE_TRY_NEW_ENV
00706     {
00707       this->ns_poa_->destroy (1, 1 ACE_ENV_ARG_PARAMETER);
00708       ACE_TRY_CHECK;
00709 
00710 
00711       CORBA::Object_var table_object =
00712         this->orb_->resolve_initial_references ("IORTable"
00713                                                 ACE_ENV_ARG_PARAMETER);
00714       ACE_TRY_CHECK;
00715 
00716       IORTable::Table_var adapter =
00717         IORTable::Table::_narrow (table_object.in () ACE_ENV_ARG_PARAMETER);
00718       ACE_TRY_CHECK;
00719       if (CORBA::is_nil (adapter.in ()))
00720         {
00721           ACE_ERROR ((LM_ERROR, "Nil IORTable\n"));
00722         }
00723       else
00724         {
00725           adapter->unbind ("NameService" ACE_ENV_ARG_PARAMETER);
00726           ACE_TRY_CHECK;
00727         }
00728     }
00729   ACE_CATCHANY
00730     {
00731       // Ignore
00732     }
00733   ACE_ENDTRY;
00734 
00735 
00736   if (this->ior_multicast_ != 0)
00737     {
00738       orb_->orb_core()->reactor ()->remove_handler (this->ior_multicast_,
00739          ACE_Event_Handler::READ_MASK | ACE_Event_Handler::DONT_CALL);
00740       delete this->ior_multicast_;
00741     }
00742 
00743   delete this->context_index_;
00744 
00745   return 0;
00746 }
00747 
00748 char*
00749 TAO_Naming_Server::naming_service_ior (void)
00750 {
00751   return CORBA::string_dup (this->naming_service_ior_.in ());
00752 }
00753 
00754 CosNaming::NamingContext_ptr
00755 TAO_Naming_Server::operator-> (void) const
00756 {
00757   return this->naming_context_.ptr ();
00758 }
00759 
00760 TAO_Naming_Server::~TAO_Naming_Server (void)
00761 {
00762 #if (TAO_HAS_MINIMUM_POA == 0)
00763   if (this->use_servant_activator_)
00764     delete this->servant_activator_;
00765 #endif /* TAO_HAS_MINIMUM_POA */
00766 }
00767 
00768 TAO_END_VERSIONED_NAMESPACE_DECL

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