diff options
author | iliyan <iliyan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2008-04-08 12:16:13 +0000 |
---|---|---|
committer | iliyan <iliyan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2008-04-08 12:16:13 +0000 |
commit | 1243661f99c8dc2e36bbc1c414347481d5b8eb87 (patch) | |
tree | 3fbecd54f322e40a0683c9bad740a26b651ce19e /TAO/tao/TAO_Internal.cpp | |
parent | c13095fddb25b40243bb22f694834c3bd0820d03 (diff) | |
download | ATCD-1243661f99c8dc2e36bbc1c414347481d5b8eb87.tar.gz |
ChangeLogTag: Tue Apr 8 12:04:20 UTC 2008 Iliyan Jeliazkov <iliyan@ociweb.com>
Diffstat (limited to 'TAO/tao/TAO_Internal.cpp')
-rw-r--r-- | TAO/tao/TAO_Internal.cpp | 322 |
1 files changed, 178 insertions, 144 deletions
diff --git a/TAO/tao/TAO_Internal.cpp b/TAO/tao/TAO_Internal.cpp index be875638eb8..e9d705e3bb7 100644 --- a/TAO/tao/TAO_Internal.cpp +++ b/TAO/tao/TAO_Internal.cpp @@ -26,6 +26,7 @@ #include "ace/Dynamic_Service.h" #include "ace/Arg_Shifter.h" #include "ace/Argv_Type_Converter.h" +#include "ace/ARGV.h" #include "ace/Env_Value_T.h" #include "ace/ACE.h" #include "ace/OS_NS_stdio.h" @@ -123,13 +124,13 @@ namespace * Initialize ORB-local (private) ACE Service Configurator * repository. * - * @return @c 0 if successful, @c -1 with @c errno set if failure. - * - */ - int open_private_services_i (ACE_Service_Gestalt* pcfg, - int & argc, - char ** argv, - bool skip_service_config_open = false, + * @return @c 0 if successful, @c -1 with @c errno set if failure. + * + */ + int open_private_services_i (ACE_Service_Gestalt_Auto_Ptr pcfg, + int & argc, + char ** argv, + bool skip_service_config_open = false, bool ignore_default_svc_conf_file = false); /** @@ -185,16 +186,159 @@ public: { } -private: - /// The mutex, associated with the condition. Do not use the ACE - /// global mutex, because it causes deadlocks with other thrads that - /// may be in DLL_Manager::open() - ACE_Recursive_Thread_Mutex mutex_; -}; -#endif // ACE_HAS_THREADS + + private: + /// The mutex, associated with the condition. Do not use the ACE + /// global mutex, because it causes deadlocks with other threads that + /// may be in DLL_Manager::open() + ACE_Recursive_Thread_Mutex mutex_; + }; + #endif // ACE_HAS_THREADS + + + + + // **************************************************************** + /// Note that the argument vector will be corrupted upon return + int + TAO::ORB::open_global_services (int argc, + char **argv) + { + { + // Count of the number of (times we did this for all) ORBs. + static int orb_init_count = 0; + + // Using ACE_Static_Object_Lock::instance() precludes ORB_init() + // from being called within a static object CTOR. + ACE_MT (ACE_GUARD_RETURN (TAO_SYNCH_RECURSIVE_MUTEX, + guard, + *ACE_Static_Object_Lock::instance (), + -1)); + + // Make sure TAO's singleton manager is initialized. + // We need to initialize before TAO_default_environment() is called + // since that call instantiates a TAO_TSS_Singleton. + if (TAO_Singleton_Manager::instance ()->init () == -1) + return -1; + + // Prevent multiple initializations. + if (++orb_init_count > 1) + return 0; + + } + + // Prevent any other thread from going through ORB initialization before the + // uber-gestalt is initialized. + ACE_MT (ACE_GUARD_RETURN (TAO_SYNCH_RECURSIVE_MUTEX, + guard, + TAO_Ubergestalt_Ready_Condition::instance ()->mutex (), + -1)); + + if (TAO_debug_level > 2) + { + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("TAO (%P|%t) Initializing the ") + ACE_TEXT ("process-wide service context\n"))); + } + + ACE_Service_Gestalt* theone = ACE_Service_Config::global (); + ACE_Service_Config_Guard auto_config_guard (theone); + + register_global_services_i (theone); + + // Be certain to copy the program name so that service configurator + // has something to skip! + ACE_CString argv0 ((argc <= 0 || argv == 0) ? "" : ACE_TEXT_ALWAYS_CHAR (argv[0])); + + // Construct an argument vector specific to the process-wide + // (global) Service Configurator instance. + CORBA::StringSeq global_svc_config_argv; + global_svc_config_argv.length (1); + global_svc_config_argv[0] = argv0.c_str (); + + // Will expand the environment variables, if any were used. Is this a good thing? + // I guess it provides greater flexibility for deployment, so let's leave it. Will + // also quote arguments. + ACE_ARGV copyargv (argc, argv, true, true); + + // Adjust to proper TCHAR type + int tmpargc = argc; + ACE_Argv_Type_Converter cvtargv (tmpargc, copyargv.argv()); + + tmpargc = cvtargv.get_argc (); + ACE_TCHAR **tmpargv = cvtargv.get_TCHAR_argv (); + + // Collect global SC parameters. True means "immediately + // apply global setting" like debug flag, etc. + if (parse_global_args_i (tmpargc, + tmpargv, + global_svc_config_argv, + true) == -1) + return -1; + + bool skip_service_config_open = false; // by default we shouldn't + + if (parse_svcconf_args_i (tmpargc, + tmpargv, + global_svc_config_argv) == -1) + return -1; + + if (parse_private_args_i (tmpargc, + tmpargv, + global_svc_config_argv, + skip_service_config_open) == -1) + return -1; + + // Perform the open magic (unless SC::open() has been called already) + int global_svc_config_argc = global_svc_config_argv.length (); + int status = open_private_services_i (theone, + global_svc_config_argc, + global_svc_config_argv.get_buffer (), + skip_service_config_open); + + // okay? + if (status == -1) + { + if (TAO_debug_level > 0) + { + ACE_ERROR ((LM_DEBUG, + ACE_TEXT ("TAO (%P|%t) Failed to open process-") + ACE_TEXT ("wide service configuration context\n"))); + } + + return -1; + } + + if (TAO_debug_level > 2) + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("TAO (%P|%t) Completed initializing the ") + ACE_TEXT ("process-wide service context\n"))); + + if (TAO_debug_level > 4) + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("TAO (%P|%t) Default ORB services initialization begins\n"))); + + // Load more ORB-related services + register_additional_services_i (theone); + + if (TAO_debug_level > 4) + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("TAO (%P|%t) Default ORB services initialization completed\n"))); + + // Notify all other threads that may be waiting, that the global + // gestalt has been initialized. + is_ubergestalt_ready = true; + ACE_MT (if (TAO_Ubergestalt_Ready_Condition::instance ()-> + broadcast () == -1) + return -1); + + return 0; +} + + int -TAO::ORB::open_services (ACE_Service_Gestalt* pcfg, +TAO::ORB::open_services (ACE_Intrusive_Auto_Ptr<ACE_Service_Gestalt> pcfg, int &argc, ACE_TCHAR **argv) { @@ -242,13 +386,7 @@ TAO::ORB::open_services (ACE_Service_Gestalt* pcfg, // Be certain to copy the program name so that service configurator // has something to skip! - ACE_CString argv0 (""); - - if (argc > 0 && argv != 0) - { - argv0 = ACE_TEXT_ALWAYS_CHAR (argv[0]); - } - + ACE_CString argv0 ((argc <= 0 || argv == 0) ? "" : ACE_TEXT_ALWAYS_CHAR (argv[0])); svc_config_argv.length (1); svc_config_argv[0] = argv0.c_str (); @@ -273,122 +411,26 @@ TAO::ORB::open_services (ACE_Service_Gestalt* pcfg, // Construct an argument vector specific to the process-wide // (global) Service Configurator instance. CORBA::StringSeq global_svc_config_argv; + // Parse any globally applicable arguments, but do not make them effective. We are effectively purging the command line from them without affecting the global state - after all, it may be a private (local) configuration context. + int status = + parse_global_args_i(argc, argv, global_svc_config_argv, false); - ACE_Service_Gestalt * theone = ACE_Service_Config::global (); - - if (service_open_count == 1) - { - ACE_Service_Config_Guard config_guard (theone); - - if (TAO_debug_level > 2) - { - ACE_DEBUG ((LM_DEBUG, - ACE_TEXT ("TAO (%P|%t) Initializing the ") - ACE_TEXT ("process-wide services\n"))); - } - - register_global_services_i (theone); - - // Be certain to copy the program name so that service configurator - // has something to skip! - ACE_CString gargv0 (""); - - if (argc > 0 && argv != 0) - { - gargv0 = ACE_TEXT_ALWAYS_CHAR (argv[0]); - } - - global_svc_config_argv.length (1); - global_svc_config_argv[0] = gargv0.c_str (); - - if (parse_global_args_i (argc, argv, global_svc_config_argv, true) == -1) - { - return -1; - } - - if (parse_svcconf_args_i (argc, argv, global_svc_config_argv) == -1) - { - return -1; - } - - // If the target configuration happens to be the global context, - // add any 'private' arguments here. - if (pcfg == theone && svc_config_argv.length() > 1) - { - CORBA::ULong glen = global_svc_config_argv.length(); - global_svc_config_argv.length(glen + svc_config_argv.length() - 1); - for (CORBA::ULong i = 1; i < svc_config_argv.length(); i++) - global_svc_config_argv[glen++] = svc_config_argv[i]; - svc_config_argv.length(1); - } - - int global_svc_config_argc = global_svc_config_argv.length (); - int status = - open_private_services_i (theone, - global_svc_config_argc, - global_svc_config_argv.get_buffer (), - skip_service_config_open); - - if (status == -1) - { - if (TAO_debug_level > 0) - { - ACE_ERROR ((LM_DEBUG, - ACE_TEXT ("TAO (%P|%t) Failed to open process-") - ACE_TEXT ("wide service configuration\n"))); - } - - return -1; - } - - register_additional_services_i (theone); - - if (TAO_debug_level > 4) - ACE_DEBUG ((LM_DEBUG, - ACE_TEXT ("TAO (%P|%t) Default ORB - global ") - ACE_TEXT ("initialization completed.\n"))); - - // Notify all other threads that may be waiting, that the global - // gestalt has been initialized. - { - ACE_MT (ACE_GUARD_RETURN (TAO_SYNCH_RECURSIVE_MUTEX, - guard, - TAO_Ubergestalt_Ready_Condition::instance ()->mutex (), - -1)); - - is_ubergestalt_ready = true; - ACE_MT (if (TAO_Ubergestalt_Ready_Condition::instance ()-> - broadcast () == -1) - return -1); - } - - } - else - { - int status = - parse_global_args_i(argc, argv,global_svc_config_argv, false); - if (status == -1 && TAO_debug_level > 0) + if (status == -1 && TAO_debug_level > 0) ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("TAO (%P|%t) Skipping the process-wide ") ACE_TEXT ("service configuration, service_open_count ") ACE_TEXT ("= %d, status = %d\n"), service_open_count, status)); - } if (TAO_debug_level > 2) - { ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("TAO (%P|%t) Initializing the ") ACE_TEXT ("orb-specific services\n"))); - } if (parse_svcconf_args_i (argc, argv, svc_config_argv) == -1) - { return -1; - } - - int status = 0; + // Not a big deal to call open_private_services_i() again (if it was the global one). The SG::open() would not run if it has already been executed. // only open the private context if it is not also the global context if (pcfg != ACE_Service_Config::global()) { @@ -400,12 +442,7 @@ TAO::ORB::open_services (ACE_Service_Gestalt* pcfg, skip_service_config_open); } - if (status >= 0) - { - return 0; - } - - if (TAO_debug_level > 0) + if (status < 0 && TAO_debug_level > 0) { ACE_ERROR_RETURN ((LM_DEBUG, ACE_TEXT ("TAO (%P|%t) Failed to ") @@ -413,11 +450,11 @@ TAO::ORB::open_services (ACE_Service_Gestalt* pcfg, -1); } - return -1; + return status; } int -TAO::ORB::close_services (ACE_Service_Gestalt* pcfg) +TAO::ORB::close_services (ACE_Service_Gestalt_Auto_Ptr pcfg) { ACE_MT (ACE_GUARD_RETURN (TAO_SYNCH_RECURSIVE_MUTEX, guard, @@ -427,6 +464,7 @@ TAO::ORB::close_services (ACE_Service_Gestalt* pcfg) if (pcfg == ACE_Service_Config::global()) return 0; + return pcfg->close (); } @@ -448,7 +486,7 @@ namespace /// Open services, belonging to the gestalt instance. int - open_private_services_i (ACE_Service_Gestalt * pcfg, + open_private_services_i (ACE_Service_Gestalt_Auto_Ptr pcfg, int & argc, char ** argv, bool skip_service_config_open, @@ -691,19 +729,19 @@ namespace ACE_Arg_Shifter arg_shifter (argc, argv); CORBA::ULong len = 0; + while (arg_shifter.is_anything_left ()) { - const ACE_TCHAR *current_arg = - arg_shifter.get_the_parameter (ACE_TEXT ("-ORBSvcConf")); - - if (0 != current_arg) + // Can't interpret this argument. Move on to the next argument. + if (arg_shifter.cur_arg_strncasecmp (ACE_TEXT ("-ORBSvcConf")) == 0) { - // Specify the name of the svc.conf file to be used. + const ACE_TCHAR *current_arg = + arg_shifter.get_the_parameter (ACE_TEXT ("-ORBSvcConf")); + arg_shifter.consume_arg (); // Proceeds only if the configuration file exists. FILE * const conf_file = ACE_OS::fopen (current_arg, ACE_TEXT ("r")); - if (0 == conf_file) { // Assigning EINVAL to errno to make an exception @@ -712,9 +750,8 @@ namespace errno = EINVAL; ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("TAO (%P|%t) Service ") - ACE_TEXT ("Configurator ") - ACE_TEXT ("unable to open file %s\n"), + ACE_TEXT ("TAO (%P|%t) Unable to open file %s") + ACE_TEXT (", referenced by -ORBSvcConf option\n"), current_arg), -1); } @@ -729,10 +766,7 @@ namespace svc_config_argv[len] = CORBA::string_dup ("-f"); svc_config_argv[len + 1] = CORBA::string_dup (ACE_TEXT_ALWAYS_CHAR (current_arg)); - - arg_shifter.consume_arg (); } - // Can't interpret this argument. Move on to the next argument. else { // Any arguments that don't match are ignored so that the |