2 //=============================================================================
6 * A very simple client which uses the AMI callback model.
8 * @author Johnny Willemsen <jwillemsen@remedy.nl>
10 //=============================================================================
13 #include "ace/Get_Opt.h"
16 #include "ami_testS.h"
17 #include "tao/Codeset/Codeset.h"
19 const ACE_TCHAR
*ior
= ACE_TEXT("file://test.ior");
21 int shutdown_flag
= 1;
26 parse_args (int argc
, ACE_TCHAR
*argv
[])
28 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("dk:"));
31 while ((c
= get_opts ()) != -1)
38 ior
= get_opts
.opt_arg ();
42 ACE_ERROR_RETURN ((LM_ERROR
,
49 // Indicates successful parsing of the command line
53 class Handler
: public POA_A::AMI_AMI_TestHandler
60 ~Handler () = default;
66 void foo_excep (::Messaging::ExceptionHolder
* excep_holder
)
69 "Callback method <foo_excep> called:\n"
70 "Testing proper exception handling ...\n"));
73 excep_holder
->raise_exception ();
75 catch (const A::DidTheRightThing
& ex
)
78 "... exception received successfully: <%d>\n",
80 #if defined(ACE_HAS_WCHAR) || defined(ACE_HAS_XPG4_MULTIBYTE_CHAR)
81 ACE_HEX_DUMP((LM_DEBUG
,
82 reinterpret_cast<char const *>(ex
.whatDidTheRightThing
.in()),
83 ACE_OS::strlen(ex
.whatDidTheRightThing
.in()) * sizeof(CORBA::WChar
)
86 CORBA::WChar
const* wstring
= L
"Hello world";
88 CORBA::WChar
const empty
[] = { 0 };
89 CORBA::WChar
const* wstring
= empty
;
91 if (ACE_OS::strcmp (wstring
, ex
.whatDidTheRightThing
.in()) != 0)
93 ex
._tao_print_exception ("ERROR");
95 "... caught the exception but got wrong wstring -> ERROR\n"));
99 catch (const CORBA::Exception
& ex
)
101 ex
._tao_print_exception ("ERROR");
102 ACE_ERROR ((LM_ERROR
,
103 "... caught the wrong exception -> ERROR\n"));
110 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
115 CORBA::ORB_init (argc
, argv
);
117 CORBA::Object_var object_var
=
118 orb
->resolve_initial_references ("RootPOA");
120 PortableServer::POA_var poa_var
=
121 PortableServer::POA::_narrow (object_var
.in ());
123 PortableServer::POAManager_var poa_manager_var
=
124 poa_var
->the_POAManager ();
126 poa_manager_var
->activate ();
128 if (parse_args (argc
, argv
) != 0)
131 // We reuse the object_var smart pointer!
132 object_var
= orb
->string_to_object (ior
);
134 A::AMI_Test_var ami_test_var
=
135 A::AMI_Test::_narrow (object_var
.in ());
137 if (CORBA::is_nil (ami_test_var
.in ()))
139 ACE_ERROR_RETURN ((LM_ERROR
,
140 "Object reference <%s> is nil.\n",
145 // Instantiate the ReplyHandler and register that with the POA.
147 PortableServer::ObjectId_var id
=
148 poa_var
->activate_object (&handler
);
150 CORBA::Object_var object
= poa_var
->id_to_reference (id
.in ());
152 A::AMI_AMI_TestHandler_var the_handler_var
=
153 A::AMI_AMI_TestHandler::_narrow (object
.in ());
155 // Trigger the DidTheRightThing exception on the server side
156 // by sending 0 to it.
157 ACE_DEBUG ((LM_DEBUG
,
158 "Sending asynch message\n"));
160 ami_test_var
->sendc_foo (the_handler_var
.in (), 0);
164 ACE_DEBUG ((LM_DEBUG
,
165 "Issuing a synchronous method to collect the AMI replies\n"));
168 ami_test_var
->foo (1);
172 ami_test_var
->shutdown ();
175 poa_var
->destroy (1, // ethernalize objects
176 0); // wait for completion
180 catch (const CORBA::Exception
& ex
)
182 ex
._tao_print_exception ("Caught exception:");