TAO_Internal.cpp

Go to the documentation of this file.
00001 // TAO_Internal.cpp,v 1.90 2006/06/03 05:06:31 mesnier_p Exp
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/DLL_Parser.h"
00014 #include "tao/ORB_Core.h"
00015 #include "tao/Adapter_Factory.h"
00016 #include "tao/Default_Stub_Factory.h"
00017 #include "tao/Default_Endpoint_Selector_Factory.h"
00018 #include "tao/Default_Protocols_Hooks.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            "TAO_Internal.cpp,v 1.90 2006/06/03 05:06:31 mesnier_p Exp")
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                        char **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                        char **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                         char **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 /// A little helper class to get around the TAO_Singleton::instance ()
00169 /// inability to pass default initialization arguments to the
00170 /// singleton ctor.
00171 
00172 #if defined (ACE_HAS_THREADS)
00173 class TAO_Ubergestalt_Ready_Condition
00174   : public ACE_SYNCH_RECURSIVE_CONDITION
00175 {
00176 public:
00177   TAO_Ubergestalt_Ready_Condition (void)
00178     : ACE_SYNCH_RECURSIVE_CONDITION
00179   (*ACE_Static_Object_Lock::instance())
00180   {
00181   };
00182 
00183   static TAO_Ubergestalt_Ready_Condition* instance (void)
00184   {
00185     // The first thread to get here will initialize the static
00186     // local. Any subsequent threads synchronizaton will be handled by
00187     // TAO_Singleton
00188     static TAO_Ubergestalt_Ready_Condition *i_ =
00189       TAO_Singleton <TAO_Ubergestalt_Ready_Condition,
00190                      TAO_SYNCH_RECURSIVE_MUTEX>::instance ();
00191 
00192     return i_;
00193   };
00194 };
00195 #endif // ACE_HAS_THREADS
00196 
00197 int
00198 TAO::ORB::open_services (ACE_Service_Gestalt* pcfg,
00199                          int &argc,
00200                          ACE_TCHAR **argv)
00201 {
00202   {
00203     ACE_MT (ACE_GUARD_RETURN (TAO_SYNCH_RECURSIVE_MUTEX,
00204                               guard,
00205                               TAO_Ubergestalt_Ready_Condition::instance ()->mutex (),
00206                               -1));
00207 
00208     // Wait in line, while the default ORB (which isn't us) completes
00209     // initialization of the globaly reuired service objects
00210     if (service_open_count == 1)
00211       {
00212         if (TAO_debug_level > 4)
00213           ACE_DEBUG ((LM_DEBUG,
00214                       ACE_TEXT ("TAO (%P|%t) Waiting for the default ")
00215                       ACE_TEXT ("ORB to complete the global ")
00216                       ACE_TEXT ("initialization\n")));
00217 
00218         ACE_MT (while (!is_ubergestalt_ready)
00219                 TAO_Ubergestalt_Ready_Condition::instance ()->wait ());
00220 
00221         if (TAO_debug_level > 4)
00222           ACE_DEBUG ((LM_DEBUG,
00223                       ACE_TEXT ("TAO (%P|%t) The default ")
00224                       ACE_TEXT ("ORB must have completed the global ")
00225                       ACE_TEXT ("initialization...\n")));
00226 
00227       }
00228     else
00229       {
00230         if (TAO_debug_level > 4)
00231           ACE_DEBUG ((LM_DEBUG,
00232                       ACE_TEXT ("TAO (%P|%t) We are %sthe default ")
00233                       ACE_TEXT ("ORB ...\n"),
00234                       (service_open_count == 0) ? "" : "not "));
00235       }
00236 
00237     service_open_count++;
00238   }
00239 
00240   // Construct an argument vector specific to the Service
00241   // Configurator.
00242   CORBA::StringSeq svc_config_argv;
00243 
00244   // Be certain to copy the program name so that service configurator
00245   // has something to skip!
00246   ACE_CString argv0 ("");
00247 
00248   if (argc > 0 && argv != 0)
00249     {
00250       argv0 = ACE_TEXT_ALWAYS_CHAR (argv[0]);
00251     }
00252 
00253   svc_config_argv.length (1);
00254   svc_config_argv[0] = argv0.c_str ();
00255 
00256   // Should we skip the ACE_Service_Config::open() method, e.g., if we
00257   // already being configured by the ACE Service Configurator.
00258   //
00259   // @@ This is no longer needed since the Service Configurator is now
00260   // reentrant.(-Ossama)
00261   // @@ Leaving it in, since the -ORBSkipServiceConfigOpen is still
00262   // available. (-Iliyan)
00263   bool skip_service_config_open = false;
00264 
00265   // Extract any ORB options from the argument vector.
00266   if (parse_private_args_i (argc,
00267                             argv,
00268                             svc_config_argv,
00269                             skip_service_config_open) == -1)
00270     {
00271       return -1;
00272     }
00273 
00274   // Construct an argument vector specific to the process-wide
00275   // (global) Service Configurator instance.
00276   CORBA::StringSeq global_svc_config_argv;
00277 
00278   ACE_Service_Gestalt * theone = ACE_Service_Config::global ();
00279 
00280   if (service_open_count == 1)
00281     {
00282       ACE_Service_Config_Guard config_guard (theone);
00283 
00284       if (TAO_debug_level > 2)
00285         {
00286           ACE_DEBUG ((LM_DEBUG,
00287                       ACE_TEXT ("TAO (%P|%t) Initializing the ")
00288                       ACE_TEXT ("process-wide services\n")));
00289         }
00290 
00291       register_global_services_i (theone);
00292 
00293       // Be certain to copy the program name so that service configurator
00294       // has something to skip!
00295       ACE_CString argv0 ("");
00296 
00297       if (argc > 0 && argv != 0)
00298         {
00299           argv0 = ACE_TEXT_ALWAYS_CHAR (argv[0]);
00300         }
00301 
00302       global_svc_config_argv.length (1);
00303       global_svc_config_argv[0] = argv0.c_str ();
00304 
00305       if (parse_global_args_i (argc, argv, global_svc_config_argv, true) == -1)
00306         {
00307           return -1;
00308         }
00309 
00310       if (parse_svcconf_args_i (argc, argv, global_svc_config_argv) == -1)
00311         {
00312           return -1;
00313         }
00314 
00315       int global_svc_config_argc = global_svc_config_argv.length ();
00316       int status =
00317         open_private_services_i (theone,
00318                                  global_svc_config_argc,
00319                                  global_svc_config_argv.get_buffer (),
00320                                  skip_service_config_open);
00321 
00322       if (status == -1 && TAO_debug_level > 0)
00323         {
00324           if (TAO_debug_level > 0)
00325             {
00326               ACE_ERROR_RETURN ((LM_DEBUG,
00327                                  ACE_TEXT ("TAO (%P|%t) Failed to ")
00328                                  ACE_TEXT ("open process-wide service ")
00329                                  ACE_TEXT ("configuration\n")),
00330                                 -1);
00331             }
00332 
00333           return -1;
00334         }
00335 
00336       register_additional_services_i (theone);
00337 
00338 
00339       if (TAO_debug_level > 4)
00340         ACE_DEBUG ((LM_DEBUG,
00341                     ACE_TEXT ("TAO (%P|%t) Default ORB - global ")
00342                     ACE_TEXT ("initialization completed.\n")));
00343 
00344       // Notify all other threads that may be waiting, that the global
00345       // gestalt has been initialized.
00346       {
00347         ACE_MT (ACE_GUARD_RETURN (TAO_SYNCH_RECURSIVE_MUTEX,
00348                                   guard,
00349                                   TAO_Ubergestalt_Ready_Condition::instance ()->mutex (),
00350                                   -1));
00351 
00352         is_ubergestalt_ready = true;
00353         ACE_MT (if (TAO_Ubergestalt_Ready_Condition::instance ()->
00354                     broadcast () == -1)
00355                 return -1);
00356       }
00357 
00358     }
00359   else
00360     {
00361       int status =
00362         parse_global_args_i(argc, argv,global_svc_config_argv, false);
00363       if (status == -1 && TAO_debug_level > 0)
00364         ACE_DEBUG ((LM_DEBUG,
00365                     ACE_TEXT ("TAO (%P|%t) Skipping the process-wide ")
00366                     ACE_TEXT ("service configuration, service_open_count ")
00367                     ACE_TEXT ("= %d, status = %d\n"),
00368                     service_open_count,
00369                     status));
00370     }
00371 
00372   if (TAO_debug_level > 2)
00373     {
00374       ACE_DEBUG ((LM_DEBUG,
00375                   ACE_TEXT ("TAO (%P|%t) Initializing the ")
00376                   ACE_TEXT ("orb-specific services\n")));
00377     }
00378 
00379   if (parse_svcconf_args_i (argc, argv, svc_config_argv) == -1)
00380     {
00381       return -1;
00382     }
00383 
00384   int svc_config_argc = svc_config_argv.length ();
00385   int status =
00386     open_private_services_i (pcfg,
00387                              svc_config_argc,
00388                              svc_config_argv.get_buffer (),
00389                              skip_service_config_open);
00390 
00391   if (status >= 0)
00392     {
00393       return 0;
00394     }
00395 
00396   if (TAO_debug_level > 0)
00397     {
00398       ACE_ERROR_RETURN ((LM_DEBUG,
00399                          ACE_TEXT ("TAO (%P|%t) Failed to ")
00400                          ACE_TEXT ("open orb service configuration\n")),
00401                         -1);
00402     }
00403 
00404   return -1;
00405 }
00406 
00407 int
00408 TAO::ORB::close_services (ACE_Service_Gestalt* pcfg)
00409 {
00410   ACE_MT (ACE_GUARD_RETURN (TAO_SYNCH_RECURSIVE_MUTEX,
00411                             guard,
00412                             *ACE_Static_Object_Lock::instance (),
00413                             -1));
00414   service_open_count--;
00415 
00416   return pcfg->close ();
00417 }
00418 
00419 void
00420 TAO::ORB::default_svc_conf_entries (char const * rf_args,
00421                                     char const * ssf_args,
00422                                     char const * csf_args)
00423 {
00424   resource_factory_args        = rf_args;
00425   server_strategy_factory_args = ssf_args;
00426   client_strategy_factory_args = csf_args;
00427 }
00428 
00429 TAO_END_VERSIONED_NAMESPACE_DECL
00430 
00431 // -----------------------------------------------------
00432 namespace
00433 {
00434   /// Open services, belonging to the gestalt instance.
00435 
00436   int
00437   open_private_services_i (ACE_Service_Gestalt * pcfg,
00438                            int & argc,
00439                            ACE_TCHAR ** argv,
00440                            bool skip_service_config_open,
00441                            bool ignore_default_svc_conf_file)
00442   {
00443 
00444     if (skip_service_config_open)
00445       {
00446         return 0;
00447       }
00448 
00449 #if defined (TAO_PLATFORM_SVC_CONF_FILE_NOTSUP)
00450     ignore_default_svc_conf_file = true;
00451 #endif /* TAO_PLATFORM_SVC_CONF_FILE_NOTSUP */
00452 
00453     return pcfg->open (argc,
00454                        argv,
00455                        ACE_DEFAULT_LOGGER_KEY,
00456                        0, // Don't ignore static services.
00457                        ignore_default_svc_conf_file);
00458   }
00459 
00460   /// @brief registers all process-wide (global) services, available
00461   /// to all ORBs
00462   void
00463   register_global_services_i (ACE_Service_Gestalt * pcfg)
00464   {
00465     // This has to be done before intializing the resource
00466     // factory. Codesets is a special library since its configuration
00467     // is optional and it may be linked statically.
00468     if (negotiate_codesets)
00469       {
00470         TAO_Codeset_Manager_Factory_Base *factory =
00471           ACE_Dynamic_Service<TAO_Codeset_Manager_Factory_Base>::instance (
00472             "TAO_Codeset");
00473 
00474         if (factory == 0 || factory->is_default ())
00475           {
00476 #if !defined (TAO_AS_STATIC_LIBS)
00477             // only for dynamic libs, check to see if default factory
00478             // and if so, remove it
00479             ACE_Service_Config::process_directive (
00480               ACE_REMOVE_SERVICE_DIRECTIVE ("TAO_Codeset"));
00481 
00482             ACE_Service_Config::process_directive (
00483               ACE_DYNAMIC_SERVICE_DIRECTIVE (
00484                 "TAO_Codeset",
00485                 "TAO_Codeset",
00486                 "_make_TAO_Codeset_Manager_Factory",
00487                 ""));
00488 
00489             factory =
00490               ACE_Dynamic_Service<
00491                   TAO_Codeset_Manager_Factory_Base
00492                 >::instance ("TAO_Codeset");
00493 #endif
00494           }
00495 
00496         if (factory == 0)
00497           {
00498             if (TAO_debug_level > 0)
00499               {
00500                 ACE_ERROR ((LM_ERROR,
00501                             ACE_TEXT ("(%P|%t) ORB_Core: ")
00502                             ACE_TEXT ("Unable to initialize ")
00503                             ACE_TEXT ("Codeset Manager\n")));
00504               }
00505           }
00506       }
00507 
00508     pcfg->process_directive (
00509       ace_svc_desc_TAO_Default_Resource_Factory);
00510     pcfg->process_directive (
00511       ace_svc_desc_TAO_Default_Client_Strategy_Factory);
00512     pcfg->process_directive (
00513       ace_svc_desc_TAO_Default_Server_Strategy_Factory);
00514 
00515     // Configure the IIOP factory. You do *NOT* need modify this
00516     // code to add your own protocol, instead simply add the
00517     // following to your svc.conf file:
00518     //
00519     // dynamic PN_Factory Service_Object * LIB:_make_PN_Protocol_Factory() ""
00520     // static Resource_Factory "-ORBProtocolFactory PN_Factory"
00521     //
00522     // where PN is the name of your protocol and LIB is the base
00523     // name of the shared library that implements the protocol.
00524 
00525 #if defined (TAO_HAS_IIOP) && (TAO_HAS_IIOP != 0)
00526     pcfg->process_directive (ace_svc_desc_TAO_IIOP_Protocol_Factory);
00527 #endif /* TAO_HAS_IIOP && TAO_HAS_IIOP != 0 */
00528 
00529     // add descriptor to list of static objects.
00530     pcfg->process_directive (ace_svc_desc_TAO_MCAST_Parser);
00531     pcfg->process_directive (ace_svc_desc_TAO_CORBANAME_Parser);
00532     pcfg->process_directive (ace_svc_desc_TAO_CORBALOC_Parser);
00533     pcfg->process_directive (ace_svc_desc_TAO_FILE_Parser);
00534     pcfg->process_directive (ace_svc_desc_TAO_DLL_Parser);
00535     pcfg->process_directive (ace_svc_desc_TAO_Default_Stub_Factory);
00536     pcfg->process_directive (
00537       ace_svc_desc_TAO_Default_Endpoint_Selector_Factory);
00538     pcfg->process_directive (ace_svc_desc_TAO_Default_Protocols_Hooks);
00539     pcfg->process_directive (
00540       ace_svc_desc_TAO_Default_Thread_Lane_Resources_Manager_Factory);
00541     pcfg->process_directive (ace_svc_desc_TAO_Default_Collocation_Resolver);
00542 
00543   } /* register_global_services_i */
00544 
00545   void
00546   register_additional_services_i (ACE_Service_Gestalt * pcfg)
00547   {
00548     // @@ What the heck do these things do and do we need to avoid
00549     //    calling them if we're not invoking the svc.conf file?
00550     // @@ They are needed for platforms that have no file system,
00551     //    like VxWorks.
00552 
00553     if (resource_factory_args != 0)
00554       {
00555         pcfg->process_directive(
00556           ACE_TEXT_CHAR_TO_TCHAR (resource_factory_args));
00557       }
00558 
00559     if (client_strategy_factory_args != 0)
00560       {
00561         pcfg->process_directive
00562           (ACE_TEXT_CHAR_TO_TCHAR (client_strategy_factory_args));
00563       }
00564 
00565     if (server_strategy_factory_args != 0)
00566       {
00567         pcfg->process_directive
00568           (ACE_TEXT_CHAR_TO_TCHAR (server_strategy_factory_args));
00569       }
00570 
00571     // If available, allow the Adapter Factory to setup.
00572     ACE_Service_Object *adapter_factory =
00573       ACE_Dynamic_Service<ACE_Service_Object>::instance (
00574         pcfg,
00575         TAO_ORB_Core::poa_factory_name ().c_str ());
00576 
00577     if (adapter_factory != 0)
00578       {
00579         adapter_factory->init (0, 0);
00580       }
00581 
00582     ACE_Service_Object * const pi_server_loader =
00583       ACE_Dynamic_Service<ACE_Service_Object>::instance (
00584         pcfg,
00585         "PI_Server_Loader");
00586 
00587     if (pi_server_loader != 0)
00588       {
00589         pi_server_loader->init (0, 0);
00590       }
00591 
00592     ACE_Service_Object * const bidir_loader =
00593       ACE_Dynamic_Service<ACE_Service_Object>::instance (
00594         pcfg,
00595         "BiDirGIOP_Loader");
00596 
00597     if (bidir_loader != 0)
00598       {
00599         bidir_loader->init (0, 0);
00600       }
00601 
00602     ACE_Service_Object * const messaging_loader =
00603       ACE_Dynamic_Service<ACE_Service_Object>::instance (
00604         pcfg,
00605         "Messaging_Loader");
00606 
00607     if (messaging_loader != 0)
00608       {
00609         messaging_loader->init (0, 0);
00610       }
00611 
00612     // Handle RTCORBA library special case.  Since RTCORBA needs
00613     // its init method call to register several hooks, call it
00614     // here if it hasn't already been called.
00615     ACE_Service_Object * const rt_loader =
00616       ACE_Dynamic_Service<ACE_Service_Object>::instance (
00617         pcfg,
00618         "RT_ORB_Loader");
00619 
00620     if (rt_loader != 0)
00621       {
00622         rt_loader->init (0, 0);
00623       }
00624 
00625     ACE_Service_Object * const rtscheduler_loader =
00626       ACE_Dynamic_Service<ACE_Service_Object>::instance (
00627         pcfg,
00628         "RTScheduler_Loader");
00629 
00630     if (rtscheduler_loader != 0)
00631       {
00632         rtscheduler_loader->init (0, 0);
00633       }
00634 
00635   } /* register_additional_services_i */
00636 
00637   int
00638   parse_svcconf_args_i (int &argc,
00639                         char **argv,
00640                         CORBA::StringSeq &svc_config_argv)
00641   {
00642     // Extract the Service Configurator ORB options from the argument
00643     // vector.
00644     ACE_Arg_Shifter arg_shifter (argc, argv);
00645     CORBA::ULong len = 0;
00646 
00647     while (arg_shifter.is_anything_left ())
00648       {
00649         const ACE_TCHAR *current_arg =
00650           arg_shifter.get_the_parameter (ACE_TEXT ("-ORBSvcConf"));
00651 
00652         if (0 != current_arg)
00653           {
00654             // Specify the name of the svc.conf file to be used.
00655 
00656             // Proceeds only if the configuration file exists.
00657             FILE * const conf_file =
00658               ACE_OS::fopen (current_arg, ACE_TEXT ("r"));
00659 
00660             if (0 == conf_file)
00661               {
00662                 // Assigning EINVAL to errno to make an exception
00663                 // thrown.  calling code does not throw an exception if
00664                 // the errno is set to ENOENT for some reason.
00665                 errno = EINVAL;
00666 
00667                 ACE_ERROR_RETURN ((LM_ERROR,
00668                                    ACE_TEXT ("TAO (%P|%t) Service ")
00669                                    ACE_TEXT ("Configurator ")
00670                                    ACE_TEXT ("unable to open file %s\n"),
00671                                    current_arg),
00672                                   -1);
00673               }
00674             else
00675               {
00676                 ACE_OS::fclose (conf_file);
00677               }
00678 
00679             len = svc_config_argv.length ();
00680             svc_config_argv.length (len + 2);  // 2 arguments to add
00681 
00682             svc_config_argv[len] = CORBA::string_dup ("-f");
00683             svc_config_argv[len + 1] =
00684               CORBA::string_dup (ACE_TEXT_ALWAYS_CHAR (current_arg));
00685 
00686             arg_shifter.consume_arg ();
00687           }
00688         // Can't interpret this argument.  Move on to the next argument.
00689         else
00690           {
00691             // Any arguments that don't match are ignored so that the
00692             // caller can still use them.
00693             arg_shifter.ignore_arg ();
00694           }
00695       }
00696 
00697     return 0;
00698   } /* parse_svcconf_args_i */
00699 
00700   int
00701   parse_private_args_i (int &argc,
00702                         char **argv,
00703                         CORBA::StringSeq &svc_config_argv,
00704                         bool & skip_service_config_open)
00705   {
00706     // Extract the Service Configurator ORB options from the argument
00707     // vector.
00708     ACE_Arg_Shifter arg_shifter (argc, argv);
00709     CORBA::ULong len = 0;
00710 
00711     while (arg_shifter.is_anything_left ())
00712       {
00713         const ACE_TCHAR *current_arg = 0;
00714         int result =
00715           arg_shifter.cur_arg_strncasecmp (
00716             ACE_TEXT ("-ORBSkipServiceConfigOpen"));
00717 
00718         if (0 == result)  // Start with the parameterless flags.
00719           {
00720             skip_service_config_open = true;
00721 
00722             arg_shifter.consume_arg ();
00723           }
00724         else  // Continue with flags that accept parameters.
00725           {
00726             current_arg =
00727               arg_shifter.get_the_parameter (
00728                 ACE_TEXT ("-ORBSvcConfDirective"));
00729 
00730             if (0 != current_arg)
00731               {
00732                 len = svc_config_argv.length ();
00733                 svc_config_argv.length (len + 2);  // 2 arguments to add
00734 
00735                 // This is used to pass arguments to the Service
00736                 // Configurator using the "command line" to provide
00737                 // configuration information rather than using a svc.conf
00738                 // file.  Pass the "-S" to the service configurator.
00739                 svc_config_argv[len] = CORBA::string_dup ("-S");
00740                 svc_config_argv[len + 1] =
00741                   CORBA::string_dup (ACE_TEXT_ALWAYS_CHAR (current_arg));
00742 
00743                 arg_shifter.consume_arg ();
00744               }
00745             else
00746               {
00747                 current_arg =
00748                   arg_shifter.get_the_parameter (
00749                     ACE_TEXT ("-ORBServiceConfigLoggerKey"));
00750 
00751                 if (0 != current_arg)
00752                   {
00753                     len = svc_config_argv.length ();
00754                     svc_config_argv.length (len + 2);  // 2 arguments to add
00755 
00756                     svc_config_argv[len] = CORBA::string_dup ("-k");
00757                     svc_config_argv[len + 1] =
00758                       CORBA::string_dup (ACE_TEXT_ALWAYS_CHAR (current_arg));
00759 
00760                     arg_shifter.consume_arg ();
00761                   }
00762                 // Can't interpret this argument.
00763                 // Move on to the next argument.
00764                 else
00765                   {
00766                     // Any arguments that don't match are ignored so that
00767                     // the caller can still use them.
00768                     arg_shifter.ignore_arg ();
00769                   }
00770               }
00771           }
00772       }
00773 
00774     return 0;
00775   } /* parse_private_args_i */
00776 
00777   int
00778   parse_global_args_i (int &argc,
00779                        char **argv,
00780                        CORBA::StringSeq &svc_config_argv,
00781                        bool apply_values)
00782   {
00783     // NOTE: When adding new global arguments, ensure they are only
00784     // applied when apply_values is true, but that they are always
00785     // consumed, if they need to be consumed.
00786 #if defined (TAO_DEBUG) && !defined (ACE_HAS_WINCE)
00787     // Make it a little easier to debug programs using this code.
00788     if (apply_values)
00789       {
00790         TAO_debug_level = ACE_Env_Value<u_int> ("TAO_ORB_DEBUG", 0);
00791 
00792         char * const value = ACE_OS::getenv ("TAO_ORB_DEBUG");
00793 
00794         if (value != 0)
00795           {
00796             TAO_debug_level = ACE_OS::atoi (value);
00797 
00798             if (TAO_debug_level <= 0)
00799               {
00800                 TAO_debug_level = 1;
00801               }
00802 
00803             ACE_DEBUG ((LM_DEBUG,
00804                         ACE_TEXT ("TAO_debug_level == %d\n"),
00805                         TAO_debug_level));
00806           }
00807       }
00808 #endif  /* TAO_DEBUG && !ACE_HAS_WINCE */
00809 
00810 
00811     // Extract the Service Configurator ORB options from the argument
00812     // vector.
00813     ACE_Arg_Shifter arg_shifter (argc, argv);
00814     CORBA::ULong len = 0;
00815 
00816     while (arg_shifter.is_anything_left ())
00817       {
00818         const ACE_TCHAR *current_arg = 0;
00819         int strcmp_result =
00820           arg_shifter.cur_arg_strncasecmp (ACE_TEXT ("-ORBDebug"));
00821 
00822         if (0 == strcmp_result)
00823           {
00824             if (apply_values)
00825               {
00826                 // Later, replace all of these
00827                 // warning this turns on a daemon.
00828                 ACE::debug (1);
00829               }
00830 
00831             arg_shifter.consume_arg ();
00832           }
00833         else
00834           {
00835             current_arg =
00836               arg_shifter.get_the_parameter (
00837                 ACE_TEXT ("-ORBNegotiateCodesets"));
00838 
00839             if (0 != current_arg)
00840               {
00841                 if (apply_values)
00842                   {
00843                     // Don't consume, the ORB_Core::init will use it again.
00844                     negotiate_codesets = (ACE_OS::atoi (current_arg));
00845                   }
00846               }
00847             else
00848               {
00849                 current_arg =
00850                   arg_shifter.get_the_parameter (
00851                     ACE_TEXT ("-ORBDebugLevel"));
00852 
00853                 if (0 != current_arg)
00854                   {
00855                     if (apply_values)
00856                       {
00857                         TAO_debug_level =
00858                           ACE_OS::atoi (current_arg);
00859                       }
00860 
00861                     arg_shifter.consume_arg ();
00862                   }
00863                 else
00864                   {
00865                     strcmp_result =
00866                       arg_shifter.cur_arg_strncasecmp (
00867                         ACE_TEXT ("-ORBDaemon"));
00868 
00869                     if (0 == strcmp_result)
00870                       {
00871                         // Be a daemon.
00872                         if (apply_values)
00873                           {
00874                             len = svc_config_argv.length ();
00875                             svc_config_argv.length (len + 1);
00876 
00877                             svc_config_argv[len] =
00878                               CORBA::string_dup ("-b");
00879                           }
00880 
00881                         arg_shifter.consume_arg ();
00882                       }
00883                     // Can't interpret this argument.
00884                     // Move on to the next argument.
00885                     else
00886                       {
00887                         // Any arguments that don't match are ignored so
00888                         // that the caller can still use them.
00889                         arg_shifter.ignore_arg ();
00890                       }
00891                   }
00892               }
00893           }
00894       }
00895 
00896     return 0;
00897   } /* parse_global_args_i */
00898 } // anonymous namespace.

Generated on Thu Nov 9 11:54:23 2006 for TAO by doxygen 1.3.6