=default for generated implementation copy ctor
[ACE_TAO.git] / TAO / examples / RTScheduling / POA_Holder.cpp
blob7ece096155e6f01469774253e9dc49493a503526
1 #include "POA_Holder.h"
3 #include "tao/debug.h"
5 #include "ace/Arg_Shifter.h"
6 #include "ace/Log_Msg.h"
8 POA_Holder::POA_Holder ()
9 :priority_model_ (RTCORBA::CLIENT_PROPAGATED),
10 server_priority_ (0),
11 thread_pool_ (0)
15 int
16 POA_Holder::init (ACE_Arg_Shifter& arg_shifter)
18 ACE_DEBUG ((LM_DEBUG,
19 "Init POA\n"));
21 const ACE_TCHAR *current_arg = 0;
23 POA_name_ = ACE_TEXT_ALWAYS_CHAR(arg_shifter.get_current ()); // Read the name of the POA
24 arg_shifter.consume_arg ();
26 while (arg_shifter.is_anything_left ())
28 if (0 != (current_arg = arg_shifter.get_the_parameter (ACE_TEXT("-PriorityModel"))))
30 if (arg_shifter.cur_arg_strncasecmp (ACE_TEXT("CLIENT")) == 0)
31 priority_model_ = RTCORBA::CLIENT_PROPAGATED;
32 else
33 priority_model_ = RTCORBA::SERVER_DECLARED;
34 arg_shifter.consume_arg ();
36 server_priority_ = ACE_OS::atoi (current_arg);
37 arg_shifter.consume_arg ();
39 else if (0 != (current_arg = arg_shifter.get_the_parameter (ACE_TEXT("-Lanes"))))
41 int lanecount = ACE_OS::atoi (current_arg);
42 lanes_.length (lanecount);
43 arg_shifter.consume_arg ();
45 int l_index = 0;
46 //parse lane values ...
47 while (arg_shifter.is_anything_left ())
49 if (arg_shifter.cur_arg_strncasecmp (ACE_TEXT("-Lane")) == 0)
51 arg_shifter.consume_arg ();
53 // read priority
54 lanes_[l_index].lane_priority = ACE_OS::atoi (arg_shifter.get_current ());
55 arg_shifter.consume_arg ();
57 // static thread count
58 lanes_[l_index].static_threads = ACE_OS::atoi (arg_shifter.get_current ());
59 arg_shifter.consume_arg ();
61 // dynamic thread count
62 lanes_[l_index].dynamic_threads = ACE_OS::atoi (arg_shifter.get_current ());
63 arg_shifter.consume_arg ();
65 //if (TAO_debug_level > 0)
66 ACE_DEBUG ((LM_DEBUG, "lane parsed - %d, %d, %d\n",
67 lanes_[l_index].lane_priority, lanes_[l_index].static_threads, lanes_[l_index].dynamic_threads));
68 l_index++;
70 else
71 break;
72 } /* while -- lane values */
74 } /* if -Lanes */
75 else if (arg_shifter.cur_arg_strncasecmp (ACE_TEXT("-ThreadPool")) == 0)
77 ACE_DEBUG ((LM_DEBUG,
78 "Thread Pool\n"));
80 arg_shifter.consume_arg ();
81 thread_pool_ = 1;
82 // read priority
83 tp_static_threads_ = ACE_OS::atoi (arg_shifter.get_current ());
84 arg_shifter.consume_arg ();
86 tp_dynamic_threads_ = ACE_OS::atoi (arg_shifter.get_current ());
87 arg_shifter.consume_arg ();
89 tp_priority_ = ACE_OS::atoi (arg_shifter.get_current ());
90 arg_shifter.consume_arg ();
91 ACE_DEBUG ((LM_DEBUG,
92 "Thread Pool Initialized\n"));
94 else if (0 != (current_arg = arg_shifter.get_the_parameter (ACE_TEXT("-Bands"))))
96 ACE_DEBUG ((LM_DEBUG,
97 "Initializing Bands\n"));
99 int bandcount = ACE_OS::atoi (current_arg);
100 bands_.length (bandcount);
101 arg_shifter.consume_arg ();
103 int b_index = 0;
104 //parse band values ...
105 while (arg_shifter.is_anything_left ())
107 if (arg_shifter.cur_arg_strncasecmp (ACE_TEXT("-Band")) == 0)
109 arg_shifter.consume_arg ();
111 // read low
112 bands_[b_index].low = ACE_OS::atoi (arg_shifter.get_current ());
113 arg_shifter.consume_arg ();
115 // read high
116 bands_[b_index].high = ACE_OS::atoi (arg_shifter.get_current ());
117 arg_shifter.consume_arg ();
119 //if (TAO_debug_level > 0)
120 ACE_DEBUG ((LM_DEBUG, "band parsed - %d, %d\n",
121 bands_[b_index].low, bands_[b_index].high));
122 b_index++;
124 else
125 break;
126 } /* while -- Band values */
127 ACE_DEBUG ((LM_DEBUG,
128 "Bands Initialized\n"));
129 } /* if -Bands */
130 else // something else is showing up ...
132 ACE_DEBUG ((LM_DEBUG,
133 "Finish Init POA\n"));
135 return 0;
138 ACE_DEBUG ((LM_DEBUG,
139 "Finish Init POA\n"));
140 return 0;
143 void
144 POA_Holder::activate (RTCORBA::RTORB_ptr rt_orb, PortableServer::POA_ptr parent_poa)
146 CORBA::Policy_var priority_model_policy;
147 CORBA::Policy_var lanes_policy;
148 CORBA::Policy_var bands_policy;
149 CORBA::Policy_var thread_pool_policy;
151 // Create a priority model policy.
152 priority_model_policy =
153 rt_orb->create_priority_model_policy (priority_model_,
154 server_priority_);
156 if (lanes_.length () != 0)
158 // Create a thread-pool.
159 CORBA::ULong stacksize = 0;
160 CORBA::Boolean allow_request_buffering = 0;
161 CORBA::ULong max_buffered_requests = 0;
162 CORBA::ULong max_request_buffer_size = 0;
163 CORBA::Boolean allow_borrowing = 0;
165 // Create the thread-pool.
166 RTCORBA::ThreadpoolId threadpool_id =
167 rt_orb->create_threadpool_with_lanes (stacksize,
168 lanes_,
169 allow_borrowing,
170 allow_request_buffering,
171 max_buffered_requests,
172 max_request_buffer_size);
174 // Create a thread-pool policy.
175 lanes_policy =
176 rt_orb->create_threadpool_policy (threadpool_id);
178 ACE_DEBUG ((LM_DEBUG,
179 "Activated Lanes\n"));
182 if (thread_pool_)
184 CORBA::ULong stacksize = 0;
185 CORBA::Boolean allow_request_buffering = 0;
186 CORBA::ULong max_buffered_requests = 0;
187 CORBA::ULong max_request_buffer_size = 0;
189 RTCORBA::ThreadpoolId threadpool_id_1 =
190 rt_orb->create_threadpool (stacksize,
191 tp_static_threads_,
192 tp_dynamic_threads_,
193 tp_priority_,
194 allow_request_buffering,
195 max_buffered_requests,
196 max_request_buffer_size);
199 thread_pool_policy = rt_orb->create_threadpool_policy (threadpool_id_1);
201 ACE_DEBUG ((LM_DEBUG,
202 "Activated thread pool\n"));
205 if (bands_.length () != 0)
207 // Create a bands policy.
208 bands_policy =
209 rt_orb->create_priority_banded_connection_policy (this->bands_);
210 ACE_DEBUG ((LM_DEBUG,
211 "Activated Bands\n"));
214 CORBA::PolicyList poa_policy_list;
216 if (lanes_.length () == 0 && bands_.length () == 0)
218 if (thread_pool_)
220 poa_policy_list.length (2);
221 poa_policy_list[0] = priority_model_policy;
222 poa_policy_list[1] = thread_pool_policy;
224 else
226 poa_policy_list.length (1);
227 poa_policy_list[0] = priority_model_policy;
230 else if (lanes_.length () != 0 && bands_.length () == 0)
232 if (thread_pool_)
234 poa_policy_list.length (3);
235 poa_policy_list[0] = priority_model_policy;
236 poa_policy_list[1] = lanes_policy;
237 poa_policy_list[2] = thread_pool_policy;
239 else
241 poa_policy_list.length (2);
242 poa_policy_list[0] = priority_model_policy;
243 poa_policy_list[1] = lanes_policy;
246 else if (lanes_.length () == 0 && bands_.length () != 0)
248 if (thread_pool_)
250 poa_policy_list.length (3);
251 poa_policy_list[0] = priority_model_policy;
252 poa_policy_list[1] = bands_policy;
253 poa_policy_list[2] = thread_pool_policy;
255 else
257 poa_policy_list.length (2);
258 poa_policy_list[0] = priority_model_policy;
259 poa_policy_list[1] = bands_policy;
262 else
264 if (thread_pool_)
266 poa_policy_list.length (4);
267 poa_policy_list[0] = priority_model_policy;
268 poa_policy_list[1] = lanes_policy;
269 poa_policy_list[2] = bands_policy;
270 poa_policy_list[3] = thread_pool_policy;
272 else
274 poa_policy_list.length (3);
275 poa_policy_list[0] = priority_model_policy;
276 poa_policy_list[1] = lanes_policy;
277 poa_policy_list[2] = bands_policy;
281 ACE_DEBUG ((LM_DEBUG,
282 "Initialized POA Policy\n"));
284 if (TAO_debug_level > 0)
285 ACE_DEBUG ((LM_DEBUG, "creating POA %C\n", POA_name_.c_str ()));
287 // Get the POA Manager.
288 PortableServer::POAManager_var poa_manager =
289 parent_poa->the_POAManager ();
291 PortableServer::POA_var poa =
292 parent_poa->create_POA (POA_name_.c_str (),
293 poa_manager.in (),
294 poa_policy_list);