Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / examples / RTCORBA / Activity / Builder.cpp
blob820c9b284f1c0a60ed2544480f838788287707a4
1 #include "Builder.h"
3 #include "ace/Get_Opt.h"
4 #include "POA_Holder.h"
5 #include "Job_i.h"
6 #include "Thread_Task.h"
7 #include "Activity.h"
9 Builder::Builder(void)
10 :poa_count_ (0),
11 poa_list_ (0),
12 task_count_ (0),
13 task_list_ (0),
14 job_count_ (0),
15 job_list_ (0)
17 ACTIVITY::instance()->builder (this);
20 Builder::~Builder(void)
24 int
25 Builder::init (int argc, ACE_TCHAR *argv[])
27 ACE_Arg_Shifter arg_shifter (argc, argv);
29 const ACE_TCHAR* current_arg = 0;
31 int task_count = 0;
32 int poa_count = 0;
33 int job_count = 0;
35 while (arg_shifter.is_anything_left ())
37 if (0 != (current_arg = arg_shifter.get_the_parameter (ACE_TEXT("-TaskCount"))))
39 task_count_ = ACE_OS::atoi (current_arg);
40 ACE_NEW_RETURN (task_list_, Periodic_Task*[task_count_], -1);
41 ACE_OS::memset (this->task_list_,
43 this->task_count_ * sizeof (this->task_list_[0]));
44 arg_shifter.consume_arg ();
46 if (0 != (current_arg = arg_shifter.get_the_parameter (ACE_TEXT("-JobCount"))))
48 job_count_ = ACE_OS::atoi (current_arg);
49 ACE_NEW_RETURN (job_list_, Job_i*[job_count_], -1);
50 ACE_OS::memset (this->job_list_,
52 this->job_count_ * sizeof (this->job_list_[0]));
53 arg_shifter.consume_arg ();
55 if (0 != (current_arg = arg_shifter.get_the_parameter (ACE_TEXT("-POACount"))))
57 poa_count_ = ACE_OS::atoi (current_arg);
58 ACE_NEW_RETURN (poa_list_, POA_Holder*[poa_count_], -1);
59 ACE_OS::memset (this->poa_list_,
61 this->poa_count_ * sizeof (this->poa_list_[0]));
62 arg_shifter.consume_arg ();
64 else if (arg_shifter.cur_arg_strncasecmp (ACE_TEXT("-ThreadTask")) == 0)
66 if (task_count < this->task_count_)
68 arg_shifter.consume_arg ();
70 Periodic_Task *task = 0;
72 ACE_NEW_RETURN (task, Thread_Task (), -1);
74 if (task->init_task (arg_shifter) == -1)
75 return -1;
77 task_list_[task_count++] = task;
79 else
80 return -1;
82 else if (arg_shifter.cur_arg_strncasecmp (ACE_TEXT("-Job")) == 0)
84 if (job_count < this->job_count_)
86 arg_shifter.consume_arg ();
88 Job_i *job;
90 ACE_NEW_RETURN (job, Job_i (), -1);
92 if (job->init (arg_shifter) == -1)
93 return -1;
95 this->job_list_[job_count++] = job;
97 else
98 return -1;
100 else if (arg_shifter.cur_arg_strncasecmp (ACE_TEXT("-POA")) == 0)
102 if (poa_count < this->poa_count_)
104 arg_shifter.consume_arg ();
106 POA_Holder *poa_holder = 0;
108 ACE_NEW_RETURN (poa_holder, POA_Holder (), -1);
110 if (poa_holder->init (arg_shifter) == -1)
112 delete poa_holder;
113 return -1;
116 this->poa_list_[poa_count++] = poa_holder;
118 else
119 return -1;
121 else
123 arg_shifter.ignore_arg ();
127 return 0;
131 Builder::fini (void)
133 // It's only a hack for proper cleanup of this badly designed test.
134 static bool already_cleaned = false;
135 if (already_cleaned)
136 return 0;
138 int count;
140 for (count = 0; count < this->task_count_; ++count)
141 delete this->task_list_[count];
142 delete [] this->task_list_;
144 delete [] this->job_list_;
146 for (count = 0; count < this->poa_count_; ++count)
147 delete this->poa_list_[count];
148 delete [] this->poa_list_;
150 already_cleaned = true;
152 return 0;
156 Builder::poa_list (POA_LIST& poa_list)
158 poa_list = poa_list_;
159 return poa_count_;
163 Builder::task_list (TASK_LIST& task_list)
165 task_list = task_list_;
166 return task_count_;
170 Builder::job_list (JOB_LIST& job_list)
172 job_list = job_list_;
173 return job_count_;
177 ACE_STATIC_SVC_DEFINE(Builder,
178 ACE_TEXT ("Builder"),
179 ACE_SVC_OBJ_T,
180 &ACE_SVC_NAME (Builder),
181 ACE_Service_Type::DELETE_THIS | ACE_Service_Type::DELETE_OBJ,
184 ACE_FACTORY_DEFINE (ACE_Local_Service, Builder)