// $Id$ #include "ace/Service_Config.h" #include "ace/Service_Repository.h" #include "ace/Object_Manager.h" #include "ace/ARGV.h" #include "ace/Arg_Shifter.h" #include "TAO_Internal.h" #include "default_server.h" #include "default_client.h" #include "default_resource.h" #include "IIOP_Factory.h" #include "CORBANAME_Parser.h" #include "CORBALOC_Parser.h" #include "FILE_Parser.h" #include "DLL_Parser.h" #include "Object_Loader.h" ACE_RCSID(tao, TAO_Internal, "$Id$") int TAO_Internal::service_open_count_ = 0; #if defined (TAO_PLATFORM_SVC_CONF_FILE_NOTSUP) const char *TAO_Internal::resource_factory_args_ = TAO_DEFAULT_RESOURCE_FACTORY_ARGS; const char *TAO_Internal::server_strategy_args_ = TAO_DEFAULT_SERVER_STRATEGY_FACTORY_ARGS; const char *TAO_Internal::client_strategy_args_ = TAO_DEFAULT_CLIENT_STRATEGY_FACTORY_ARGS; #else const char *TAO_Internal::resource_factory_args_ = 0; const char *TAO_Internal::server_strategy_args_ = 0; const char *TAO_Internal::client_strategy_args_ = 0; #endif /* TAO_PLATFORM_SVC_CONF_FILE_NOTSUP */ int TAO_Internal::open_services (int &argc, char **argv) { // Construct an argument vector specific to the Service // Configurator. ACE_ARGV svc_config_argv; // Be certain to copy the program name so that service configurator // has something to skip! const char *argv0 = ""; if (argc > 0 && argv != 0) argv0 = argv[0]; svc_config_argv.add (argv0); // Should we skip the method, e.g., if we // already being configured by the ACE Service Configurator. int skip_service_config_open = 0; // Extract the Service Configurator ORB options from the argument // vector. ACE_Arg_Shifter arg_shifter (argc, argv); while (arg_shifter.is_anything_left ()) { char *current_arg = 0; // Start with the parameterless flags. if (arg_shifter.cur_arg_strncasecmp ("-ORBSkipServiceConfigOpen") == 0) { skip_service_config_open = 1; arg_shifter.consume_arg (); } else if (arg_shifter.cur_arg_strncasecmp ("-ORBDaemon") == 0) { // Be a daemon svc_config_argv.add ("-b"); arg_shifter.consume_arg (); } // Continue with flags that accept parameters. else if ((current_arg = arg_shifter.get_the_parameter ("-ORBSvcConfDirective"))) { // This is used to pass arguments to the Service // Configurator using the "command line" to provide // configuration information rather than using a svc.conf // file. Pass the "-S" to the service configurator. svc_config_argv.add ("-S"); svc_config_argv.add (current_arg); arg_shifter.consume_arg (); } else if ((current_arg = arg_shifter.get_the_parameter ("-ORBSvcConf"))) { // Specify the name of the svc.conf file to be used. // Proceeds only if the configuration file exists. FILE* conf_file; if ((conf_file = ACE_OS::fopen (current_arg, "r")) == 0) { // Assigning EINVAL to errno to make an exception thrown. // calling code does not throw an exception if the errno // is set to ENOENT for some reason. errno = EINVAL; ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("TAO (%P|%t) Service Configurator ") ACE_TEXT ("unable to open file %s\n"), current_arg), -1); } else { ACE_OS::fclose (conf_file); } svc_config_argv.add ("-f"); svc_config_argv.add (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 // caller can still use them. arg_shifter.ignore_arg (); } int svc_config_argc = svc_config_argv.argc (); return TAO_Internal::open_services_i (svc_config_argc, svc_config_argv.argv (), 0, // @@ What about this argument? skip_service_config_open); } void TAO_Internal::default_svc_conf_entries (const char *resource_factory_args, const char *server_strategy_args, const char *client_strategy_args) { TAO_Internal::resource_factory_args_ = resource_factory_args; TAO_Internal::server_strategy_args_ = server_strategy_args; TAO_Internal::client_strategy_args_ = client_strategy_args; } int TAO_Internal::open_services_i (int &argc, char **argv, int ignore_default_svc_conf_file, int skip_service_config_open) { ACE_MT (ACE_GUARD_RETURN (TAO_SYNCH_RECURSIVE_MUTEX, guard, *ACE_Static_Object_Lock::instance (), -1)); #if defined (TAO_PLATFORM_SVC_CONF_FILE_NOTSUP) ignore_default_svc_conf_file = 1; #endif /* TAO_PLATFORM_SVC_CONF_FILE_NOTSUP */ if (TAO_Internal::service_open_count_++ == 0) { ACE_Service_Config::static_svcs ()-> insert (&ace_svc_desc_TAO_Default_Resource_Factory); ACE_Service_Config::static_svcs ()-> insert (&ace_svc_desc_TAO_Default_Client_Strategy_Factory); ACE_Service_Config::static_svcs ()-> insert (&ace_svc_desc_TAO_Default_Server_Strategy_Factory); // Configure the IIOP factory. You do *NOT* // need modify this code to add your own protocol, instead // simply add the following to your svc.conf file: // // dynamic PN_Factory Service_Object * LIB:_make_PN_Protocol_Factory() "" // static Resource_Factory "-ORBProtocolFactory PN_Factory" // // where PN is the name of your protocol and LIB is the base // name of the shared library that implements the protocol. ACE_Service_Config::static_svcs ()-> insert (&ace_svc_desc_TAO_IIOP_Protocol_Factory); // add descriptor to list of static objects. ACE_Service_Config::static_svcs ()-> insert (&ace_svc_desc_TAO_CORBANAME_Parser); ACE_Service_Config::static_svcs ()-> insert (&ace_svc_desc_TAO_CORBALOC_Parser); ACE_Service_Config::static_svcs ()-> insert (&ace_svc_desc_TAO_FILE_Parser); ACE_Service_Config::static_svcs ()-> insert (&ace_svc_desc_TAO_DLL_Parser); int result = 0; if (skip_service_config_open == 0) result = ACE_Service_Config::open (argc, argv, ACE_DEFAULT_LOGGER_KEY, 0, // Don't ignore static services. ignore_default_svc_conf_file); // @@ What the heck do these things do and do we need to avoid // calling them if we're not invoking the svc.conf file? if (TAO_Internal::resource_factory_args_ != 0) ACE_Service_Config::process_directive (TAO_Internal::resource_factory_args_); if (TAO_Internal::client_strategy_args_ != 0) ACE_Service_Config::process_directive (TAO_Internal::client_strategy_args_); if (TAO_Internal::server_strategy_args_ != 0) ACE_Service_Config::process_directive (TAO_Internal::server_strategy_args_); return result; } else return 0; } TAO_Internal::TAO_Internal (void) { } int TAO_Internal::close_services (void) { ACE_MT (ACE_GUARD_RETURN (TAO_SYNCH_RECURSIVE_MUTEX, guard, *ACE_Static_Object_Lock::instance (), -1)); --service_open_count_; return 0; }