2 //=============================================================================
6 * This is a simple client implementation.
8 * @author Irfan Pyarali
10 //=============================================================================
13 #include "ace/streams.h"
14 #include "ace/Get_Opt.h"
15 #include "ace/Profile_Timer.h"
17 #include "ace/OS_NS_string.h"
19 static ACE_TCHAR
*IOR
[7] = { 0, 0, 0, 0, 0, 0, 0 };
20 static int iterations
= 1;
23 parse_args (int argc
, ACE_TCHAR
**argv
)
25 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("a:b:c:d:e:f:i:"));
28 while ((c
= get_opts ()) != -1)
32 IOR
[1] = ACE_OS::strdup (get_opts
.opt_arg ());
35 IOR
[2] = ACE_OS::strdup (get_opts
.opt_arg ());
38 IOR
[3] = ACE_OS::strdup (get_opts
.opt_arg ());
41 IOR
[4] = ACE_OS::strdup (get_opts
.opt_arg ());
44 IOR
[5] = ACE_OS::strdup (get_opts
.opt_arg ());
47 IOR
[6] = ACE_OS::strdup (get_opts
.opt_arg ());
50 iterations
= ACE_OS::atoi (get_opts
.opt_arg ());
54 ACE_ERROR_RETURN ((LM_ERROR
,
67 // Indicates successful parsing of command line.
72 print_stats (ACE_Profile_Timer::ACE_Elapsed_Time
&elapsed_time
,
77 elapsed_time
.real_time
*= ACE_ONE_SECOND_IN_MSECS
;
78 elapsed_time
.user_time
*= ACE_ONE_SECOND_IN_MSECS
;
79 elapsed_time
.system_time
*= ACE_ONE_SECOND_IN_MSECS
;
81 elapsed_time
.real_time
/= iterations
;
82 elapsed_time
.user_time
/= iterations
;
83 elapsed_time
.system_time
/= iterations
;
85 double tmp
= 1000 / elapsed_time
.real_time
;
88 "\treal_time\t = %0.06f ms,\n"
89 "\tuser_time\t = %0.06f ms,\n"
90 "\tsystem_time\t = %0.06f ms,\n"
91 "\t%0.00f calls/second\n",
92 elapsed_time
.real_time
< 0.0 ? 0.0 : elapsed_time
.real_time
,
93 elapsed_time
.user_time
< 0.0 ? 0.0 : elapsed_time
.user_time
,
94 elapsed_time
.system_time
< 0.0 ? 0.0 : elapsed_time
.system_time
,
95 tmp
< 0.0 ? 0.0 : tmp
));
99 "\tNo time stats printed. Zero iterations or error occurred.\n"));
102 template <class T
, class T_var
>
106 static void run (CORBA::ORB_ptr orb
,
111 // Get an object reference from the argument string.
112 CORBA::Object_var object
= orb
->string_to_object (IOR
);
114 // Try to narrow the object reference to a reference.
115 T_var test
= T::_narrow (object
.in ());
117 ACE_Profile_Timer timer
;
118 ACE_Profile_Timer::ACE_Elapsed_Time elapsed_time
;
120 // We start an ACE_Profile_Timer here...
123 CORBA::Long result
= 0;
125 for (i
= 0; i
< iterations
; i
++)
127 // Invoke the doit() method on the reference.
128 result
= test
->doit ();
133 timer
.elapsed_time (elapsed_time
);
135 // compute average time.
136 print_stats (elapsed_time
, i
);
138 // Print the result of doit () method on the reference.
139 ACE_DEBUG ((LM_DEBUG
,
147 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
151 // Initialize the ORB
152 CORBA::ORB_var orb
= CORBA::ORB_init (argc
, argv
);
154 // Initialize options based on command-line arguments.
155 int parse_args_result
= parse_args (argc
, argv
);
156 if (parse_args_result
!= 0)
157 return parse_args_result
;
161 Test
<A
, A_var
>::run (orb
.in (),
164 Test
<Outer::B
, Outer::B_var
>::run (orb
.in (),
167 Test
<Outer::Inner::C
, Outer::Inner::C_var
>::run (orb
.in (),
170 Test
<A
, A_var
>::run (orb
.in (),
173 Test
<Outer::B
, Outer::B_var
>::run (orb
.in (),
176 Test
<Outer::Inner::C
, Outer::Inner::C_var
>::run (orb
.in (),
181 catch (const CORBA::Exception
& ex
)
183 ex
._tao_print_exception ("Exception Caught in main");