Naming_Server.cpp

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

Generated on Tue Feb 2 17:49:05 2010 for TAO_CosNaming by  doxygen 1.4.7