RT_ORB_Loader.cpp

Go to the documentation of this file.
00001 #include "tao/RTCORBA/RT_ORB_Loader.h"
00002 
00003 #if defined (TAO_HAS_CORBA_MESSAGING) && TAO_HAS_CORBA_MESSAGING != 0
00004 
00005 #include "tao/RTCORBA/RT_ORBInitializer.h"
00006 
00007 #include "tao/debug.h"
00008 #include "tao/ORB_Constants.h"
00009 #include "tao/ORBInitializer_Registry.h"
00010 #include "tao/SystemException.h"
00011 #include "ace/OS_NS_strings.h"
00012 #include "ace/Arg_Shifter.h"
00013 
00014 ACE_RCSID (RTCORBA,
00015            RT_ORB_Loader,
00016            "$Id: RT_ORB_Loader.cpp 80216 2007-12-10 08:15:33Z johnnyw $")
00017 
00018 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00019 
00020 TAO_RT_ORB_Loader::~TAO_RT_ORB_Loader (void)
00021 {
00022 }
00023 
00024 int
00025 TAO_RT_ORB_Loader::init (int argc, ACE_TCHAR* argv[])
00026 {
00027   ACE_TRACE ("TAO_RT_ORB_Loader::init");
00028 
00029   static bool initialized = false;
00030 
00031   // Only allow initialization once.
00032   if (initialized)
00033     return 0;
00034 
00035   initialized = true;
00036 
00037   // Set defaults.
00038   int priority_mapping_type =
00039     TAO_RT_ORBInitializer::TAO_PRIORITY_MAPPING_DIRECT;
00040   int network_priority_mapping_type =
00041     TAO_RT_ORBInitializer::TAO_NETWORK_PRIORITY_MAPPING_LINEAR;
00042   int ace_sched_policy = ACE_SCHED_OTHER;
00043   long sched_policy = THR_SCHED_DEFAULT;
00044   long scope_policy = THR_SCOPE_PROCESS;
00045   int curarg = 0;
00046   ACE_Time_Value dynamic_thread_time;
00047   TAO_RT_ORBInitializer::TAO_RTCORBA_DT_LifeSpan lifespan = TAO_RT_ORBInitializer::TAO_RTCORBA_DT_INFINITIVE;
00048 
00049   ACE_Arg_Shifter arg_shifter (argc, argv);
00050 
00051   // Parse any service configurator parameters.
00052   while (arg_shifter.is_anything_left ())
00053     {
00054       const ACE_TCHAR *current_arg = 0;
00055       if (0 != (current_arg = arg_shifter.get_the_parameter
00056                   (ACE_TEXT("-ORBPriorityMapping"))))
00057         {
00058           const ACE_TCHAR *name = current_arg;
00059           if (ACE_OS::strcasecmp (name,
00060                                   ACE_TEXT("continuous")) == 0)
00061             priority_mapping_type =
00062               TAO_RT_ORBInitializer::TAO_PRIORITY_MAPPING_CONTINUOUS;
00063           else if (ACE_OS::strcasecmp (name,
00064                                        ACE_TEXT("linear")) == 0)
00065             priority_mapping_type =
00066               TAO_RT_ORBInitializer::TAO_PRIORITY_MAPPING_LINEAR;
00067           else if (ACE_OS::strcasecmp (name,
00068                                        ACE_TEXT("direct")) == 0)
00069             priority_mapping_type =
00070               TAO_RT_ORBInitializer::TAO_PRIORITY_MAPPING_DIRECT;
00071           else
00072             ACE_DEBUG ((LM_DEBUG,
00073                         ACE_TEXT("RT_ORB_Loader - unknown argument")
00074                         ACE_TEXT(" <%s> for -ORBPriorityMapping\n"),
00075                         name));
00076           arg_shifter.consume_arg ();
00077         }
00078       else if (0 != (current_arg = arg_shifter.get_the_parameter
00079                                  (ACE_TEXT("-ORBSchedPolicy"))))
00080         {
00081           const ACE_TCHAR *name = current_arg;
00082           if (ACE_OS::strcasecmp (name,
00083                                   ACE_TEXT("SCHED_OTHER")) == 0)
00084             {
00085               ace_sched_policy = ACE_SCHED_OTHER;
00086               sched_policy = THR_SCHED_DEFAULT;
00087             }
00088           else if (ACE_OS::strcasecmp (name,
00089                                        ACE_TEXT("SCHED_FIFO")) == 0)
00090             {
00091               ace_sched_policy = ACE_SCHED_FIFO;
00092               sched_policy = THR_SCHED_FIFO;
00093             }
00094           else if (ACE_OS::strcasecmp (name,
00095                                        ACE_TEXT("SCHED_RR")) == 0)
00096             {
00097               ace_sched_policy = ACE_SCHED_RR;
00098               sched_policy = THR_SCHED_RR;
00099             }
00100           else
00101             ACE_DEBUG ((LM_DEBUG,
00102                         ACE_TEXT("RT_ORB_Loader - unknown argument")
00103                         ACE_TEXT(" <%s> for -ORBSchedPolicy\n"),
00104                         name));
00105           arg_shifter.consume_arg ();
00106         }
00107       else if (0 != (current_arg = arg_shifter.get_the_parameter
00108                                  (ACE_TEXT("-ORBScopePolicy"))))
00109         {
00110           const ACE_TCHAR *name = current_arg;
00111           if (ACE_OS::strcasecmp (name,
00112                                   ACE_TEXT("SYSTEM")) == 0)
00113             scope_policy = THR_SCOPE_SYSTEM;
00114           else if (ACE_OS::strcasecmp (name,
00115                                        ACE_TEXT("PROCESS")) == 0)
00116             scope_policy = THR_SCOPE_PROCESS;
00117           else
00118             ACE_DEBUG ((LM_DEBUG,
00119                         ACE_TEXT("RT_ORB_Loader - unknown argument")
00120                         ACE_TEXT(" <%s> for -ORBScopePolicy\n"),
00121                         name));
00122           arg_shifter.consume_arg ();
00123         }
00124       else if (0 != (current_arg = arg_shifter.get_the_parameter
00125                                  (ACE_TEXT("-RTORBNetworkPriorityMapping"))))
00126         {
00127           const ACE_TCHAR *name = current_arg;
00128           if (ACE_OS::strcasecmp (name,
00129                                   ACE_TEXT("linear")) == 0)
00130               network_priority_mapping_type =
00131                 TAO_RT_ORBInitializer::TAO_NETWORK_PRIORITY_MAPPING_LINEAR;
00132           arg_shifter.consume_arg ();
00133         }
00134       else if (0 != (current_arg = arg_shifter.get_the_parameter
00135                                    (ACE_TEXT("-RTORBDynamicThreadIdleTimeout"))))
00136         {
00137           const ACE_TCHAR *name = current_arg;
00138           int timeout = ACE_OS::atoi (name);
00139           dynamic_thread_time = ACE_Time_Value (0, timeout);
00140           lifespan = TAO_RT_ORBInitializer::TAO_RTCORBA_DT_IDLE;
00141           arg_shifter.consume_arg ();
00142         }
00143       else if (0 != (current_arg = arg_shifter.get_the_parameter
00144                                    (ACE_TEXT("-RTORBDynamicThreadRunTime"))))
00145         {
00146           const ACE_TCHAR *name = current_arg;
00147           int timeout = ACE_OS::atoi (name);
00148           dynamic_thread_time = ACE_Time_Value (0, timeout);
00149           lifespan = TAO_RT_ORBInitializer::TAO_RTCORBA_DT_FIXED;
00150           arg_shifter.consume_arg ();
00151         }
00152     else
00153       {
00154         arg_shifter.ignore_arg ();
00155         if (TAO_debug_level > 0)
00156         {
00157           ACE_ERROR ((LM_ERROR,
00158                       ACE_TEXT("RT_ORB_Loader: Unknown option ")
00159                       ACE_TEXT("<%s>.\n"),
00160                       argv[curarg]));
00161         }
00162       }
00163     }
00164 
00165   // Register the ORB initializer.
00166   try
00167     {
00168       PortableInterceptor::ORBInitializer_ptr temp_orb_initializer =
00169         PortableInterceptor::ORBInitializer::_nil ();
00170 
00171       /// Register the RTCORBA ORBInitializer.
00172       ACE_NEW_THROW_EX (temp_orb_initializer,
00173                         TAO_RT_ORBInitializer (priority_mapping_type,
00174                                                network_priority_mapping_type,
00175                                                ace_sched_policy,
00176                                                sched_policy,
00177                                                scope_policy,
00178                                                lifespan,
00179                                                dynamic_thread_time),
00180                         CORBA::NO_MEMORY (
00181                           CORBA::SystemException::_tao_minor_code (
00182                             TAO::VMCID,
00183                             ENOMEM),
00184                           CORBA::COMPLETED_NO));
00185 
00186       PortableInterceptor::ORBInitializer_var orb_initializer;
00187       orb_initializer = temp_orb_initializer;
00188 
00189       PortableInterceptor::register_orb_initializer (orb_initializer.in ());
00190     }
00191   catch (const ::CORBA::Exception& ex)
00192     {
00193       ex._tao_print_exception (
00194         "Unexpected exception caught while "
00195         "initializing the RTORB");
00196       return 1;
00197     }
00198 
00199   return 0;
00200 }
00201 
00202 TAO_END_VERSIONED_NAMESPACE_DECL
00203 
00204 /////////////////////////////////////////////////////////////////////
00205 
00206 ACE_FACTORY_DEFINE (TAO_RTCORBA, TAO_RT_ORB_Loader)
00207 ACE_STATIC_SVC_DEFINE (TAO_RT_ORB_Loader,
00208                        ACE_TEXT ("RT_ORB_Loader"),
00209                        ACE_SVC_OBJ_T,
00210                        &ACE_SVC_NAME (TAO_RT_ORB_Loader),
00211                        ACE_Service_Type::DELETE_THIS
00212                        | ACE_Service_Type::DELETE_OBJ,
00213                        0)
00214 
00215 #endif /* TAO_HAS_CORBA_MESSAGING && TAO_HAS_CORBA_MESSAGING != 0 */

Generated on Tue Feb 2 17:42:49 2010 for TAO_RTCORBA by  doxygen 1.4.7