2 #include "ace/Get_Opt.h"
3 #include "tao/ORB_Core.h"
4 #include "ace/Reactor.h"
5 #include "ace/Event_Handler.h"
7 const ACE_TCHAR
*ior
= ACE_TEXT ("file://test.ior");
10 int process_result
= 1;
12 int parse_args (int argc
, ACE_TCHAR
*argv
[])
14 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("k:i:t:"));
17 while ((c
= get_opts ()) != -1)
21 ior
= get_opts
.opt_arg ();
24 iterations
= ACE_OS::atoi(get_opts
.opt_arg ());
27 timeout
= ACE_OS::atoi(get_opts
.opt_arg ());
32 ACE_ERROR_RETURN ((LM_ERROR
,
41 // Indicates successful parsing of the command line
45 class PeriodicTask
: public ACE_Event_Handler
48 explicit PeriodicTask(CORBA::ORB_var orbIn
)
49 : ACE_Event_Handler(),
51 iterationsLeft(iterations
),
52 successfulConnections(0)
56 virtual ~PeriodicTask()
60 virtual int handle_timeout(const ACE_Time_Value
&, const void *)
67 "\n(%P|%t) - handling timeout with %d iterations left\n",
69 CORBA::Object_var tmp
= orb
->string_to_object(ior
);
71 Test::Hello_var hello
= Test::Hello::_narrow(tmp
.in ());
73 if (CORBA::is_nil (hello
.in ()))
75 ACE_ERROR_RETURN ((LM_DEBUG
,
76 "Nil Test::Hello reference <%s>\n",
81 CORBA::String_var the_string
= hello
->get_string ();
83 ++successfulConnections
;
84 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) - string returned <%C>\n",
89 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) - shutdown requested\n"));
91 catch (const CORBA::Exception
& ex
)
93 ex
._tao_print_exception ("Exception caught:");
98 if(successfulConnections
== 2)
109 PeriodicTask(const PeriodicTask
&);
110 PeriodicTask
& operator=(const PeriodicTask
&);
113 int successfulConnections
;
117 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
121 CORBA::ORB_var orb
= CORBA::ORB_init (argc
, argv
);
123 if (parse_args (argc
, argv
) != 0)
126 PeriodicTask
periodicTask(orb
);
128 orb
->orb_core()->reactor()->schedule_timer(&periodicTask
, 0, ACE_Time_Value::zero
, ACE_Time_Value(timeout
));
134 catch (const CORBA::Exception
& ex
)
136 ex
._tao_print_exception ("Exception caught:");
140 return process_result
;