Merge pull request #2222 from jwillemsen/jwi-dllexportwarning
[ACE_TAO.git] / TAO / tests / POA / TIE / client.cpp
blob857df3753e19dfe79ee2904fa6625c058d46daf8
2 //=============================================================================
3 /**
4 * @file client.cpp
6 * This is a simple client implementation.
8 * @author Irfan Pyarali
9 */
10 //=============================================================================
13 #include "ace/streams.h"
14 #include "ace/Get_Opt.h"
15 #include "ace/Profile_Timer.h"
16 #include "testC.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;
22 static int
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:"));
26 int c;
28 while ((c = get_opts ()) != -1)
29 switch (c)
31 case 'a':
32 IOR[1] = ACE_OS::strdup (get_opts.opt_arg ());
33 break;
34 case 'b':
35 IOR[2] = ACE_OS::strdup (get_opts.opt_arg ());
36 break;
37 case 'c':
38 IOR[3] = ACE_OS::strdup (get_opts.opt_arg ());
39 break;
40 case 'd':
41 IOR[4] = ACE_OS::strdup (get_opts.opt_arg ());
42 break;
43 case 'e':
44 IOR[5] = ACE_OS::strdup (get_opts.opt_arg ());
45 break;
46 case 'f':
47 IOR[6] = ACE_OS::strdup (get_opts.opt_arg ());
48 break;
49 case 'i':
50 iterations = ACE_OS::atoi (get_opts.opt_arg ());
51 break;
52 case '?':
53 default:
54 ACE_ERROR_RETURN ((LM_ERROR,
55 "usage: %s "
56 "-a IOR 1 "
57 "-b IOR 2 "
58 "-c IOR 3 "
59 "-d IOR 4 "
60 "-e IOR 5 "
61 "-f IOR 6 "
62 "\n",
63 argv [0]),
64 -1);
67 // Indicates successful parsing of command line.
68 return 0;
71 void
72 print_stats (ACE_Profile_Timer::ACE_Elapsed_Time &elapsed_time,
73 int iterations)
75 if (iterations > 0)
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;
87 ACE_DEBUG ((LM_DEBUG,
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));
97 else
98 ACE_ERROR ((LM_ERROR,
99 "\tNo time stats printed. Zero iterations or error occurred.\n"));
102 template <class T, class T_var>
103 class Test
105 public:
106 static void run (CORBA::ORB_ptr orb,
107 ACE_TCHAR *IOR)
109 if (IOR != 0)
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...
121 timer.start ();
123 CORBA::Long result = 0;
124 int i = 0;
125 for (i = 0; i < iterations ; i++)
127 // Invoke the doit() method on the reference.
128 result = test->doit ();
131 // stop the timer.
132 timer.stop ();
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,
140 "%d\n",
141 result));
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;
159 int i = 1;
161 Test<A, A_var>::run (orb.in (),
162 IOR[i++]);
164 Test<Outer::B, Outer::B_var>::run (orb.in (),
165 IOR[i++]);
167 Test<Outer::Inner::C, Outer::Inner::C_var>::run (orb.in (),
168 IOR[i++]);
170 Test<A, A_var>::run (orb.in (),
171 IOR[i++]);
173 Test<Outer::B, Outer::B_var>::run (orb.in (),
174 IOR[i++]);
176 Test<Outer::Inner::C, Outer::Inner::C_var>::run (orb.in (),
177 IOR[i++]);
179 orb->destroy ();
181 catch (const CORBA::Exception& ex)
183 ex._tao_print_exception ("Exception Caught in main");
184 return -1;
186 return 0;