summaryrefslogtreecommitdiff
path: root/TAO/tao/TAO_Internal.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'TAO/tao/TAO_Internal.cpp')
-rw-r--r--TAO/tao/TAO_Internal.cpp407
1 files changed, 206 insertions, 201 deletions
diff --git a/TAO/tao/TAO_Internal.cpp b/TAO/tao/TAO_Internal.cpp
index 3fc4a4652db..c1e6ffe1497 100644
--- a/TAO/tao/TAO_Internal.cpp
+++ b/TAO/tao/TAO_Internal.cpp
@@ -11,6 +11,7 @@
#include "FILE_Parser.h"
#include "DLL_Parser.h"
#include "ORB_Core.h"
+#include "Adapter_Factory.h"
#include "Default_Stub_Factory.h"
#include "Default_Endpoint_Selector_Factory.h"
#include "Default_Protocols_Hooks.h"
@@ -24,7 +25,7 @@
#include "ace/Argv_Type_Converter.h"
#include "ace/Env_Value_T.h"
#include "ace/ACE.h"
-#include "ace/Static_Object_Lock.h"
+#include "ace/Atomic_Op.h"
#include "ace/OS_NS_stdio.h"
@@ -33,37 +34,62 @@ ACE_RCSID (tao,
"$Id$")
-#if defined (TAO_PLATFORM_SVC_CONF_FILE_NOTSUP) && \
- defined (TAO_DEFAULT_RESOURCE_FACTORY_ARGS)
-const char *TAO_Internal::resource_factory_args_ =
- TAO_DEFAULT_RESOURCE_FACTORY_ARGS;
-#else
-const char *TAO_Internal::resource_factory_args_ = 0;
-#endif /* TAO_PLATFORM_SVC_CONF_FILE_NOTSUP &&
- TAO_DEFAULT_RESOURCE_FACTORY_ARGS */
-
-#if defined (TAO_PLATFORM_SVC_CONF_FILE_NOTSUP) && \
- defined (TAO_DEFAULT_SERVER_STRATEGY_FACTORY_ARGS)
-const char *TAO_Internal::server_strategy_factory_args_ =
- TAO_DEFAULT_SERVER_STRATEGY_FACTORY_ARGS;
-#else
-const char *TAO_Internal::server_strategy_factory_args_ = 0;
-#endif /* TAO_PLATFORM_SVC_CONF_FILE_NOTSUP &&
- TAO_DEFAULT_SERVER_STRATEGY_FACTORY_ARGS */
-
-#if defined (TAO_PLATFORM_SVC_CONF_FILE_NOTSUP) && \
- defined (TAO_DEFAULT_CLIENT_STRATEGY_FACTORY_ARGS)
-const char *TAO_Internal::client_strategy_factory_args_ =
- TAO_DEFAULT_CLIENT_STRATEGY_FACTORY_ARGS;
-#else
-const char *TAO_Internal::client_strategy_factory_args_ = 0;
-#endif /* TAO_PLATFORM_SVC_CONF_FILE_NOTSUP &&
- TAO_DEFAULT_CLIENT_STRATEGY_FACTORY_ARGS */
-
-int TAO_Internal::service_open_count_ = 0;
+#ifndef TAO_DEFAULT_RESOURCE_FACTORY_ARGS
+# define TAO_DEFAULT_RESOURCE_FACTORY_ARGS 0
+#endif /* !TAO_DEFAULT_RESOURCE_FACTORY_ARGS */
+
+#ifndef TAO_DEFAULT_SERVER_STRATEGY_FACTORY_ARGS
+# define TAO_DEFAULT_SERVER_STRATEGY_FACTORY_ARGS 0
+#endif /* !TAO_DEFAULT_SERVER_STRATEGY_FACTORY_ARGS */
+
+#ifndef TAO_DEFAULT_CLIENT_STRATEGY_FACTORY_ARGS
+# define TAO_DEFAULT_CLIENT_STRATEGY_FACTORY_ARGS 0
+#endif /* !TAO_DEFAULT_RESOURCE_FACTORY_ARGS */
+
+
+namespace
+{
+ /**
+ * Initialize the ACE Service Configurator. This is a one-shot
+ * method, i.e., it can be called multiple times but it will only do
+ * its work once. It does, however, track the number of times it's
+ * called (see @c open_services()). It is fully thread-safe.
+ *
+ * @return @c 0 if successful, @c -1 with @c errno set if failure.
+ *
+ * @note You can provide your program a set of default `svc.conf'
+ * entries by setting @a ignore_default_svc_conf_file to
+ * non-zero and use @c default_svc_conf_entries() before
+ * calling @c open_services(). In addition, you can @a
+ * skip_service_config_open altogether, which used to be
+ * important when the ORB is linked in via the
+ * ACE_Service_Configurator, since the
+ * ACE_Service_Configurator was non-reentrant. However, the
+ * ACE_Service_Configurator is now reentrant meaning that it
+ * is really no longer necessary to do so.
+ */
+ int open_services_i (int & argc,
+ char ** argv,
+ bool ignore_default_svc_conf_file = false,
+ bool skip_service_config_open = false);
+
+ /// Number of times open_services() has been called. Incremented by
+ /// open_services(), and decremented by close_services().
+ /**
+ * @note In/decrement operations are atomic.
+ */
+ ACE_Atomic_Op<TAO_SYNCH_MUTEX, long> service_open_count (0);
+
+ char const * resource_factory_args =
+ TAO_DEFAULT_RESOURCE_FACTORY_ARGS;
+ char const * server_strategy_factory_args =
+ TAO_DEFAULT_SERVER_STRATEGY_FACTORY_ARGS;
+ char const * client_strategy_factory_args =
+ TAO_DEFAULT_CLIENT_STRATEGY_FACTORY_ARGS;
+}
int
-TAO_Internal::open_services (int &argc, ACE_TCHAR **argv)
+TAO::ORB::open_services (int &argc, ACE_TCHAR **argv)
{
// Construct an argument vector specific to the Service
// Configurator.
@@ -71,27 +97,31 @@ TAO_Internal::open_services (int &argc, ACE_TCHAR **argv)
// Be certain to copy the program name so that service configurator
// has something to skip!
- ACE_CString argv0 = "";
+ ACE_CString argv0 ("");
if (argc > 0 && argv != 0)
{
- argv0 = ACE_TEXT_ALWAYS_CHAR(argv[0]);
+ argv0 = ACE_TEXT_ALWAYS_CHAR (argv[0]);
}
CORBA::ULong len = 0;
svc_config_argv.length (1);
svc_config_argv[0] = argv0.c_str ();
- // Should we skip the <ACE_Service_Config::open> method, e.g., if we
+ // Should we skip the ACE_Service_Config::open() method, e.g., if we
// already being configured by the ACE Service Configurator.
- int skip_service_config_open = 0;
+ //
+ // @@ This is no longer needed since the Service Configurator is
+ // now reentrant.
+ // -Ossama
+ bool skip_service_config_open = false;
#if defined (TAO_DEBUG) && !defined (ACE_HAS_WINCE)
// Make it a little easier to debug programs using this code.
{
TAO_debug_level = ACE_Env_Value<u_int> ("TAO_ORB_DEBUG", 0);
- char *value = ACE_OS::getenv ("TAO_ORB_DEBUG");
+ char * const value = ACE_OS::getenv ("TAO_ORB_DEBUG");
if (value != 0)
{
@@ -103,7 +133,8 @@ TAO_Internal::open_services (int &argc, ACE_TCHAR **argv)
}
ACE_DEBUG ((LM_DEBUG,
- ACE_TEXT ("TAO_debug_level == %d\n"), TAO_debug_level));
+ ACE_TEXT ("TAO_debug_level == %d\n"),
+ TAO_debug_level));
}
}
#endif /* TAO_DEBUG && !ACE_HAS_WINCE */
@@ -118,13 +149,13 @@ TAO_Internal::open_services (int &argc, ACE_TCHAR **argv)
// Start with the parameterless flags.
if (arg_shifter.cur_arg_strncasecmp
- (ACE_TEXT("-ORBSkipServiceConfigOpen")) == 0)
+ (ACE_TEXT ("-ORBSkipServiceConfigOpen")) == 0)
{
- skip_service_config_open = 1;
+ skip_service_config_open = true;
arg_shifter.consume_arg ();
}
- else if (arg_shifter.cur_arg_strncasecmp (ACE_TEXT("-ORBDebug")) == 0)
+ else if (arg_shifter.cur_arg_strncasecmp (ACE_TEXT ("-ORBDebug")) == 0)
{
// later, replace all of these
// warning this turns on a daemon
@@ -132,14 +163,14 @@ TAO_Internal::open_services (int &argc, ACE_TCHAR **argv)
arg_shifter.consume_arg ();
}
else if ((current_arg = arg_shifter.get_the_parameter
- (ACE_TEXT("-ORBDebugLevel"))))
+ (ACE_TEXT ("-ORBDebugLevel"))))
{
TAO_debug_level =
ACE_OS::atoi (current_arg);
arg_shifter.consume_arg ();
}
- else if (arg_shifter.cur_arg_strncasecmp (ACE_TEXT("-ORBDaemon")) == 0)
+ else if (arg_shifter.cur_arg_strncasecmp (ACE_TEXT ("-ORBDaemon")) == 0)
{
// Be a daemon
@@ -151,7 +182,7 @@ TAO_Internal::open_services (int &argc, ACE_TCHAR **argv)
arg_shifter.consume_arg ();
}
// Continue with flags that accept parameters.
- else if ((current_arg = arg_shifter.get_the_parameter (ACE_TEXT("-ORBSvcConfDirective"))))
+ else if ((current_arg = arg_shifter.get_the_parameter (ACE_TEXT ("-ORBSvcConfDirective"))))
{
len = svc_config_argv.length ();
svc_config_argv.length (len + 2); // 2 arguments to add
@@ -165,12 +196,12 @@ TAO_Internal::open_services (int &argc, ACE_TCHAR **argv)
arg_shifter.consume_arg ();
}
- else if ((current_arg = arg_shifter.get_the_parameter (ACE_TEXT("-ORBSvcConf"))))
+ else if ((current_arg = arg_shifter.get_the_parameter (ACE_TEXT ("-ORBSvcConf"))))
{
// Specify the name of the svc.conf file to be used.
// Proceeds only if the configuration file exists.
- FILE *conf_file = ACE_OS::fopen (current_arg, ACE_TEXT("r"));
+ FILE * const conf_file = ACE_OS::fopen (current_arg, ACE_TEXT ("r"));
if (conf_file == 0)
{
@@ -199,7 +230,7 @@ TAO_Internal::open_services (int &argc, ACE_TCHAR **argv)
arg_shifter.consume_arg();
}
- else if ((current_arg = arg_shifter.get_the_parameter (ACE_TEXT("-ORBServiceConfigLoggerKey"))))
+ else if ((current_arg = arg_shifter.get_the_parameter (ACE_TEXT ("-ORBServiceConfigLoggerKey"))))
{
len = svc_config_argv.length ();
svc_config_argv.length (len + 2); // 2 arguments to add
@@ -219,86 +250,92 @@ TAO_Internal::open_services (int &argc, ACE_TCHAR **argv)
}
int svc_config_argc = svc_config_argv.length ();
- return TAO_Internal::open_services_i (svc_config_argc,
- svc_config_argv.get_buffer (),
- 0, // @@ What about this argument?
- skip_service_config_open);
+ return open_services_i (svc_config_argc,
+ svc_config_argv.get_buffer (),
+ 0, // @@ What about this argument?
+ skip_service_config_open);
}
+int
+TAO::ORB::close_services (void)
+{
+ --service_open_count; // Atomic!
+
+ return 0;
+}
void
-TAO_Internal::default_svc_conf_entries (const char *resource_factory_args,
- const char *server_strategy_factory_args,
- const char *client_strategy_factory_args)
+TAO::ORB::default_svc_conf_entries (char const * rf_args,
+ char const * ssf_args,
+ char const * csf_args)
{
- TAO_Internal::resource_factory_args_ = resource_factory_args;
- TAO_Internal::server_strategy_factory_args_ = server_strategy_factory_args;
- TAO_Internal::client_strategy_factory_args_ = client_strategy_factory_args;
+ resource_factory_args = rf_args;
+ server_strategy_factory_args = ssf_args;
+ client_strategy_factory_args = csf_args;
}
-int
-TAO_Internal::open_services_i (int &argc,
- char **argv,
- int ignore_default_svc_conf_file,
- int skip_service_config_open)
+// -----------------------------------------------------
+namespace
{
- ACE_MT (ACE_GUARD_RETURN (TAO_SYNCH_RECURSIVE_MUTEX,
- guard, *ACE_Static_Object_Lock::instance (),
- -1));
-
+ int
+ open_services_i (int & argc,
+ char ** argv,
+ bool ignore_default_svc_conf_file,
+ bool skip_service_config_open)
+ {
#if defined (TAO_PLATFORM_SVC_CONF_FILE_NOTSUP)
- ignore_default_svc_conf_file = 1;
+ ignore_default_svc_conf_file = true;
#endif /* TAO_PLATFORM_SVC_CONF_FILE_NOTSUP */
- if (TAO_Internal::service_open_count_++ == 0)
- {
- ACE_Service_Config::process_directive (
- ace_svc_desc_TAO_Default_Resource_Factory);
- ACE_Service_Config::process_directive (
- ace_svc_desc_TAO_Default_Client_Strategy_Factory);
- ACE_Service_Config::process_directive (
- 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::process_directive (
- ace_svc_desc_TAO_IIOP_Protocol_Factory);
-
- // add descriptor to list of static objects.
- ACE_Service_Config::process_directive (
- ace_svc_desc_TAO_MCAST_Parser);
- ACE_Service_Config::process_directive (
- ace_svc_desc_TAO_CORBANAME_Parser);
- ACE_Service_Config::process_directive (
- ace_svc_desc_TAO_CORBALOC_Parser);
- ACE_Service_Config::process_directive (
- ace_svc_desc_TAO_FILE_Parser);
- ACE_Service_Config::process_directive (
- ace_svc_desc_TAO_DLL_Parser);
- ACE_Service_Config::process_directive (
- ace_svc_desc_TAO_Default_Stub_Factory);
- ACE_Service_Config::process_directive (
- ace_svc_desc_TAO_Default_Endpoint_Selector_Factory);
- ACE_Service_Config::process_directive (
- ace_svc_desc_TAO_Default_Protocols_Hooks);
- ACE_Service_Config::process_directive (
- ace_svc_desc_TAO_Default_Thread_Lane_Resources_Manager_Factory);
- ACE_Service_Config::process_directive (
- ace_svc_desc_TAO_Default_Collocation_Resolver);
-
- int result = 0;
-
- if (skip_service_config_open == 0)
- {
+ if (service_open_count++ == 0) // Atomic increment
+ {
+ ACE_Service_Config::process_directive (
+ ace_svc_desc_TAO_Default_Resource_Factory);
+ ACE_Service_Config::process_directive (
+ ace_svc_desc_TAO_Default_Client_Strategy_Factory);
+ ACE_Service_Config::process_directive (
+ 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::process_directive (
+ ace_svc_desc_TAO_IIOP_Protocol_Factory);
+
+ // add descriptor to list of static objects.
+ ACE_Service_Config::process_directive (
+ ace_svc_desc_TAO_MCAST_Parser);
+ ACE_Service_Config::process_directive (
+ ace_svc_desc_TAO_CORBANAME_Parser);
+ ACE_Service_Config::process_directive (
+ ace_svc_desc_TAO_CORBALOC_Parser);
+ ACE_Service_Config::process_directive (
+ ace_svc_desc_TAO_FILE_Parser);
+ ACE_Service_Config::process_directive (
+ ace_svc_desc_TAO_DLL_Parser);
+ ACE_Service_Config::process_directive (
+ ace_svc_desc_TAO_Default_Stub_Factory);
+ ACE_Service_Config::process_directive (
+ ace_svc_desc_TAO_Default_Endpoint_Selector_Factory);
+ ACE_Service_Config::process_directive (
+ ace_svc_desc_TAO_Default_Protocols_Hooks);
+ ACE_Service_Config::process_directive (
+ ace_svc_desc_TAO_Default_Thread_Lane_Resources_Manager_Factory);
+ ACE_Service_Config::process_directive (
+ ace_svc_desc_TAO_Default_Collocation_Resolver);
+
+ int result = 0;
+
+ if (!skip_service_config_open)
+ {
// Copy command line parameter not to use original.
- ACE_Argv_Type_Converter command_line(argc, argv);
+ ACE_Argv_Type_Converter command_line (argc, argv);
result =
ACE_Service_Config::open (command_line.get_argc(),
@@ -306,110 +343,78 @@ TAO_Internal::open_services_i (int &argc,
ACE_DEFAULT_LOGGER_KEY,
0, // Don't ignore static services.
ignore_default_svc_conf_file);
- }
-
- // If available, allow the Adapter Factory to setup.
- ACE_Service_Object *adapter_factory =
- ACE_Dynamic_Service<TAO_Adapter_Factory>::instance (
- TAO_ORB_Core::poa_factory_name ().c_str()
- );
-
- if (adapter_factory != 0)
- {
- adapter_factory->init (0, 0);
- }
+ }
- // Handle RTCORBA library special case. Since RTCORBA needs
- // its init method call to register several hooks, call it here
- // if it hasn't already been called.
- ACE_Service_Object *rt_loader =
- ACE_Dynamic_Service<ACE_Service_Object>::instance ("RT_ORB_Loader");
+ // If available, allow the Adapter Factory to setup.
+ ACE_Service_Object *adapter_factory =
+ ACE_Dynamic_Service<TAO_Adapter_Factory>::instance (
+ TAO_ORB_Core::poa_factory_name ().c_str());
- if (rt_loader != 0)
- {
- rt_loader->init (0, 0);
- }
+ if (adapter_factory != 0)
+ {
+ adapter_factory->init (0, 0);
+ }
- ACE_Service_Object *rtscheduler_loader =
- ACE_Dynamic_Service<ACE_Service_Object>::instance ("RTScheduler_Loader");
+ // Handle RTCORBA library special case. Since RTCORBA needs
+ // its init method call to register several hooks, call it
+ // here if it hasn't already been called.
+ ACE_Service_Object * const rt_loader =
+ ACE_Dynamic_Service<ACE_Service_Object>::instance ("RT_ORB_Loader");
- if (rtscheduler_loader != 0)
- {
- rtscheduler_loader->init (0, 0);
- }
+ if (rt_loader != 0)
+ {
+ rt_loader->init (0, 0);
+ }
- // @@ 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 (
- ACE_TEXT_CHAR_TO_TCHAR (
- TAO_Internal::resource_factory_args_
- )
- );
- }
+ ACE_Service_Object * const rtscheduler_loader =
+ ACE_Dynamic_Service<ACE_Service_Object>::instance ("RTScheduler_Loader");
- if (TAO_Internal::client_strategy_factory_args_ != 0)
- {
- ACE_Service_Config::process_directive (
- ACE_TEXT_CHAR_TO_TCHAR (
- TAO_Internal::client_strategy_factory_args_
- )
- );
- }
+ if (rtscheduler_loader != 0)
+ {
+ rtscheduler_loader->init (0, 0);
+ }
- if (TAO_Internal::server_strategy_factory_args_ != 0)
- {
- ACE_Service_Config::process_directive (
- ACE_TEXT_CHAR_TO_TCHAR (
- TAO_Internal::server_strategy_factory_args_
- )
- );
- }
+ // @@ What the heck do these things do and do we need to avoid
+ // calling them if we're not invoking the svc.conf file?
+ // @@ They are needed for platforms that have no file system,
+ // like VxWorks.
+ if (resource_factory_args != 0)
+ {
+ ACE_Service_Config::process_directive (
+ ACE_TEXT_CHAR_TO_TCHAR (resource_factory_args));
+ }
- return result;
- }
- else
- {
- return 0;
- }
-}
+ if (client_strategy_factory_args != 0)
+ {
+ ACE_Service_Config::process_directive (
+ ACE_TEXT_CHAR_TO_TCHAR (client_strategy_factory_args));
+ }
-TAO_Internal::TAO_Internal (void)
-{
-}
+ if (server_strategy_factory_args != 0)
+ {
+ ACE_Service_Config::process_directive (
+ ACE_TEXT_CHAR_TO_TCHAR (server_strategy_factory_args));
+ }
-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;
+ return result;
+ }
+ else
+ {
+ return 0;
+ }
+ }
}
#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
-
template class ACE_Dynamic_Service<ACE_Service_Object>;
-
#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
-
-#pragma instantiate ACE_Dynamic_Service<ACE_Service_Object>
-
+# pragma instantiate ACE_Dynamic_Service<ACE_Service_Object>
#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */
#if defined (TAO_DEBUG) && !defined (ACE_HAS_WINCE)
-
-#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
-
-template class ACE_Env_Value<int>;
+# if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
template class ACE_Env_Value<u_int>;
-
-#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
-
-#pragma instantiate ACE_Env_Value<int>
-#pragma instantiate ACE_Env_Value<u_int>
-
-#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */
-
-#endif /*defined TAO_DEBUG && !defined (ACE_HAS_WINCE) */
+# elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
+# pragma instantiate ACE_Env_Value<u_int>
+# endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */
+#endif /* TAO_DEBUG && !ACE_HAS_WINCE */