Go to the documentation of this file.00001
00002
00003 #include "tao/CSD_ThreadPool/CSD_TP_Strategy_Factory.h"
00004 #include "tao/CSD_ThreadPool/CSD_TP_Strategy.h"
00005 #include "tao/CSD_ThreadPool/CSD_ThreadPool.h"
00006 #include "tao/CSD_Framework/CSD_Strategy_Repository.h"
00007 #include "tao/debug.h"
00008 #include "ace/Dynamic_Service.h"
00009 #include "ace/OS_NS_strings.h"
00010
00011 ACE_RCSID (CSD_ThreadPool,
00012 TP_Strategy_Factory,
00013 "$Id: CSD_TP_Strategy_Factory.cpp 83166 2008-10-12 20:55:37Z johnnyw $")
00014
00015 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00016
00017 TAO::CSD::TP_Strategy_Factory::TP_Strategy_Factory()
00018 {
00019 }
00020
00021
00022 TAO::CSD::TP_Strategy_Factory::~TP_Strategy_Factory()
00023 {
00024 }
00025
00026
00027 int
00028 TAO::CSD::TP_Strategy_Factory::init (int argc,
00029 ACE_TCHAR* argv[])
00030 {
00031 ACE_TRACE ("TAO::CSD::TP_Strategy_Factory::init");
00032
00033 static int initialized = 0;
00034
00035
00036 if (initialized)
00037 return 0;
00038
00039 initialized = 1;
00040 TAO_CSD_Strategy_Repository *repo =
00041 ACE_Dynamic_Service<TAO_CSD_Strategy_Repository>::instance ("TAO_CSD_Strategy_Repository");
00042
00043 if (repo != 0)
00044 repo->init(0,0);
00045
00046
00047 for (int curarg = 0; curarg < argc; curarg++)
00048 if (ACE_OS::strcasecmp (argv[curarg],
00049 ACE_TEXT("-CSDtp")) == 0)
00050 {
00051 ACE_CString poa_name;
00052 unsigned long num_threads = 1;
00053 bool serialize_servants = true;
00054
00055 curarg++;
00056 if (curarg < argc)
00057 {
00058
00059 ACE_CString arg ((const char *)argv[curarg]);
00060 ACE_CString::size_type pos = arg.find (':');
00061
00062 if (pos == ACE_CString::npos)
00063 {
00064 poa_name = arg;
00065 }
00066 else
00067 {
00068 poa_name = arg.substr (0, pos);
00069
00070 ACE_CString arg_remainder =
00071 arg.substr (pos + 1, arg.length () - pos);
00072
00073 ACE_CString num_thread_str;
00074
00075 pos = arg_remainder.find (':');
00076
00077 if (pos == ACE_CString::npos)
00078 {
00079 num_thread_str = arg_remainder;
00080 }
00081 else
00082 {
00083 num_thread_str = arg_remainder.substr (0, pos);
00084
00085 ACE_CString off_str =
00086 arg_remainder.substr (pos + 1, arg.length () - pos);
00087
00088
00089 if (ACE_OS::strcasecmp (off_str.c_str(), "OFF") == 0)
00090 {
00091 serialize_servants = false;
00092 }
00093 }
00094
00095 num_threads = ACE_OS::strtoul (num_thread_str.c_str (), 0, 10);
00096
00097 if (num_threads == 0)
00098 {
00099
00100 num_threads = 1;
00101 }
00102 }
00103
00104
00105 TP_Strategy* strategy = 0;
00106 ACE_NEW_RETURN (strategy,
00107 TP_Strategy (num_threads, serialize_servants),
00108 -1);
00109 CSD_Framework::Strategy_var objref = strategy;
00110
00111 TAO_CSD_Strategy_Repository *repo =
00112 ACE_Dynamic_Service<TAO_CSD_Strategy_Repository>::instance
00113 ("TAO_CSD_Strategy_Repository");
00114
00115 if (repo == 0)
00116 {
00117 TAO_CSD_ThreadPool::init ();
00118 repo = ACE_Dynamic_Service<TAO_CSD_Strategy_Repository>::instance (
00119 "TAO_CSD_Strategy_Repository"
00120 );
00121 }
00122
00123
00124 repo->add_strategy (poa_name, strategy);
00125 }
00126 }
00127 else
00128 {
00129 if (TAO_debug_level > 0)
00130 {
00131 ACE_ERROR ((LM_ERROR,
00132 ACE_TEXT("CSD_ORB_Loader: Unknown option ")
00133 ACE_TEXT("<%s>.\n"),
00134 argv[curarg]));
00135 }
00136 }
00137
00138
00139 return 0;
00140 }
00141
00142 TAO_END_VERSIONED_NAMESPACE_DECL
00143
00144 ACE_FACTORY_NAMESPACE_DEFINE(TAO_CSD_TP,
00145 TAO_CSD_TP_Strategy_Factory,
00146 TAO::CSD::TP_Strategy_Factory)
00147
00148 ACE_STATIC_SVC_DEFINE(TAO_CSD_TP_Strategy_Factory,
00149 ACE_TEXT("TAO_CSD_TP_Strategy_Factory"),
00150 ACE_SVC_OBJ_T,
00151 &ACE_SVC_NAME(TAO_CSD_TP_Strategy_Factory),
00152 ACE_Service_Type::DELETE_THIS | ACE_Service_Type::DELETE_OBJ,
00153 0)