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"
24 const ACE_TCHAR
*ior
= ACE_TEXT("file://test.ior");
26 int shutdown_flag
= 0;
30 parse_args (int argc
, ACE_TCHAR
*argv
[])
32 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("dk:i:x"));
35 while ((c
= get_opts ()) != -1)
42 ior
= get_opts
.opt_arg ();
45 niterations
= ACE_OS::atoi (get_opts
.opt_arg ());
52 ACE_ERROR_RETURN ((LM_ERROR
,
61 // Indicates successful parsing of the command line
65 class Handler
: public POA_A::AMI_AMI_TestHandler
74 void foo (CORBA::Long ami_return_val
,
80 "Callback method <foo> called: result <%d>, out_arg <%d>\n",
86 void foo_excep (::Messaging::ExceptionHolder
* excep_holder
)
89 "Callback method <foo_excep> called:\n"
90 "Testing proper exception handling ...\n"));
93 excep_holder
->raise_exception ();
95 catch (const A::DidTheRightThing
&)
98 "... exception received successfully\n"));
100 catch (const CORBA::Exception
&)
102 ACE_DEBUG ((LM_DEBUG
,
103 "... caught the wrong exception -> ERROR\n"));
108 void get_yadda (CORBA::Long result
)
110 ACE_DEBUG ((LM_DEBUG
,
111 "Callback method <get_yadda> called: result <%d>\n",
115 void get_yadda_excep (::Messaging::ExceptionHolder
*)
117 ACE_DEBUG ((LM_DEBUG
,
118 "Callback method <get_yadda_excep> called:\n"));
123 ACE_DEBUG ((LM_DEBUG
,
124 "Callback method <set_yadda> called:\n"));
127 void set_yadda_excep (::Messaging::ExceptionHolder
*)
129 ACE_DEBUG ((LM_DEBUG
,
130 "Callback method <set_yadda_excep> called:\n"));
135 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
137 ACE_START_TEST (ACE_TEXT ("HTIOP_AMI_simple_client"));
143 CORBA::ORB_init (argc
, argv
);
145 CORBA::Object_var object_var
=
146 orb
->resolve_initial_references ("RootPOA");
148 PortableServer::POA_var poa_var
=
149 PortableServer::POA::_narrow (object_var
.in ());
151 PortableServer::POAManager_var poa_manager_var
=
152 poa_var
->the_POAManager ();
154 poa_manager_var
->activate ();
156 if (parse_args (argc
, argv
) != 0)
159 // We reuse the object_var smart pointer!
160 object_var
= orb
->string_to_object (ior
);
162 A::AMI_Test_var ami_test_var
=
163 A::AMI_Test::_narrow (object_var
.in ());
165 if (CORBA::is_nil (ami_test_var
.in ()))
167 ACE_ERROR_RETURN ((LM_ERROR
,
168 "Object reference <%s> is nil\n",
173 ACE_OS::socket_init ();
175 // Instantiate the ReplyHandler and register that with the POA.
177 A::AMI_AMI_TestHandler_var the_handler_var
=
180 // Try out sending asynchronous messages without a reply handler
181 // registered. Things fail if we get an exception.
183 ami_test_var
->sendc_foo (A::AMI_AMI_TestHandler::_nil (),
188 // Trigger the DidTheRightThing exception on the server side
189 // by sending 0 to it.
190 ACE_DEBUG ((LM_DEBUG
,
191 "Sending asynch message\n"));
193 ami_test_var
->sendc_foo (the_handler_var
.in (),
197 CORBA::Long l
= 931247;
199 for (ssize_t ni
= 0; ni
< niterations
; ni
++)
201 ACE_DEBUG ((LM_DEBUG
,
202 "Sending asynch message: %d\n",
205 ami_test_var
->sendc_foo (the_handler_var
.in (),
210 // Begin test of attributes
211 ami_test_var
->sendc_get_yadda (the_handler_var
.in ());
213 ami_test_var
->sendc_set_yadda (the_handler_var
.in (),
216 ami_test_var
->sendc_get_yadda (the_handler_var
.in ());
218 // End test of attributes
222 ACE_DEBUG ((LM_DEBUG
,
223 "<%d> Asynchronous methods issued\n",
229 ACE_DEBUG ((LM_DEBUG
,
230 "Issuing a synchronous method to collect the AMI replies\n"));
233 //while (orb->work_pending())
234 // orb->perform_work ();
237 CORBA::Long number
= ami_test_var
->foo (l
,
243 ACE_DEBUG ((LM_DEBUG
,
244 "Received the following number: %d\n",
250 ACE_DEBUG ((LM_DEBUG
, "invoking shutdown\n"));
251 ami_test_var
->shutdown ();
254 poa_var
->destroy (1, // ethernalize objects
255 0); // wait for completion
259 catch (const CORBA::Exception
& ex
)
261 ex
._tao_print_exception ("Caught exception:");