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
))
60 virtual int svc (void)
65 this->h_
->send_stuff ("Testing",
68 this->h_
->send_stuff ("Testing",
71 this->h_
->send_stuff ("Testing",
74 catch (const CORBA::COMM_FAILURE
& f
)
78 "(%P|%t) Caught COMM_FAILURE Exception\n"));
81 "(%P|%t) This is expected\n"));
85 catch (const CORBA::Exception
& ex
)
87 ex
._tao_print_exception ("Caught CORBA Exception\n");
90 "(%P|%t) Error in test\n"));
97 "(%P|%t) Caught a C++ exception\n"));
99 "(%P|%t) Error in test\n"));
111 class Shutdown_Task
: public ACE_Task_Base
114 Shutdown_Task (CORBA::ORB_ptr o
)
115 : o_ (CORBA::ORB::_duplicate (o
))
118 virtual int svc (void)
123 ACE_DEBUG ((LM_DEBUG
,
124 "(%P|%t) Calling shutdown\n"));
126 // Just wait for the main thread to start sending out
131 profile_timer
.start ();
133 this->o_
->shutdown (blocked
);
136 profile_timer
.stop ();
138 // Get the elampsed time
139 ACE_Profile_Timer::ACE_Elapsed_Time el
;
140 profile_timer
.elapsed_time (el
);
142 // The elapsed time is in secs
143 if (el
.real_time
> 1)
145 ACE_ERROR ((LM_ERROR
,
146 "(%P|%t) ERROR: Too long to shutdown\n"));
153 ACE_DEBUG ((LM_DEBUG
,
154 "(%P|%t) Caught exception during shutdown\n"));
156 ACE_ERROR ((LM_ERROR
,
157 "(%P|%t) Error in test\n"));
161 ACE_DEBUG ((LM_DEBUG
,
162 "(%P|%t) Returning from shutdown\n"));
170 try_main (int argc
, ACE_TCHAR
*argv
[])
176 CORBA::ORB_init (argc
, argv
);
178 if (parse_args (argc
, argv
) == false)
181 CORBA::Object_var tmp
=
182 orb
->string_to_object (ior
);
185 Hang::_narrow (tmp
.in ());
187 if (CORBA::is_nil (test
.in ()))
189 ACE_ERROR_RETURN ((LM_DEBUG
,
190 "Nil test reference <%s>\n",
195 Client_Task
ct (test
.in ());
197 if (ct
.activate (THR_NEW_LWP
| THR_JOINABLE
, 1) != 0)
198 ACE_ERROR_RETURN ((LM_ERROR
,
199 "Cannot activate client threads\n"),
202 ACE_DEBUG ((LM_DEBUG
,
203 "(%P|%t) Activating shutdown thread\n"));
205 Shutdown_Task
st (orb
.in ());
207 if (st
.activate (THR_NEW_LWP
| THR_JOINABLE
, 1) != 0)
208 ACE_ERROR_RETURN ((LM_ERROR
,
209 "Cannot activate shutdown threads\n"),
212 ACE_Thread_Manager::instance ()->wait ();
217 catch (const CORBA::Exception
& ex
)
219 ex
._tao_print_exception ("CORBA Exception caught\n");
220 ACE_ERROR ((LM_ERROR
,
221 "(%P|%t) Eror in test\n"));
226 ACE_DEBUG ((LM_DEBUG
,
227 "(%P|%t) Error in test\n"));
236 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
238 return Test::try_main (argc
, argv
);