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"
18 const ACE_TCHAR
*ior
= ACE_TEXT("file://test.ior");
20 int shutdown_flag
= 0;
22 CORBA::ULong payload_size
= 128000;
25 parse_args (int argc
, ACE_TCHAR
*argv
[])
27 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("db:k:i:x"));
30 while ((c
= get_opts ()) != -1)
37 ior
= get_opts
.opt_arg ();
40 niterations
= ACE_OS::atoi (get_opts
.opt_arg ());
46 payload_size
= ACE_OS::atoi (get_opts
.opt_arg ());
50 ACE_ERROR_RETURN ((LM_ERROR
,
60 // Indicates successful parsing of the command line
64 class Handler
: public POA_A::AMI_AMI_TestHandler
68 Handler () : reply_count_ (0) {};
71 ~Handler () = default;
73 /// Get the reply count
74 long reply_count () const
76 return reply_count_
.value ();
79 void foo (CORBA::Long ami_return_val
,
86 "Callback method <foo> called: result <%d>, out_arg <%d>\n",
92 void foo_excep (::Messaging::ExceptionHolder
* excep_holder
)
97 "Callback method <foo_excep> called:\n"
98 "Testing proper exception handling ...\n"));
101 excep_holder
->raise_exception ();
103 catch (const CORBA::Exception
&)
105 ACE_DEBUG ((LM_DEBUG
,
106 "... caught the wrong exception -> ERROR\n"));
111 ACE_Atomic_Op
<TAO_SYNCH_MUTEX
, long> reply_count_
;
115 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
120 CORBA::ORB_init (argc
, argv
);
122 CORBA::Object_var object_var
=
123 orb
->resolve_initial_references ("RootPOA");
125 PortableServer::POA_var poa_var
=
126 PortableServer::POA::_narrow (object_var
.in ());
128 PortableServer::POAManager_var poa_manager_var
=
129 poa_var
->the_POAManager ();
131 poa_manager_var
->activate ();
133 if (parse_args (argc
, argv
) != 0)
136 // We reuse the object_var smart pointer!
137 CORBA::Object_var ior_object
= orb
->string_to_object (ior
);
139 A::AMI_Test_var ami_test_var
=
140 A::AMI_Test::_narrow (ior_object
.in ());
142 if (CORBA::is_nil (ami_test_var
.in ()))
144 ACE_ERROR_RETURN ((LM_ERROR
,
145 "Object reference <%s> is nil.\n",
150 // Instantiate the ReplyHandler and register that with the POA.
152 PortableServer::ObjectId_var id
=
153 poa_var
->activate_object (&handler
);
155 CORBA::Object_var object
= poa_var
->id_to_reference (id
.in ());
157 A::AMI_AMI_TestHandler_var the_handler_var
=
158 A::AMI_AMI_TestHandler::_narrow (object
.in ());
160 CORBA::Long l
= 931247;
161 A::Payload
payload (payload_size
);
162 payload
.length (payload_size
);
164 for (CORBA::ULong j
= 0; j
!= payload_size
; ++j
)
166 payload
[j
] = j
% 256;
169 for (ssize_t ni
= 0; ni
< niterations
; ni
++)
173 ACE_DEBUG ((LM_DEBUG
,
174 "Sending asynch message: %d\n",
178 ami_test_var
->sendc_foo (the_handler_var
.in (),
186 ACE_DEBUG ((LM_DEBUG
,
187 "<%d> Asynchronous methods issued\n",
193 ACE_DEBUG ((LM_DEBUG
,
194 "Issuing a synchronous method to collect the AMI replies\n"));
197 CORBA::Long number
= ami_test_var
->foo (l
,
204 ACE_DEBUG ((LM_DEBUG
,
205 "Received the following number: %d\n",
211 ami_test_var
->shutdown ();
214 poa_var
->destroy (1, // ethernalize objects
215 0); // wait for completion
219 catch (const CORBA::Exception
& ex
)
221 ex
._tao_print_exception ("Caught exception:");