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 "ace/Get_Opt.h"
17 #include "ami_testS.h"
19 const ACE_TCHAR
*ior
= ACE_TEXT("file://test.ior");
20 int shutdown_flag
= 0;
25 parse_args (int argc
, ACE_TCHAR
*argv
[])
27 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("dk:x"));
30 while ((c
= get_opts ()) != -1)
37 ior
= get_opts
.opt_arg ();
44 ACE_ERROR_RETURN ((LM_ERROR
,
52 // Indicates successful parsing of the command line
56 class Handler
: public POA_A::AMI_AMI_TestHandler
63 ~Handler () = default;
65 void get_yadda (CORBA::Long result
)
68 "Error: Callback method <get_yadda> called: result <%d>\n",
73 void get_yadda_excep (::Messaging::ExceptionHolder
*excep_holder
)
76 "Callback method <get_yadda_excep> called:\n"));
79 excep_holder
->raise_exception ();
81 catch (const A::DidTheRightThingB
& ex
)
84 "... exception received successfully\n"));
88 "ERROR: ex.id not 42: %d\n",
92 if (ACE_OS::strcmp (ex
.whatDidTheRightThing
.in (), "Hello world") != 0)
95 "ERROR: ex.whatDidTheRightThing not ok: <%C>\n",
96 ex
.whatDidTheRightThing
.in ()));
100 catch (const CORBA::Exception
& ex
)
102 ex
._tao_print_exception ("ERROR");
103 ACE_ERROR ((LM_ERROR
,
104 "... caught the wrong exception -> ERROR\n"));
110 ACE_ERROR ((LM_ERROR
,
111 "Error: Callback method <set_yadda> called:\n"));
115 void set_yadda_excep (::Messaging::ExceptionHolder
*excep_holder
)
117 ACE_DEBUG ((LM_DEBUG
,
118 "Callback method <set_yadda_excep> called:\n"));
121 excep_holder
->raise_exception ();
123 catch (const A::DidTheRightThing
& ex
)
125 ACE_DEBUG ((LM_DEBUG
,
126 "... exception received successfully\n"));
129 ACE_ERROR ((LM_ERROR
,
130 "ERROR: ex.id not 42: %d\n",
134 if (ACE_OS::strcmp (ex
.whatDidTheRightThing
.in (), "Hello world") != 0)
136 ACE_ERROR ((LM_ERROR
,
137 "ERROR: ex.whatDidTheRightThing not ok: <%C>\n",
138 ex
.whatDidTheRightThing
.in ()));
142 catch (const CORBA::Exception
& ex
)
144 ex
._tao_print_exception ("ERROR");
145 ACE_ERROR ((LM_ERROR
,
146 "... caught the wrong exception -> ERROR\n"));
150 void get_dadda (CORBA::Long result
)
152 ACE_ERROR ((LM_ERROR
,
153 "Error: Callback method <get_dadda> called: result <%d>\n",
158 void get_dadda_excep (::Messaging::ExceptionHolder
*excep_holder
)
160 ACE_DEBUG ((LM_DEBUG
,
161 "Callback method <get_dadda_excep> called:\n"));
164 excep_holder
->raise_exception ();
166 catch (const A::DidTheRightThing
& ex
)
168 ACE_DEBUG ((LM_DEBUG
,
169 "... exception received successfully\n"));
172 ACE_ERROR ((LM_ERROR
,
173 "ERROR: ex.id not 42: %d\n",
177 if (ACE_OS::strcmp (ex
.whatDidTheRightThing
.in (), "Hello world") != 0)
179 ACE_ERROR ((LM_ERROR
,
180 "ERROR: ex.whatDidTheRightThing not ok: <%C>\n",
181 ex
.whatDidTheRightThing
.in ()));
185 catch (const CORBA::Exception
& ex
)
187 ex
._tao_print_exception ("ERROR");
188 ACE_ERROR ((LM_ERROR
,
189 "... caught the wrong exception -> ERROR\n"));
193 void inout_arg_test (const char *)
195 ACE_DEBUG ((LM_DEBUG
,
196 "Callback method <set_yadda_excep> called:\n"));
199 void inout_arg_test_excep (::Messaging::ExceptionHolder
*)
205 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
210 CORBA::ORB_init (argc
, argv
);
212 CORBA::Object_var object_var
=
213 orb
->resolve_initial_references ("RootPOA");
215 PortableServer::POA_var poa_var
=
216 PortableServer::POA::_narrow (object_var
.in ());
218 PortableServer::POAManager_var poa_manager_var
=
219 poa_var
->the_POAManager ();
221 poa_manager_var
->activate ();
223 if (parse_args (argc
, argv
) != 0)
226 // We reuse the object_var smart pointer!
227 object_var
= orb
->string_to_object (ior
);
229 A::AMI_Test_var ami_test_var
=
230 A::AMI_Test::_narrow (object_var
.in ());
232 if (CORBA::is_nil (ami_test_var
.in ()))
234 ACE_ERROR_RETURN ((LM_ERROR
,
235 "Object reference <%s> is nil.\n",
240 // Instantiate the ReplyHandler and register that with the POA.
242 PortableServer::ObjectId_var id
=
243 poa_var
->activate_object (&handler
);
245 CORBA::Object_var object
= poa_var
->id_to_reference (id
.in ());
247 A::AMI_AMI_TestHandler_var the_handler_var
=
248 A::AMI_AMI_TestHandler::_narrow (object
.in ());
250 // Begin test of attributes
251 ami_test_var
->sendc_get_yadda (the_handler_var
.in ());
253 ami_test_var
->sendc_set_yadda (the_handler_var
.in (), 4711);
255 ami_test_var
->sendc_get_yadda (the_handler_var
.in ());
257 ami_test_var
->sendc_get_dadda (the_handler_var
.in ());
258 // End test of attributes
262 ACE_DEBUG ((LM_DEBUG
,
263 "Issuing a synchronous method to collect the AMI replies\n"));
266 CORBA::String_var mystring
= CORBA::string_dup ("Hello");
268 ami_test_var
->inout_arg_test (mystring
.inout ());
272 ami_test_var
->shutdown ();
275 poa_var
->destroy (1, // ethernalize objects
276 0); // wait for completion
280 catch (const CORBA::Exception
& ex
)
282 ex
._tao_print_exception ("Caught exception:");