4 #include "AppShutdown.h"
5 #include "TestAppExceptionC.h"
6 #include "Foo_B_ClientEngine.h"
7 #include "ace/Get_Opt.h"
8 // To force static load the service.
10 #include "tao/CSD_ThreadPool/CSD_ThreadPool.h"
12 ClientApp::ClientApp()
13 : TestAppBase("TP_Test_3_Client"),
14 client_task_ (true), // shutdown orb after client is done.
18 ior_(ACE_TEXT("Not Set")),
25 ClientApp::~ClientApp()
31 ClientApp::run_i(int argc
, ACE_TCHAR
* argv
[])
33 int result
= this->init(argc
, argv
);
44 this->run_orb_event_loop();
46 // Calling wait on ACE_Thread_Manager singleton to avoid the problem
47 // that the main thread might exit before all CSD Threads exit.
49 // Wait for all CSD task threads exit.
50 ACE_Thread_Manager::instance ()->wait ();
52 result
= this->check_validity () ? 0 : -1;
60 ClientApp::init(int argc
, ACE_TCHAR
* argv
[])
62 this->orb_
= CORBA::ORB_init(argc
, argv
);
64 // Parse the command-line args for this application.
65 // * Raises -1 if problems are encountered.
66 // * Returns 1 if the usage statement was explicitly requested.
67 // * Returns 0 otherwise.
68 int result
= this->parse_args(argc
, argv
);
74 TheAppShutdown
->init(this->orb_
.in(), num_servants_
);
81 ClientApp::poa_setup(void)
83 this->poa_
= this->create_poa(this->orb_
.in(),
89 ClientApp::csd_setup(void)
91 this->tp_strategy_
= new TAO::CSD::TP_Strategy(this->num_csd_threads_
);
93 if (!this->tp_strategy_
->apply_to(this->poa_
.in()))
96 "Failed to apply CSD strategy to poa.\n"));
97 throw TestAppException();
103 ClientApp::client_setup(void)
105 // Turn the ior_ into a Foo_B obj ref.
106 Foo_B_var foo
= RefHelper
<Foo_B
>::string_to_ref(this->orb_
.in(),
109 this->servants_
.create_and_activate(1, // number of callback servants
111 ServantListType::T_stub_var cb
= this->servants_
.objref(0);
113 // Create the ClientEngine object, and give it the Foo_B and Callback object
115 ClientEngine_Handle engine
116 = new Foo_B_ClientEngine(foo
.in(), cb
.in (), this->client_id_
);
117 this->client_task_
.add_engine(engine
.in());
122 ClientApp::poa_activate(void)
124 PortableServer::POAManager_var poa_manager
125 = this->poa_
->the_POAManager();
126 poa_manager
->activate();
131 ClientApp::run_clients()
133 this->client_task_
.open();
138 ClientApp::run_orb_event_loop(void)
140 OrbRunner
orb_runner(this->orb_
.in(), this->num_orb_threads_
);
142 TheAppShutdown
->wait ();
146 PortableServer::POA_ptr
147 ClientApp::create_poa(CORBA::ORB_ptr orb
,
148 const char* poa_name
)
151 PortableServer::POA_var root_poa
152 = RefHelper
<PortableServer::POA
>::resolve_initial_ref(orb
,
155 // Get the POAManager from the Root POA.
156 PortableServer::POAManager_var poa_manager
157 = root_poa
->the_POAManager();
159 // Create the child POA Policies.
160 CORBA::PolicyList
policies(0);
163 // Create the child POA
164 PortableServer::POA_var poa
= AppHelper::create_poa(poa_name
,
169 // Give away the child POA_ptr from the POA_var variable.
180 ClientApp::parse_args(int argc
, ACE_TCHAR
* argv
[])
182 this->exe_name_
= argv
[0];
184 ACE_Get_Opt
get_opts(argc
, argv
, ACE_TEXT("i:k:n:"));
188 while ((c
= get_opts()) != -1)
194 this->ior_
= get_opts
.opt_arg();
198 result
= set_arg(this->client_kind_
,
205 result
= set_arg(this->client_id_
,
212 this->usage_statement();
216 this->usage_statement();
226 return this->arg_dependency_checks();
230 ClientApp::usage_statement()
233 "Usage: %s [options]\n\n"
236 "\t[-k <client_kind>]\n"
237 "\t[-n <client_id>]\n"
239 this->exe_name_
.c_str()));
244 ClientApp::arg_dependency_checks()
246 if (this->ior_
== ACE_TEXT("Not Set"))
249 "Error: Missing required command-line option (-i <ior>).\n"));
250 this->usage_statement();
253 if (this->client_id_
<= 0)
256 "Error: Invalid command-line option (-n <client id>).\n"
257 " The client id should be positive integer.\n"));
258 this->usage_statement();
267 ClientApp::set_arg(unsigned& value
,
268 const ACE_TCHAR
* arg
,
273 int tmp
= ACE_OS::atoi(arg
);
278 "Error: -%c <%s> must be integer type with a value of, "
279 "at least, %d.\n", opt
, name
, min
));
280 this->usage_statement();
290 ClientApp::check_validity ()
292 // Check whether the clients return any errors.
293 if (this->client_task_
.failure_count () > 0)