=default for generated implementation copy ctor
[ACE_TAO.git] / TAO / tao / Dynamic_TP / DTP_Config.cpp
blob5577389cca4393a4cd6d4a69ebfd4309374b3b37
1 #include "tao/Dynamic_TP/DTP_Config.h"
3 #if defined (TAO_HAS_CORBA_MESSAGING) && TAO_HAS_CORBA_MESSAGING != 0
5 #include "tao/Dynamic_TP/DTP_ORBInitializer.h"
7 #include "tao/debug.h"
8 #include "ace/Dynamic_Service.h"
9 #include "ace/OS_NS_strings.h"
11 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
13 TAO_DTP_Config_Registry_Installer::TAO_DTP_Config_Registry_Installer ()
15 ACE_Service_Config::process_directive (ace_svc_desc_TAO_DTP_Config_Registry);
19 TAO_DTP_Config_Registry::TAO_DTP_Config_Registry ()
23 TAO_DTP_Config_Registry::~TAO_DTP_Config_Registry ()
27 int
28 TAO_DTP_Config_Registry::init (int , ACE_TCHAR* [] )
30 return 0;
33 bool
34 TAO_DTP_Config_Registry::find (const ACE_CString& name,
35 TAO_DTP_Definition &entry)
37 return registry_.find (name, entry) == 0;
40 int
41 TAO_DTP_Config_Registry::bind (const ACE_CString& name,
42 TAO_DTP_Definition &entry)
44 return registry_.bind (name, entry);
47 int
48 TAO_DTP_Config_Registry::rebind (const ACE_CString& name,
49 TAO_DTP_Definition &entry)
51 return registry_.rebind (name, entry);
54 //-------------------------------------------------------------------------
56 TAO_DTP_Config::TAO_DTP_Config ()
60 TAO_DTP_Config::~TAO_DTP_Config ()
64 int
65 TAO_DTP_Config::init (int argc, ACE_TCHAR* argv[])
67 TAO_DTP_Definition entry;
69 ACE_TCHAR *name = 0;
70 bool overwrite = false;
72 int curarg = 0;
73 int r = 0;
75 for (curarg = 0; curarg < argc; ++curarg)
77 long val = 0;
78 if ((r = this->parse_string (curarg,
79 argc,
80 argv,
81 ACE_TEXT("-DTPName"),name )) != 0)
83 if (r < 0)
85 return -1;
88 else if ((r = this->parse_bool (curarg,
89 argc,
90 argv,
91 ACE_TEXT("-DTPOverwrite"),
92 overwrite )) != 0)
94 if (r < 0)
96 return -1;
99 else if ((r = this->parse_long (curarg,
100 argc,
101 argv,
102 ACE_TEXT("-DTPMin"),
103 val )) != 0)
105 if (r < 0)
107 return -1;
109 entry.min_threads_ = val;
111 else if ((r = this->parse_long (curarg,
112 argc,
113 argv,
114 ACE_TEXT("-DTPInit"),
115 val )) != 0)
117 if (r < 0)
119 return -1;
121 entry.init_threads_ = val;
123 else if ((r = this->parse_long (curarg,
124 argc,
125 argv,
126 ACE_TEXT("-DTPMax"),
127 val )) != 0)
129 if (r < 0)
131 return -1;
133 entry.max_threads_ = val;
135 else if ((r = this->parse_long (curarg,
136 argc,
137 argv,
138 ACE_TEXT("-DTPStack"),
139 val )) != 0)
141 if (r < 0)
143 return -1;
145 entry.stack_size_ = val;
147 else if ((r = this->parse_long (curarg,
148 argc,
149 argv,
150 ACE_TEXT("-DTPTImeout"),
151 val )) != 0)
153 if (r < 0)
155 return -1;
157 entry.timeout_ = val;
159 else if ((r = this->parse_long (curarg,
160 argc,
161 argv,
162 ACE_TEXT("-DTPQueue"),
163 val )) != 0)
165 if (r < 0)
167 return -1;
169 entry.queue_depth_ = val;
171 else
173 if (TAO_debug_level > 0)
175 TAOLIB_DEBUG ((LM_DEBUG,
176 ACE_TEXT ("TAO (%P|%t) - DTP_Config - ")
177 ACE_TEXT ("Unrecognized argv[%d], %C\n"),
178 curarg, argv[curarg]));
180 return -1;
184 if ((entry.max_threads_ != -1 && entry.max_threads_ < entry.init_threads_) ||
185 (entry.min_threads_ > entry.init_threads_))
187 if (TAO_debug_level > 0)
189 TAOLIB_DEBUG ((LM_DEBUG,
190 ACE_TEXT ("TAO (%P|%t) - DTP_Config - ")
191 ACE_TEXT ("thread count constraint ")
192 ACE_TEXT ("violated, min: %d <= init: %d <= max: ")
193 ACE_TEXT ("%d or max = -1\n"),
194 entry.min_threads_,
195 entry.init_threads_,
196 entry.max_threads_));
198 return 0;
201 ACE_CString name_str = ACE_TEXT_ALWAYS_CHAR (name);
202 ACE_Service_Gestalt *current = ACE_Service_Config::current();
203 TAO_DTP_Config_Registry* registry =
204 ACE_Dynamic_Service<TAO_DTP_Config_Registry>::instance
205 (current, "DTP_Config_Registry", true);
207 if (registry == 0)
209 current->process_directive (ace_svc_desc_TAO_DTP_Config_Registry);
210 registry = ACE_Dynamic_Service<TAO_DTP_Config_Registry>::instance
211 (current, "DTP_Config_Registry", true);
212 if (registry == 0)
214 if (TAO_debug_level > 0)
216 TAOLIB_DEBUG((LM_DEBUG,
217 ACE_TEXT ("TAO (%P|%t) - DTP_Config - ")
218 ACE_TEXT ("cannot initialize registry\n")));
220 return -1;
224 if (!overwrite)
226 return registry->bind(name_str, entry);
228 else
230 return registry->rebind(name_str, entry);
232 return 0;
236 TAO_DTP_Config::parse_long (int &curarg,
237 int argc, ACE_TCHAR *argv[],
238 const ACE_TCHAR *match, long &value)
240 ACE_TCHAR *str;
241 int result = this->parse_string (curarg, argc, argv, match, str);
242 if (result < 1)
243 return result;
245 ACE_TCHAR *err = 0;
246 value = ACE_OS::strtol (str, &err, 10);
247 if (err && *err != 0)
249 this->report_option_value_error (match, str);
250 return -1;
252 return 1;
256 TAO_DTP_Config::parse_bool (int &curarg,
257 int argc, ACE_TCHAR *argv[],
258 const ACE_TCHAR *match, bool &value)
260 long num;
261 int result = this->parse_long (curarg, argc, argv, match, num);
262 if (result < 1)
263 return result;
265 value = num != 0;
267 return 1;
271 TAO_DTP_Config::parse_string (int &curarg,
272 int argc, ACE_TCHAR *argv[],
273 const ACE_TCHAR *match, ACE_TCHAR *&value)
275 if (ACE_OS::strcasecmp (argv[curarg], match) != 0)
276 return 0;
278 ++curarg;
279 if (curarg >= argc)
281 this->report_option_value_error (match, ACE_TEXT("<missing>"));
282 return -1;
285 value = argv[curarg];
286 return 1;
290 void
291 TAO_DTP_Config::report_option_value_error (const ACE_TCHAR* option_name,
292 const ACE_TCHAR* option_value)
294 if (TAO_debug_level > 0)
296 TAOLIB_DEBUG((LM_DEBUG,
297 ACE_TEXT ("TAO (%P|%t) - DTP_Config - unknown ")
298 ACE_TEXT ("argument <%s> for <%s>\n"),
299 option_value, option_name));
304 /////////////////////////////////////////////////////////////////////
306 ACE_FACTORY_DEFINE (TAO_Dynamic_TP, TAO_DTP_Config_Registry)
307 ACE_STATIC_SVC_DEFINE (TAO_DTP_Config_Registry,
308 ACE_TEXT ("DTP_Config_Registry"),
309 ACE_SVC_OBJ_T,
310 &ACE_SVC_NAME (TAO_DTP_Config_Registry),
311 ACE_Service_Type::DELETE_THIS
312 | ACE_Service_Type::DELETE_OBJ,
314 ACE_FACTORY_DEFINE (TAO_Dynamic_TP, TAO_DTP_Config)
315 ACE_STATIC_SVC_DEFINE (TAO_DTP_Config,
316 ACE_TEXT ("DTP_Config"),
317 ACE_SVC_OBJ_T,
318 &ACE_SVC_NAME (TAO_DTP_Config),
319 ACE_Service_Type::DELETE_THIS
320 | ACE_Service_Type::DELETE_OBJ,
322 TAO_END_VERSIONED_NAMESPACE_DECL
324 #endif /* (TAO_HAS_CORBA_MESSAGING) && TAO_HAS_CORBA_MESSAGING != 0 */