TAO_Internal.cpp

Go to the documentation of this file.
00001 // $Id: TAO_Internal.cpp 79495 2007-08-24 15:22:50Z mesnier_p $
00002 
00003 #include "tao/TAO_Internal.h"
00004 #include "tao/TAO_Singleton.h"
00005 #include "tao/default_server.h"
00006 #include "tao/default_client.h"
00007 #include "tao/default_resource.h"
00008 #include "tao/IIOP_Factory.h"
00009 #include "tao/MCAST_Parser.h"
00010 #include "tao/CORBANAME_Parser.h"
00011 #include "tao/CORBALOC_Parser.h"
00012 #include "tao/FILE_Parser.h"
00013 #include "tao/HTTP_Parser.h"
00014 #include "tao/DLL_Parser.h"
00015 #include "tao/ORB_Core.h"
00016 #include "tao/Adapter_Factory.h"
00017 #include "tao/Default_Stub_Factory.h"
00018 #include "tao/Default_Endpoint_Selector_Factory.h"
00019 #include "tao/Default_Thread_Lane_Resources_Manager.h"
00020 #include "tao/Default_Collocation_Resolver.h"
00021 #include "tao/Codeset_Manager_Factory_Base.h"
00022 #include "tao/Codeset_Manager.h"
00023 #include "tao/debug.h"
00024 #include "tao/StringSeqC.h"
00025 
00026 #include "ace/Dynamic_Service.h"
00027 #include "ace/Arg_Shifter.h"
00028 #include "ace/Argv_Type_Converter.h"
00029 #include "ace/Env_Value_T.h"
00030 #include "ace/ACE.h"
00031 #include "ace/OS_NS_stdio.h"
00032 #include "ace/Static_Object_Lock.h"
00033 
00034 ACE_RCSID (tao,
00035            TAO_Internal,
00036            "$Id: TAO_Internal.cpp 79495 2007-08-24 15:22:50Z mesnier_p $")
00037 
00038 #ifndef TAO_DEFAULT_RESOURCE_FACTORY_ARGS
00039 #  define TAO_DEFAULT_RESOURCE_FACTORY_ARGS 0
00040 #endif  /* !TAO_DEFAULT_RESOURCE_FACTORY_ARGS */
00041 
00042 #ifndef TAO_DEFAULT_SERVER_STRATEGY_FACTORY_ARGS
00043 #  define TAO_DEFAULT_SERVER_STRATEGY_FACTORY_ARGS 0
00044 #endif  /* !TAO_DEFAULT_SERVER_STRATEGY_FACTORY_ARGS */
00045 
00046 #ifndef TAO_DEFAULT_CLIENT_STRATEGY_FACTORY_ARGS
00047 #  define TAO_DEFAULT_CLIENT_STRATEGY_FACTORY_ARGS 0
00048 #endif  /* !TAO_DEFAULT_RESOURCE_FACTORY_ARGS */
00049 
00050 
00051 namespace
00052 {
00053   /**
00054    * Parses the supplied command-line arguments to extract any that
00055    * apply to the process (globally)
00056    *
00057    * @brief Modifies the argc to reflect any arguments it has
00058    * "consumed"
00059    *
00060    * When multiple ORBs are being configured, the global options are
00061    * only processed for the first ORB loaded. However subsequent ORBs
00062    * may be supplied with some of these options, so they need to be
00063    * eliminated as though they were processed. For this reason,
00064    * this function is called for every ORB, but only the first call
00065    * sets apply_values to true
00066    *
00067    */
00068   int
00069   parse_global_args_i (int &argc,
00070                        ACE_TCHAR **argv,
00071                        CORBA::StringSeq &svc_config_argv,
00072                        bool apply_values);
00073 
00074   /**
00075    * Parses the supplied command-line arguments to extract any that
00076    * specify a Service Configurator file (-ORBSvcConf). This is done
00077    * separately, because depending on the context, the configuration
00078    * file may apply to the process-wide service repository, or to the
00079    * orb-specific (private) one.
00080    *
00081    * @brief Modifies the argc to reflect any arguments it has
00082    * "consumed"
00083    */
00084   int
00085   parse_svcconf_args_i (int &argc,
00086                        ACE_TCHAR **argv,
00087                        CORBA::StringSeq &svc_config_argv);
00088 
00089   /**
00090    * Initialize the ACE Service Configurator with the process-global
00091    * services (available to any ORB).
00092    *
00093    * @return @c 0 if successful, @c -1 with @c errno set if failure.
00094    *
00095    * @note You can provide your program a set of default `svc.conf'
00096    *       entries by setting @a ignore_default_svc_conf_file to
00097    *       non-zero and use @c default_svc_conf_entries() before
00098    *       calling @c open_global_services().  In addition, you can @a
00099    *       skip_service_config_open altogether, which used to be
00100    *       important when the ORB is linked in via the
00101    *       ACE_Service_Config, since the ACE_Service_Config was
00102    *       non-reentrant.  However, the ACE_Service_Config is now
00103    *       reentrant meaning that it is really no longer necessary to
00104    *       do so.
00105    */
00106   void register_global_services_i (ACE_Service_Gestalt * pcfg);
00107   void register_additional_services_i (ACE_Service_Gestalt * pcfg);
00108 
00109   /**
00110    * Parses the supplied command-line arguments to extract any
00111    * instance-specific ones.
00112    *
00113    * @brief Modifies the argc to reflect any arguments it has
00114    * "consumed"
00115    */
00116   int
00117   parse_private_args_i (int &argc,
00118                         ACE_TCHAR **argv,
00119                         CORBA::StringSeq & svc_config_argv,
00120                         bool & skip_service_config_open);
00121 
00122   /**
00123    * Initialize ORB-local (private) ACE Service Configurator
00124    * repository.
00125    *
00126    * @return @c 0 if successful, @c -1 with @c errno set if failure.
00127    *
00128    */
00129   int open_private_services_i (ACE_Service_Gestalt* pcfg,
00130                                int & argc,
00131                                char ** argv,
00132                                bool skip_service_config_open = false,
00133                                bool ignore_default_svc_conf_file = false);
00134 
00135   /**
00136    * Number of times open_services() has been called.  Incremented by
00137    * open_global_services_i(), and decremented by close_services().
00138    *
00139    * @note In/decrement operations are atomic.
00140    */
00141   long service_open_count = 0;
00142 
00143   /**
00144    * Part of a condition variable, which helps to ensure non-default
00145    * ORBs can not proceed with their initialization, until the globaly
00146    * required services have been instantiated by the default
00147    * ORB. Usually, the first ORB to be created is designated the
00148    * default ORB (reference the CORBA spec)
00149    */
00150   bool is_ubergestalt_ready = false;
00151 
00152   char const * resource_factory_args =
00153     TAO_DEFAULT_RESOURCE_FACTORY_ARGS;
00154   char const * server_strategy_factory_args =
00155     TAO_DEFAULT_SERVER_STRATEGY_FACTORY_ARGS;
00156   char const * client_strategy_factory_args =
00157     TAO_DEFAULT_CLIENT_STRATEGY_FACTORY_ARGS;
00158 
00159 #if (TAO_NEGOTIATE_CODESETS == 1)
00160   bool negotiate_codesets = true;
00161 #else
00162   bool negotiate_codesets = false;
00163 #endif /* TAO_NEGOTIATE_CODESETS */
00164 } // anonymous namespace
00165 
00166 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00167 
00168 #if defined (ACE_HAS_THREADS)
00169 /// A little helper class to get around the TAO_Singleton::instance ()
00170 /// inability to pass default initialization arguments to the
00171 /// singleton ctor.
00172 
00173 class TAO_Ubergestalt_Ready_Condition
00174   : public ACE_SYNCH_RECURSIVE_CONDITION
00175 {
00176 public:
00177   static TAO_Ubergestalt_Ready_Condition* instance (void)
00178   {
00179     return TAO_Singleton <TAO_Ubergestalt_Ready_Condition,
00180       TAO_SYNCH_RECURSIVE_MUTEX>::instance ();
00181   };
00182 
00183   TAO_Ubergestalt_Ready_Condition (void)
00184     : ACE_SYNCH_RECURSIVE_CONDITION
00185   (this->mutex_)
00186   {
00187     // empty
00188   };
00189 
00190 private:
00191   /// The mutex, associated with the condition. Do not use the ACE
00192   /// global mutex, because it causes deadlocks with other thrads that
00193   /// may be in DLL_Manager::open()
00194   ACE_Recursive_Thread_Mutex mutex_;
00195 };
00196 #endif // ACE_HAS_THREADS
00197 
00198 int
00199 TAO::ORB::open_services (ACE_Service_Gestalt* pcfg,
00200                          int &argc,
00201                          ACE_TCHAR **argv)
00202 {
00203   {
00204     ACE_MT (ACE_GUARD_RETURN (TAO_SYNCH_RECURSIVE_MUTEX,
00205                               guard,
00206                               TAO_Ubergestalt_Ready_Condition::instance ()->mutex (),
00207                               -1));
00208 
00209     // Wait in line, while the default ORB (which isn't us) completes
00210     // initialization of the globaly required service objects
00211     if (service_open_count == 1)
00212       {
00213         if (TAO_debug_level > 4)
00214           ACE_DEBUG ((LM_DEBUG,
00215                       ACE_TEXT ("TAO (%P|%t) Waiting for the default ")
00216                       ACE_TEXT ("ORB to complete the global ")
00217                       ACE_TEXT ("initialization\n")));
00218 
00219         ACE_MT (while (!is_ubergestalt_ready)
00220                 TAO_Ubergestalt_Ready_Condition::instance ()->wait ());
00221 
00222         if (TAO_debug_level > 4)
00223           ACE_DEBUG ((LM_DEBUG,
00224                       ACE_TEXT ("TAO (%P|%t) The default ")
00225                       ACE_TEXT ("ORB must have completed the global ")
00226                       ACE_TEXT ("initialization...\n")));
00227 
00228       }
00229     else
00230       {
00231         if (TAO_debug_level > 4)
00232           ACE_DEBUG ((LM_DEBUG,
00233                       ACE_TEXT ("TAO (%P|%t) We are %sthe default ")
00234                       ACE_TEXT ("ORB ...\n"),
00235                       (service_open_count == 0) ? "" : "not "));
00236       }
00237 
00238     ++service_open_count;
00239   }
00240 
00241   // Construct an argument vector specific to the Service
00242   // Configurator.
00243   CORBA::StringSeq svc_config_argv;
00244 
00245   // Be certain to copy the program name so that service configurator
00246   // has something to skip!
00247   ACE_CString argv0 ("");
00248 
00249   if (argc > 0 && argv != 0)
00250     {
00251       argv0 = ACE_TEXT_ALWAYS_CHAR (argv[0]);
00252     }
00253 
00254   svc_config_argv.length (1);
00255   svc_config_argv[0] = argv0.c_str ();
00256 
00257   // Should we skip the ACE_Service_Config::open() method, e.g., if we
00258   // already being configured by the ACE Service Configurator.
00259   //
00260   // @@ This is no longer needed since the Service Configurator is now
00261   // reentrant.(-Ossama)
00262   // @@ Leaving it in, since the -ORBSkipServiceConfigOpen is still
00263   // available. (-Iliyan)
00264   bool skip_service_config_open = false;
00265 
00266   // Extract any ORB options from the argument vector.
00267   if (parse_private_args_i (argc,
00268                             argv,
00269                             svc_config_argv,
00270                             skip_service_config_open) == -1)
00271     {
00272       return -1;
00273     }
00274 
00275   // Construct an argument vector specific to the process-wide
00276   // (global) Service Configurator instance.
00277   CORBA::StringSeq global_svc_config_argv;
00278 
00279   ACE_Service_Gestalt * theone = ACE_Service_Config::global ();
00280 
00281   if (service_open_count == 1)
00282     {
00283       ACE_Service_Config_Guard config_guard (theone);
00284 
00285       if (TAO_debug_level > 2)
00286         {
00287           ACE_DEBUG ((LM_DEBUG,
00288                       ACE_TEXT ("TAO (%P|%t) Initializing the ")
00289                       ACE_TEXT ("process-wide services\n")));
00290         }
00291 
00292       register_global_services_i (theone);
00293 
00294       // Be certain to copy the program name so that service configurator
00295       // has something to skip!
00296       ACE_CString gargv0 ("");
00297 
00298       if (argc > 0 && argv != 0)
00299         {
00300           gargv0 = ACE_TEXT_ALWAYS_CHAR (argv[0]);
00301         }
00302 
00303       global_svc_config_argv.length (1);
00304       global_svc_config_argv[0] = gargv0.c_str ();
00305 
00306       if (parse_global_args_i (argc, argv, global_svc_config_argv, true) == -1)
00307         {
00308           return -1;
00309         }
00310 
00311       if (parse_svcconf_args_i (argc, argv, global_svc_config_argv) == -1)
00312         {
00313           return -1;
00314         }
00315 
00316       // If the target configuration happens to be the global context,
00317       // add any 'private' arguments here.
00318       if (pcfg == theone && svc_config_argv.length() > 1)
00319         {
00320           CORBA::ULong glen = global_svc_config_argv.length();
00321           global_svc_config_argv.length(glen + svc_config_argv.length() - 1);
00322           for (CORBA::ULong i = 1; i < svc_config_argv.length(); i++)
00323             global_svc_config_argv[glen++] = svc_config_argv[i];
00324           svc_config_argv.length(1);
00325         }
00326 
00327       int global_svc_config_argc = global_svc_config_argv.length ();
00328       int status =
00329         open_private_services_i (theone,
00330                                  global_svc_config_argc,
00331                                  global_svc_config_argv.get_buffer (),
00332                                  skip_service_config_open);
00333 
00334       if (status == -1)
00335         {
00336           if (TAO_debug_level > 0)
00337             {
00338               ACE_ERROR ((LM_DEBUG,
00339                           ACE_TEXT ("TAO (%P|%t) Failed to open process-")
00340                           ACE_TEXT ("wide service configuration\n")));
00341             }
00342 
00343           return -1;
00344         }
00345 
00346       register_additional_services_i (theone);
00347 
00348       if (TAO_debug_level > 4)
00349         ACE_DEBUG ((LM_DEBUG,
00350                     ACE_TEXT ("TAO (%P|%t) Default ORB - global ")
00351                     ACE_TEXT ("initialization completed.\n")));
00352 
00353       // Notify all other threads that may be waiting, that the global
00354       // gestalt has been initialized.
00355       {
00356         ACE_MT (ACE_GUARD_RETURN (TAO_SYNCH_RECURSIVE_MUTEX,
00357                                   guard,
00358                                   TAO_Ubergestalt_Ready_Condition::instance ()->mutex (),
00359                                   -1));
00360 
00361         is_ubergestalt_ready = true;
00362         ACE_MT (if (TAO_Ubergestalt_Ready_Condition::instance ()->
00363                     broadcast () == -1)
00364                 return -1);
00365       }
00366 
00367     }
00368   else
00369     {
00370       int status =
00371         parse_global_args_i(argc, argv,global_svc_config_argv, false);
00372       if (status == -1 && TAO_debug_level > 0)
00373         ACE_DEBUG ((LM_DEBUG,
00374                     ACE_TEXT ("TAO (%P|%t) Skipping the process-wide ")
00375                     ACE_TEXT ("service configuration, service_open_count ")
00376                     ACE_TEXT ("= %d, status = %d\n"),
00377                     service_open_count,
00378                     status));
00379     }
00380 
00381   if (TAO_debug_level > 2)
00382     {
00383       ACE_DEBUG ((LM_DEBUG,
00384                   ACE_TEXT ("TAO (%P|%t) Initializing the ")
00385                   ACE_TEXT ("orb-specific services\n")));
00386     }
00387 
00388   if (parse_svcconf_args_i (argc, argv, svc_config_argv) == -1)
00389     {
00390       return -1;
00391     }
00392 
00393   int status = 0;
00394   // only open the private context if it is not also the global context
00395   if (pcfg != ACE_Service_Config::global())
00396     {
00397       int svc_config_argc = svc_config_argv.length ();
00398       status =
00399         open_private_services_i (pcfg,
00400                                  svc_config_argc,
00401                                  svc_config_argv.get_buffer (),
00402                                  skip_service_config_open);
00403     }
00404 
00405   if (status >= 0)
00406     {
00407       return 0;
00408     }
00409 
00410   if (TAO_debug_level > 0)
00411     {
00412       ACE_ERROR_RETURN ((LM_DEBUG,
00413                          ACE_TEXT ("TAO (%P|%t) Failed to ")
00414                          ACE_TEXT ("open orb service configuration\n")),
00415                         -1);
00416     }
00417 
00418   return -1;
00419 }
00420 
00421 int
00422 TAO::ORB::close_services (ACE_Service_Gestalt* pcfg)
00423 {
00424   ACE_MT (ACE_GUARD_RETURN (TAO_SYNCH_RECURSIVE_MUTEX,
00425                             guard,
00426                             *ACE_Static_Object_Lock::instance (),
00427                             -1));
00428   service_open_count--;
00429 
00430   if (pcfg == ACE_Service_Config::global())
00431     return 0;
00432   return pcfg->close ();
00433 }
00434 
00435 void
00436 TAO::ORB::default_svc_conf_entries (char const * rf_args,
00437                                     char const * ssf_args,
00438                                     char const * csf_args)
00439 {
00440   resource_factory_args        = rf_args;
00441   server_strategy_factory_args = ssf_args;
00442   client_strategy_factory_args = csf_args;
00443 }
00444 
00445 TAO_END_VERSIONED_NAMESPACE_DECL
00446 
00447 // -----------------------------------------------------
00448 namespace
00449 {
00450   /// Open services, belonging to the gestalt instance.
00451 
00452   int
00453   open_private_services_i (ACE_Service_Gestalt * pcfg,
00454                            int & argc,
00455                            char ** argv,
00456                            bool skip_service_config_open,
00457                            bool ignore_default_svc_conf_file)
00458   {
00459 
00460     if (skip_service_config_open)
00461       {
00462         return 0;
00463       }
00464 
00465 #if defined (TAO_PLATFORM_SVC_CONF_FILE_NOTSUP)
00466     ignore_default_svc_conf_file = true;
00467 #endif /* TAO_PLATFORM_SVC_CONF_FILE_NOTSUP */
00468 
00469     // Copy command line parameter to allow conversion
00470     ACE_Argv_Type_Converter command_line (argc, argv);
00471 
00472     return pcfg->open (command_line.get_argc (),
00473                        command_line.get_TCHAR_argv (),
00474                        ACE_DEFAULT_LOGGER_KEY,
00475                        0, // Don't ignore static services.
00476                        ignore_default_svc_conf_file);
00477   }
00478 
00479   /// @brief registers all process-wide (global) services, available
00480   /// to all ORBs
00481   void
00482   register_global_services_i (ACE_Service_Gestalt * pcfg)
00483   {
00484     // This has to be done before intializing the resource
00485     // factory. Codesets is a special library since its configuration
00486     // is optional and it may be linked statically.
00487     if (negotiate_codesets)
00488       {
00489         TAO_Codeset_Manager_Factory_Base *factory =
00490           ACE_Dynamic_Service<TAO_Codeset_Manager_Factory_Base>::instance (
00491             "TAO_Codeset");
00492 
00493         if (factory == 0 || factory->is_default ())
00494           {
00495 #if !defined (TAO_AS_STATIC_LIBS)
00496             // only for dynamic libs, check to see if default factory
00497             // and if so, remove it
00498             ACE_Service_Config::process_directive (
00499               ACE_REMOVE_SERVICE_DIRECTIVE ("TAO_Codeset"));
00500 
00501             ACE_Service_Config::process_directive (
00502               ACE_DYNAMIC_SERVICE_DIRECTIVE (
00503                 "TAO_Codeset",
00504                 "TAO_Codeset",
00505                 "_make_TAO_Codeset_Manager_Factory",
00506                 ""));
00507 
00508             factory =
00509               ACE_Dynamic_Service<
00510                   TAO_Codeset_Manager_Factory_Base
00511                 >::instance ("TAO_Codeset");
00512 #endif
00513           }
00514 
00515         if (factory == 0)
00516           {
00517             if (TAO_debug_level > 0)
00518               {
00519                 ACE_ERROR ((LM_ERROR,
00520                             ACE_TEXT ("(%P|%t) ORB_Core: ")
00521                             ACE_TEXT ("Unable to initialize ")
00522                             ACE_TEXT ("Codeset Manager\n")));
00523               }
00524           }
00525       }
00526 
00527     pcfg->process_directive (
00528       ace_svc_desc_TAO_Default_Resource_Factory);
00529     pcfg->process_directive (
00530       ace_svc_desc_TAO_Default_Client_Strategy_Factory);
00531     pcfg->process_directive (
00532       ace_svc_desc_TAO_Default_Server_Strategy_Factory);
00533 
00534     // Configure the IIOP factory. You do *NOT* need modify this
00535     // code to add your own protocol, instead simply add the
00536     // following to your svc.conf file:
00537     //
00538     // dynamic PN_Factory Service_Object * LIB:_make_PN_Protocol_Factory() ""
00539     // static Resource_Factory "-ORBProtocolFactory PN_Factory"
00540     //
00541     // where PN is the name of your protocol and LIB is the base
00542     // name of the shared library that implements the protocol.
00543 
00544 #if defined (TAO_HAS_IIOP) && (TAO_HAS_IIOP != 0)
00545     pcfg->process_directive (ace_svc_desc_TAO_IIOP_Protocol_Factory);
00546 #endif /* TAO_HAS_IIOP && TAO_HAS_IIOP != 0 */
00547 
00548     // add descriptor to list of static objects.
00549 #if (TAO_HAS_MCAST_PARSER == 1)
00550     pcfg->process_directive (ace_svc_desc_TAO_MCAST_Parser);
00551 #endif /* TAO_HAS_MCAST_PARSER == 1 */
00552 #if (TAO_HAS_CORBANAME_PARSER == 1)
00553     pcfg->process_directive (ace_svc_desc_TAO_CORBANAME_Parser);
00554 #endif /* TAO_HAS_CORBANAME_PARSER == 1 */
00555 #if (TAO_HAS_CORBALOC_PARSER == 1)
00556     pcfg->process_directive (ace_svc_desc_TAO_CORBALOC_Parser);
00557 #endif /* TAO_HAS_CORBALOC_PARSER == 1 */
00558 #if (TAO_HAS_FILE_PARSER == 1)
00559     pcfg->process_directive (ace_svc_desc_TAO_FILE_Parser);
00560 #endif /* TAO_HAS_FILE_PARSER == 1 */
00561 #if (TAO_HAS_DDL_PARSER == 1)
00562     pcfg->process_directive (ace_svc_desc_TAO_DLL_Parser);
00563 #endif /* TAO_HAS_DDL_PARSER == 1 */
00564 #if (TAO_HAS_HTTP_PARSER == 1)
00565     pcfg->process_directive (ace_svc_desc_TAO_HTTP_Parser);
00566 #endif /* TAO_HAS_HTTP_PARSER */
00567     pcfg->process_directive (ace_svc_desc_TAO_Default_Stub_Factory);
00568     pcfg->process_directive (
00569       ace_svc_desc_TAO_Default_Endpoint_Selector_Factory);
00570     pcfg->process_directive (
00571       ace_svc_desc_TAO_Default_Thread_Lane_Resources_Manager_Factory);
00572     pcfg->process_directive (ace_svc_desc_TAO_Default_Collocation_Resolver);
00573 
00574   } /* register_global_services_i */
00575 
00576   void
00577   register_additional_services_i (ACE_Service_Gestalt * pcfg)
00578   {
00579     // @@ What the heck do these things do and do we need to avoid
00580     //    calling them if we're not invoking the svc.conf file?
00581     // @@ They are needed for platforms that have no file system,
00582     //    like VxWorks.
00583 
00584     if (resource_factory_args != 0)
00585       {
00586         pcfg->process_directive(
00587           ACE_TEXT_CHAR_TO_TCHAR (resource_factory_args));
00588       }
00589 
00590     if (client_strategy_factory_args != 0)
00591       {
00592         pcfg->process_directive
00593           (ACE_TEXT_CHAR_TO_TCHAR (client_strategy_factory_args));
00594       }
00595 
00596     if (server_strategy_factory_args != 0)
00597       {
00598         pcfg->process_directive
00599           (ACE_TEXT_CHAR_TO_TCHAR (server_strategy_factory_args));
00600       }
00601 
00602     ACE_Service_Object * const pi_server_loader =
00603       ACE_Dynamic_Service<ACE_Service_Object>::instance (
00604         pcfg,
00605         "PI_Server_Loader");
00606 
00607     if (pi_server_loader != 0)
00608       {
00609         pi_server_loader->init (0, 0);
00610       }
00611 
00612     ACE_Service_Object * const bidir_loader =
00613       ACE_Dynamic_Service<ACE_Service_Object>::instance (
00614         pcfg,
00615         "BiDirGIOP_Loader");
00616 
00617     if (bidir_loader != 0)
00618       {
00619         bidir_loader->init (0, 0);
00620       }
00621 
00622     ACE_Service_Object * const messaging_loader =
00623       ACE_Dynamic_Service<ACE_Service_Object>::instance (
00624         pcfg,
00625         "Messaging_Loader");
00626 
00627     if (messaging_loader != 0)
00628       {
00629         messaging_loader->init (0, 0);
00630       }
00631 
00632     // Handle RTCORBA library special case.  Since RTCORBA needs
00633     // its init method call to register several hooks, call it
00634     // here if it hasn't already been called.
00635     ACE_Service_Object * const rt_loader =
00636       ACE_Dynamic_Service<ACE_Service_Object>::instance (
00637         pcfg,
00638         "RT_ORB_Loader");
00639 
00640     if (rt_loader != 0)
00641       {
00642         rt_loader->init (0, 0);
00643       }
00644 
00645     ACE_Service_Object * const rtscheduler_loader =
00646       ACE_Dynamic_Service<ACE_Service_Object>::instance (
00647         pcfg,
00648         "RTScheduler_Loader");
00649 
00650     if (rtscheduler_loader != 0)
00651       {
00652         rtscheduler_loader->init (0, 0);
00653       }
00654 
00655     ACE_Service_Object * const csd_framework_loader =
00656       ACE_Dynamic_Service<ACE_Service_Object>::instance (
00657         pcfg,
00658         "CSD_Framework_Loader");
00659 
00660     if (csd_framework_loader != 0)
00661       {
00662         csd_framework_loader->init (0, 0);
00663       }
00664 
00665     ACE_Service_Object * const endpoint_policy_loader =
00666       ACE_Dynamic_Service<ACE_Service_Object>::instance (
00667         pcfg,
00668         "EndpointPolicy_Initializer");
00669 
00670     if (endpoint_policy_loader != 0)
00671       {
00672         endpoint_policy_loader->init (0, 0);
00673       }
00674 
00675     ACE_Service_Object * const diffserv_policy_loader =
00676       ACE_Dynamic_Service<ACE_Service_Object>::instance (
00677         pcfg,
00678         "DiffservPolicy_Initializer");
00679 
00680     if (diffserv_policy_loader != 0)
00681       {
00682         diffserv_policy_loader->init (0, 0);
00683       }
00684   } /* register_additional_services_i */
00685 
00686   int
00687   parse_svcconf_args_i (int &argc,
00688                         ACE_TCHAR **argv,
00689                         CORBA::StringSeq &svc_config_argv)
00690   {
00691     // Extract the Service Configurator ORB options from the argument
00692     // vector.
00693     ACE_Arg_Shifter arg_shifter (argc, argv);
00694     CORBA::ULong len = 0;
00695 
00696     while (arg_shifter.is_anything_left ())
00697       {
00698         const ACE_TCHAR *current_arg =
00699           arg_shifter.get_the_parameter (ACE_TEXT ("-ORBSvcConf"));
00700 
00701         if (0 != current_arg)
00702           {
00703             // Specify the name of the svc.conf file to be used.
00704 
00705             // Proceeds only if the configuration file exists.
00706             FILE * const conf_file =
00707               ACE_OS::fopen (current_arg, ACE_TEXT ("r"));
00708 
00709             if (0 == conf_file)
00710               {
00711                 // Assigning EINVAL to errno to make an exception
00712                 // thrown.  calling code does not throw an exception if
00713                 // the errno is set to ENOENT for some reason.
00714                 errno = EINVAL;
00715 
00716                 ACE_ERROR_RETURN ((LM_ERROR,
00717                                    ACE_TEXT ("TAO (%P|%t) Service ")
00718                                    ACE_TEXT ("Configurator ")
00719                                    ACE_TEXT ("unable to open file %s\n"),
00720                                    current_arg),
00721                                   -1);
00722               }
00723             else
00724               {
00725                 ACE_OS::fclose (conf_file);
00726               }
00727 
00728             len = svc_config_argv.length ();
00729             svc_config_argv.length (len + 2);  // 2 arguments to add
00730 
00731             svc_config_argv[len] = CORBA::string_dup ("-f");
00732             svc_config_argv[len + 1] =
00733               CORBA::string_dup (ACE_TEXT_ALWAYS_CHAR (current_arg));
00734 
00735             arg_shifter.consume_arg ();
00736           }
00737         // Can't interpret this argument.  Move on to the next argument.
00738         else
00739           {
00740             // Any arguments that don't match are ignored so that the
00741             // caller can still use them.
00742             arg_shifter.ignore_arg ();
00743           }
00744       }
00745 
00746     return 0;
00747   } /* parse_svcconf_args_i */
00748 
00749   int
00750   parse_private_args_i (int &argc,
00751                         ACE_TCHAR **argv,
00752                         CORBA::StringSeq &svc_config_argv,
00753                         bool & skip_service_config_open)
00754   {
00755     // Extract the Service Configurator ORB options from the argument
00756     // vector.
00757     ACE_Arg_Shifter arg_shifter (argc, argv);
00758     CORBA::ULong len = 0;
00759 
00760     while (arg_shifter.is_anything_left ())
00761       {
00762         const ACE_TCHAR *current_arg = 0;
00763         if (0 == arg_shifter.cur_arg_strncasecmp
00764             (ACE_TEXT ("-ORBSkipServiceConfigOpen")))
00765           {
00766             skip_service_config_open = true;
00767 
00768             arg_shifter.consume_arg ();
00769           }
00770         else if (0 != (current_arg = arg_shifter.get_the_parameter
00771                        (ACE_TEXT ("-ORBSvcConfDirective"))))
00772           {
00773             len = svc_config_argv.length ();
00774             svc_config_argv.length (len + 2);  // 2 arguments to add
00775 
00776             // This is used to pass arguments to the Service
00777             // Configurator using the "command line" to provide
00778             // configuration information rather than using a svc.conf
00779             // file.  Pass the "-S" to the service configurator.
00780             svc_config_argv[len] = CORBA::string_dup ("-S");
00781             svc_config_argv[len + 1] =
00782               CORBA::string_dup (ACE_TEXT_ALWAYS_CHAR (current_arg));
00783 
00784             arg_shifter.consume_arg ();
00785           }
00786         else if (0 != (current_arg = arg_shifter.get_the_parameter
00787                        (ACE_TEXT ("-ORBServiceConfigLoggerKey"))))
00788           {
00789             len = svc_config_argv.length ();
00790             svc_config_argv.length (len + 2);  // 2 arguments to add
00791 
00792             svc_config_argv[len] = CORBA::string_dup ("-k");
00793             svc_config_argv[len + 1] =
00794               CORBA::string_dup (ACE_TEXT_ALWAYS_CHAR (current_arg));
00795 
00796             arg_shifter.consume_arg ();
00797           }
00798         else if (0 == arg_shifter.cur_arg_strncasecmp
00799                        (ACE_TEXT ("-ORBNegotiateCodesets")))
00800           {
00801             // Negotiate codesets must be evaluated prior to calling
00802             // register_global_services_i.
00803 
00804             // Don't consume, the ORB_Core::init will use it again.
00805             arg_shifter.ignore_arg();
00806 
00807             if (0 != (current_arg = arg_shifter.get_current()))
00808               negotiate_codesets = (ACE_OS::atoi (current_arg));
00809             arg_shifter.ignore_arg();
00810           }
00811         else if (0 != (current_arg =
00812                        arg_shifter.get_the_parameter
00813                        (ACE_TEXT ("-ORBDebugLevel"))))
00814           {
00815             // Allowing different ORBs to change the global debug
00816             // level may be unexpected, but since this
00817             TAO_debug_level = ACE_OS::atoi (current_arg);
00818 
00819             arg_shifter.consume_arg ();
00820           }
00821         else
00822           {
00823             // Can't interpret this argument.  Move on to the next
00824             // argument.  Any arguments that don't match are ignored
00825             // so that the caller can still use them.
00826             arg_shifter.ignore_arg ();
00827           }
00828       }
00829 
00830     return 0;
00831   } /* parse_private_args_i */
00832 
00833   int
00834   parse_global_args_i (int &argc,
00835                        ACE_TCHAR **argv,
00836                        CORBA::StringSeq &svc_config_argv,
00837                        bool apply_values)
00838   {
00839     // NOTE: When adding new global arguments, ensure they are only
00840     // applied when apply_values is true, but that they are always
00841     // consumed, if they need to be consumed.
00842 #if defined (TAO_DEBUG) && !defined (ACE_HAS_WINCE)
00843     // Make it a little easier to debug programs using this code.
00844     if (apply_values)
00845       {
00846         TAO_debug_level = ACE_Env_Value<u_int> ("TAO_ORB_DEBUG", 0);
00847 
00848         char * const value = ACE_OS::getenv ("TAO_ORB_DEBUG");
00849 
00850         if (value != 0)
00851           {
00852             TAO_debug_level = ACE_OS::atoi (value);
00853 
00854             if (TAO_debug_level <= 0)
00855               {
00856                 TAO_debug_level = 1;
00857               }
00858 
00859             ACE_DEBUG ((LM_DEBUG,
00860                         ACE_TEXT ("TAO_debug_level == %d\n"),
00861                         TAO_debug_level));
00862           }
00863       }
00864 #endif  /* TAO_DEBUG && !ACE_HAS_WINCE */
00865 
00866     // Extract the Service Configurator ORB options from the argument
00867     // vector.
00868     ACE_Arg_Shifter arg_shifter (argc, argv);
00869     CORBA::ULong len = 0;
00870 
00871     while (arg_shifter.is_anything_left ())
00872       {
00873         if (0 == arg_shifter.cur_arg_strncasecmp (ACE_TEXT ("-ORBDebug")))
00874           {
00875             if (apply_values)
00876               {
00877                 // Later, replace all of these
00878                 // warning this turns on a daemon.
00879                 ACE::debug (1);
00880               }
00881 
00882             arg_shifter.consume_arg ();
00883           }
00884         else if (0 == arg_shifter.cur_arg_strncasecmp
00885                  (ACE_TEXT ("-ORBDaemon")))
00886           {
00887             // Be a daemon.
00888             if (apply_values)
00889               {
00890                 len = svc_config_argv.length ();
00891                 svc_config_argv.length (len + 1);
00892 
00893                 svc_config_argv[len] =
00894                   CORBA::string_dup ("-b");
00895               }
00896 
00897             arg_shifter.consume_arg ();
00898           }
00899         // Can't interpret this argument.
00900         // Move on to the next argument.
00901         else
00902           {
00903             // Any arguments that don't match are ignored so
00904             // that the caller can still use them.
00905             arg_shifter.ignore_arg ();
00906           }
00907       }
00908     return 0;
00909   } /* parse_global_args_i */
00910 } // anonymous namespace.

Generated on Sun Jan 27 13:07:37 2008 for TAO by doxygen 1.3.6