2 //=============================================================================
4 * @file simple_client.cpp
6 * A very simple client which uses the AMI callback model.
8 * @author Alexander Babu Arulanthu <alex@cs.wustl.edu>
9 * @author Michael Kircher <Michael.Kircher@mchp.siemens.de>
11 //=============================================================================
14 #include "../test_config.h"
16 #include "ace/OS_NS_sys_socket.h"
17 #include "ace/Get_Opt.h"
20 #include "ami_testC.h"
21 #include "ami_testS.h"
25 const ACE_TCHAR
*ior
= ACE_TEXT("file://test.ior");
27 int shutdown_flag
= 0;
31 parse_args (int argc
, ACE_TCHAR
*argv
[])
33 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("dk:i:x"));
36 while ((c
= get_opts ()) != -1)
43 ior
= get_opts
.opt_arg ();
46 niterations
= ACE_OS::atoi (get_opts
.opt_arg ());
53 ACE_ERROR_RETURN ((LM_ERROR
,
62 // Indicates successful parsing of the command line
66 class Handler
: public POA_A::AMI_AMI_TestHandler
75 void foo (CORBA::Long ami_return_val
,
81 "Callback method <foo> called: result <%d>, out_arg <%d>\n",
87 void foo_excep (::Messaging::ExceptionHolder
* excep_holder
)
91 "Callback method <foo_excep> called:\n"
92 "Testing proper exception handling ...\n"));
95 excep_holder
->raise_exception ();
97 catch (const A::DidTheRightThing
&)
100 "... exception received successfully\n"));
102 catch (const CORBA::Exception
&)
104 ACE_DEBUG ((LM_DEBUG
,
105 "... caught the wrong exception -> ERROR\n"));
110 void get_yadda (CORBA::Long result
)
112 ACE_DEBUG ((LM_DEBUG
,
113 "Callback method <get_yadda> called: result <%d>\n",
117 void get_yadda_excep (::Messaging::ExceptionHolder
*)
119 ACE_DEBUG ((LM_DEBUG
,
120 "Callback method <get_yadda_excep> called:\n"));
123 void set_yadda (void)
125 ACE_DEBUG ((LM_DEBUG
,
126 "Callback method <set_yadda> called:\n"));
129 void set_yadda_excep (::Messaging::ExceptionHolder
*)
131 ACE_DEBUG ((LM_DEBUG
,
132 "Callback method <set_yadda_excep> called:\n"));
138 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
140 ACE_START_TEST (ACE_TEXT ("HTIOP_AMI_simple_client"));
146 CORBA::ORB_init (argc
, argv
);
148 CORBA::Object_var object_var
=
149 orb
->resolve_initial_references ("RootPOA");
151 PortableServer::POA_var poa_var
=
152 PortableServer::POA::_narrow (object_var
.in ());
154 PortableServer::POAManager_var poa_manager_var
=
155 poa_var
->the_POAManager ();
157 poa_manager_var
->activate ();
159 if (parse_args (argc
, argv
) != 0)
162 // We reuse the object_var smart pointer!
163 object_var
= orb
->string_to_object (ior
);
165 A::AMI_Test_var ami_test_var
=
166 A::AMI_Test::_narrow (object_var
.in ());
168 if (CORBA::is_nil (ami_test_var
.in ()))
170 ACE_ERROR_RETURN ((LM_ERROR
,
171 "Object reference <%s> is nil\n",
176 ACE_OS::socket_init ();
178 // Instantiate the ReplyHandler and register that with the POA.
180 A::AMI_AMI_TestHandler_var the_handler_var
=
183 // Try out sending asynchronous messages without a reply handler
184 // registered. Things fail if we get an exception.
186 ami_test_var
->sendc_foo (A::AMI_AMI_TestHandler::_nil (),
191 // Trigger the DidTheRightThing exception on the server side
192 // by sending 0 to it.
193 ACE_DEBUG ((LM_DEBUG
,
194 "Sending asynch message\n"));
196 ami_test_var
->sendc_foo (the_handler_var
.in (),
200 CORBA::Long l
= 931247;
202 for (ssize_t ni
= 0; ni
< niterations
; ni
++)
204 ACE_DEBUG ((LM_DEBUG
,
205 "Sending asynch message: %d\n",
208 ami_test_var
->sendc_foo (the_handler_var
.in (),
213 // Begin test of attributes
214 ami_test_var
->sendc_get_yadda (the_handler_var
.in ());
216 ami_test_var
->sendc_set_yadda (the_handler_var
.in (),
219 ami_test_var
->sendc_get_yadda (the_handler_var
.in ());
221 // End test of attributes
225 ACE_DEBUG ((LM_DEBUG
,
226 "<%d> Asynchronous methods issued\n",
232 ACE_DEBUG ((LM_DEBUG
,
233 "Issuing a synchronous method to collect the AMI replies\n"));
236 //while (orb->work_pending())
237 // orb->perform_work ();
240 CORBA::Long number
= ami_test_var
->foo (l
,
246 ACE_DEBUG ((LM_DEBUG
,
247 "Received the following number: %d\n",
253 ACE_DEBUG ((LM_DEBUG
, "invoking shutdown\n"));
254 ami_test_var
->shutdown ();
257 poa_var
->destroy (1, // ethernalize objects
258 0 // wait for completion
263 catch (const CORBA::Exception
& ex
)
265 ex
._tao_print_exception ("Caught exception:");