Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / TAO / tao / CSD_ThreadPool / CSD_TP_Strategy_Factory.cpp
blobf23ff0fa9eb531a9a5804fe64d22f2864770700e
1 #include "tao/CSD_ThreadPool/CSD_TP_Strategy_Factory.h"
2 #include "tao/CSD_ThreadPool/CSD_TP_Strategy.h"
3 #include "tao/CSD_ThreadPool/CSD_ThreadPool.h"
4 #include "tao/CSD_Framework/CSD_Strategy_Repository.h"
5 #include "tao/debug.h"
6 #include "ace/Dynamic_Service.h"
7 #include "ace/OS_NS_strings.h"
9 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
11 TAO::CSD::TP_Strategy_Factory::TP_Strategy_Factory()
16 TAO::CSD::TP_Strategy_Factory::~TP_Strategy_Factory()
21 int
22 TAO::CSD::TP_Strategy_Factory::init (int argc,
23 ACE_TCHAR* argv[])
25 ACE_TRACE ("TAO::CSD::TP_Strategy_Factory::init");
27 static int initialized = 0;
29 // Only allow initialization once.
30 if (initialized)
31 return 0;
33 initialized = 1;
34 TAO_CSD_Strategy_Repository *repo =
35 ACE_Dynamic_Service<TAO_CSD_Strategy_Repository>::instance
36 (ACE_TEXT ("TAO_CSD_Strategy_Repository"));
38 if (repo == 0)
40 TAO_CSD_ThreadPool::init ();
41 repo = ACE_Dynamic_Service<TAO_CSD_Strategy_Repository>::instance
42 (ACE_TEXT ("TAO_CSD_Strategy_Repository"));
45 if (repo == 0)
47 if (TAO_debug_level > 0)
49 TAOLIB_DEBUG((LM_DEBUG,
50 ACE_TEXT ("TAO (%P|%t) - TP_Strategy_Factory - ")
51 ACE_TEXT ("cannot initialize strategy repo\n")));
53 return -1;
56 repo->init(0,0);
58 // Parse any service configurator parameters.
59 for (int curarg = 0; curarg < argc; curarg++)
61 if (ACE_OS::strcasecmp (argv[curarg],
62 ACE_TEXT("-CSDtp")) == 0)
64 ACE_CString poa_name;
65 unsigned long num_threads = 1;
66 bool serialize_servants = true;
68 curarg++;
69 if (curarg >= argc)
71 return -1;
74 // Parse the parameter
75 ACE_TCHAR *sep = ACE_OS::strchr (argv[curarg],':');
76 if (sep == 0)
78 poa_name = ACE_TEXT_ALWAYS_CHAR (argv[curarg]);
80 else
82 *sep = 0;
83 poa_name = ACE_TEXT_ALWAYS_CHAR (argv[curarg]);
84 num_threads = ACE_OS::strtol (sep + 1, &sep, 10);
85 if (*sep != 0 && *sep != ':')
87 return -1;
89 if (*sep == ':')
91 if (ACE_OS::strcasecmp (
92 sep + 1, ACE_TEXT_CHAR_TO_TCHAR ("OFF")) == 0)
94 serialize_servants = false;
99 // Create the ThreadPool strategy for each named poa.
100 TP_Strategy* strategy = 0;
101 ACE_NEW_RETURN (strategy,
102 TP_Strategy (num_threads, serialize_servants),
103 -1);
104 CSD_Framework::Strategy_var objref = strategy;
105 repo->add_strategy (poa_name, strategy);
107 else
109 if (TAO_debug_level > 0)
111 TAOLIB_ERROR ((LM_ERROR,
112 ACE_TEXT("CSD_ORB_Loader: Unknown option ")
113 ACE_TEXT("<%s>.\n"),
114 argv[curarg]));
116 return -1;
120 return 0;
123 TAO_END_VERSIONED_NAMESPACE_DECL
125 ACE_FACTORY_NAMESPACE_DEFINE(TAO_CSD_TP,
126 TAO_CSD_TP_Strategy_Factory,
127 TAO::CSD::TP_Strategy_Factory)
129 ACE_STATIC_SVC_DEFINE(TAO_CSD_TP_Strategy_Factory,
130 ACE_TEXT("TAO_CSD_TP_Strategy_Factory"),
131 ACE_SVC_OBJ_T,
132 &ACE_SVC_NAME(TAO_CSD_TP_Strategy_Factory),
133 ACE_Service_Type::DELETE_THIS | ACE_Service_Type::DELETE_OBJ,