Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / orbsvcs / tests / HTIOP / AMI / simple_client.cpp
blob68204a73c165cb8bcaf0103cfa55222ab203a931
2 //=============================================================================
3 /**
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"
18 #include "ace/Task.h"
20 #include "ami_testC.h"
21 #include "ami_testS.h"
24 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
25 int niterations = 5;
26 int shutdown_flag = 0;
27 int debug = 0;
29 int
30 parse_args (int argc, ACE_TCHAR *argv[])
32 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("dk:i:x"));
33 int c;
35 while ((c = get_opts ()) != -1)
36 switch (c)
38 case 'd':
39 debug = 1;
40 break;
41 case 'k':
42 ior = get_opts.opt_arg ();
43 break;
44 case 'i':
45 niterations = ACE_OS::atoi (get_opts.opt_arg ());
46 break;
47 case 'x':
48 shutdown_flag = 1;
49 break;
50 case '?':
51 default:
52 ACE_ERROR_RETURN ((LM_ERROR,
53 "usage: %s "
54 "-k <ior> "
55 "-i <niterations> "
56 "-x "
57 "\n",
58 argv [0]),
59 -1);
61 // Indicates successful parsing of the command line
62 return 0;
65 class Handler : public POA_A::AMI_AMI_TestHandler
67 public:
68 /// Constructor.
69 Handler () {};
71 /// Destructor.
72 ~Handler () {};
74 void foo (CORBA::Long ami_return_val,
75 CORBA::Long out_l)
77 if (debug)
79 ACE_DEBUG ((LM_DEBUG,
80 "Callback method <foo> called: result <%d>, out_arg <%d>\n",
81 ami_return_val,
82 out_l));
86 void foo_excep (::Messaging::ExceptionHolder * excep_holder)
88 ACE_DEBUG ((LM_DEBUG,
89 "Callback method <foo_excep> called:\n"
90 "Testing proper exception handling ...\n"));
91 try
93 excep_holder->raise_exception ();
95 catch (const A::DidTheRightThing&)
97 ACE_DEBUG ((LM_DEBUG,
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",
112 result));
115 void get_yadda_excep (::Messaging::ExceptionHolder *)
117 ACE_DEBUG ((LM_DEBUG,
118 "Callback method <get_yadda_excep> called:\n"));
121 void set_yadda ()
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"));
142 CORBA::ORB_var orb =
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)
157 return 1;
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",
169 ior),
173 ACE_OS::socket_init ();
175 // Instantiate the ReplyHandler and register that with the POA.
176 Handler handler;
177 A::AMI_AMI_TestHandler_var the_handler_var =
178 handler._this ();
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 (),
185 "");
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 (),
195 "Let's talk AMI.");
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",
203 ni));
205 ami_test_var->sendc_foo (the_handler_var.in (),
207 "Let's talk AMI.");
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 (),
214 4711);
216 ami_test_var->sendc_get_yadda (the_handler_var.in ());
218 // End test of attributes
220 if (debug)
222 ACE_DEBUG ((LM_DEBUG,
223 "<%d> Asynchronous methods issued\n",
224 niterations));
227 if (debug)
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,
239 "Let's talk SMI.");
241 if (debug)
243 ACE_DEBUG ((LM_DEBUG,
244 "Received the following number: %d\n",
245 number));
248 if (shutdown_flag)
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
257 orb->destroy ();
259 catch (const CORBA::Exception& ex)
261 ex._tao_print_exception ("Caught exception:");
262 return 1;
265 ACE_END_TEST;
266 return 0;