2 #include "ace/Get_Opt.h"
4 #include "ace/Profile_Timer.h"
5 #include "ace/OS_NS_unistd.h"
9 const ACE_TCHAR
*ior
= ACE_TEXT("file://server.ior");
11 ACE_Profile_Timer profile_timer
;
15 parse_args (int argc
, ACE_TCHAR
*argv
[])
17 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("b:k:"));
20 while ((c
= get_opts ()) != -1)
26 ACE_OS::atoi (get_opts
.opt_arg ());
36 ior
= get_opts
.opt_arg ();
41 ACE_ERROR_RETURN ((LM_ERROR
,
49 // Indicates successful parsing of the command line
53 class Client_Task
: public ACE_Task_Base
56 Client_Task (Hang_ptr h
)
57 : h_ (Hang::_duplicate (h
))
64 this->h_
->send_stuff ("Testing",
67 this->h_
->send_stuff ("Testing",
70 this->h_
->send_stuff ("Testing",
73 catch (const CORBA::COMM_FAILURE
& f
)
77 "(%P|%t) Caught COMM_FAILURE Exception\n"));
80 "(%P|%t) This is expected\n"));
84 catch (const CORBA::Exception
& ex
)
86 ex
._tao_print_exception ("Caught CORBA Exception\n");
89 "(%P|%t) Error in test\n"));
96 "(%P|%t) Caught a C++ exception\n"));
98 "(%P|%t) Error in test\n"));
110 class Shutdown_Task
: public ACE_Task_Base
113 Shutdown_Task (CORBA::ORB_ptr o
)
114 : o_ (CORBA::ORB::_duplicate (o
))
121 ACE_DEBUG ((LM_DEBUG
,
122 "(%P|%t) Calling shutdown\n"));
124 // Just wait for the main thread to start sending out
129 profile_timer
.start ();
131 this->o_
->shutdown (blocked
);
134 profile_timer
.stop ();
136 // Get the elampsed time
137 ACE_Profile_Timer::ACE_Elapsed_Time el
;
138 profile_timer
.elapsed_time (el
);
140 // The elapsed time is in secs
141 if (el
.real_time
> 1)
143 ACE_ERROR ((LM_ERROR
,
144 "(%P|%t) ERROR: Too long to shutdown\n"));
151 ACE_DEBUG ((LM_DEBUG
,
152 "(%P|%t) Caught exception during shutdown\n"));
154 ACE_ERROR ((LM_ERROR
,
155 "(%P|%t) Error in test\n"));
159 ACE_DEBUG ((LM_DEBUG
,
160 "(%P|%t) Returning from shutdown\n"));
168 try_main (int argc
, ACE_TCHAR
*argv
[])
173 CORBA::ORB_init (argc
, argv
);
175 if (parse_args (argc
, argv
) == false)
178 CORBA::Object_var tmp
=
179 orb
->string_to_object (ior
);
182 Hang::_narrow (tmp
.in ());
184 if (CORBA::is_nil (test
.in ()))
186 ACE_ERROR_RETURN ((LM_DEBUG
,
187 "Nil test reference <%s>\n",
192 Client_Task
ct (test
.in ());
194 if (ct
.activate (THR_NEW_LWP
| THR_JOINABLE
, 1) != 0)
195 ACE_ERROR_RETURN ((LM_ERROR
,
196 "Cannot activate client threads\n"),
199 ACE_DEBUG ((LM_DEBUG
,
200 "(%P|%t) Activating shutdown thread\n"));
202 Shutdown_Task
st (orb
.in ());
204 if (st
.activate (THR_NEW_LWP
| THR_JOINABLE
, 1) != 0)
205 ACE_ERROR_RETURN ((LM_ERROR
,
206 "Cannot activate shutdown threads\n"),
209 ACE_Thread_Manager::instance ()->wait ();
213 catch (const CORBA::Exception
& ex
)
215 ex
._tao_print_exception ("CORBA Exception caught\n");
216 ACE_ERROR ((LM_ERROR
,
217 "(%P|%t) Eror in test\n"));
222 ACE_DEBUG ((LM_DEBUG
,
223 "(%P|%t) Error in test\n"));
232 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
234 return Test::try_main (argc
, argv
);