2 #include "Callback_i.h"
3 #include "ClientTask.h"
4 #include "tao/CSD_ThreadPool/CSD_TP_Strategy.h"
5 #include "tao/Intrusive_Ref_Count_Handle_T.h"
6 #include "ace/Get_Opt.h"
7 #include "ace/Log_Msg.h"
8 // To force static load the service.
10 #include "tao/CSD_ThreadPool/CSD_ThreadPool.h"
13 ClientApp::ClientApp()
18 ClientApp::~ClientApp()
24 ClientApp::run (int argc
, ACE_TCHAR
* argv
[])
27 = CORBA::ORB_init (argc
, argv
);
29 // Parse the command-line args for this application.
30 // * Raises -1 if problems are encountered.
31 // * Returns 1 if the usage statement was explicitly requested.
32 // * Returns 0 otherwise.
33 int result
= this->parse_args (argc
, argv
);
40 = orb
->string_to_object(this->ior_
.c_str());
42 if (CORBA::is_nil(obj
.in()))
45 "(%P|%t) Failed to convert IOR string to obj ref.\n"));
46 throw TestException();
49 Foo_var foo
= Foo::_narrow(obj
.in());
51 if (CORBA::is_nil(foo
.in()))
54 "(%P|%t) Failed to narrow obj ref to Foo interface.\n"));
55 throw TestException();
58 // Create the callback object using the child poa with the custom
60 obj
= orb
->resolve_initial_references("RootPOA");
62 if (CORBA::is_nil(obj
.in()))
65 "(%P|%t) Failed to resolve initial ref for 'RootPOA'.\n"));
66 throw TestException();
69 PortableServer::POA_var root_poa
70 = PortableServer::POA::_narrow(obj
.in());
72 if (CORBA::is_nil(root_poa
.in()))
75 "(%P|%t) Failed to narrow obj ref to POA interface.\n"));
76 throw TestException();
79 PortableServer::POAManager_var poa_manager
80 = root_poa
->the_POAManager();
82 // Create the child POA.
83 CORBA::PolicyList
policies(0);
86 PortableServer::POA_var child_poa
87 = root_poa
->create_POA("ChildPoa",
91 if (CORBA::is_nil(child_poa
.in()))
93 ACE_ERROR((LM_ERROR
, "(%P|%t) ERROR [ServerApp::run()]: "
94 "Failed to create the child POA.\n"));
95 throw TestException();
98 // Create the thread pool servant dispatching strategy object, and
99 // hold it in a (local) smart pointer variable.
100 TAO_Intrusive_Ref_Count_Handle
<TAO::CSD::TP_Strategy
> csd_tp_strategy
=
101 new TAO::CSD::TP_Strategy();
103 csd_tp_strategy
->set_num_threads(1);
105 // Tell the strategy to apply itself to the child poa.
106 if (csd_tp_strategy
->apply_to(child_poa
.in()) == false)
108 ACE_ERROR((LM_ERROR
, "(%P|%t) ERROR [ServerApp::run()]: "
109 "Failed to apply custom dispatching strategy to child poa.\n"));
110 throw TestException();
113 // Create the servant object.
114 Callback_i
* servant
= new Callback_i ();
116 // local smart pointer variable to deal with releasing the reference
117 // to the servant object when the smart pointer object falls out of scope.
118 PortableServer::ServantBase_var
owner_transfer(servant
);
120 // Activate the servant using the Child POA.
121 PortableServer::ObjectId_var oid
122 = child_poa
->activate_object(servant
);
124 // Obtain the object reference.
125 obj
= child_poa
->servant_to_reference(servant
);
127 if (CORBA::is_nil(obj
.in()))
130 "(%P|%t) Failed to activate servant (Callback_i).\n"));
131 throw TestException();
134 Callback_var callback
= Callback::_narrow (obj
.in ());
136 ClientTask
client_task(orb
.in (), foo
.in (), callback
.in ());
138 if (client_task
.open () != 0)
140 throw TestException();
143 // Activate the POA Manager
144 poa_manager
->activate();
147 "(%P|%t) ClientApp is ready.\n"));
154 "(%P|%t) ClientApp is destroying the Root POA.\n"));
156 // Tear-down the root poa and orb.
157 root_poa
->destroy(1, 1);
160 "(%P|%t) ClientApp is destroying the ORB.\n"));
165 "(%P|%t) ClientApp has completed running successfully.\n"));
172 ClientApp::parse_args(int argc
, ACE_TCHAR
* argv
[])
174 this->exe_name_
= argv
[0];
176 ACE_Get_Opt
get_opts(argc
, argv
, ACE_TEXT("i:"));
180 while ((c
= get_opts()) != -1)
185 this->ior_
= get_opts
.opt_arg();
189 this->usage_statement();
192 this->usage_statement();
202 ClientApp::usage_statement()
205 "Usage: %s [options]\n\n"
209 this->exe_name_
.c_str()));