Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / RTCORBA / Policy_Combinations / client.cpp
blob5819b2d4553aaee18341e7aa75c51b7de67ff110
1 #include "ace/Get_Opt.h"
2 #include "ace/Task.h"
3 #include "testC.h"
4 #include "tao/ORB_Core.h"
5 #include "tao/RTCORBA/RTCORBA.h"
6 #include "../check_supported_priorities.cpp"
8 static const ACE_TCHAR *ior = 0;
9 static int iterations = 5;
10 static int shutdown_server = 0;
11 static RTCORBA::Priority default_thread_priority;
13 static int
14 parse_args (int argc, ACE_TCHAR **argv)
16 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:i:x"));
17 int c;
19 while ((c = get_opts ()) != -1)
20 switch (c)
22 case 'k':
23 ior = get_opts.opt_arg ();
24 break;
26 case 'i':
27 iterations = ACE_OS::atoi (get_opts.opt_arg ());
28 break;
30 case 'x':
31 shutdown_server = 1;
32 break;
34 case '?':
35 default:
36 ACE_ERROR_RETURN ((LM_ERROR,
37 "usage: %s "
38 "-k ior "
39 "-i iterations "
40 "-x shutdown server "
41 "\n",
42 argv [0]),
43 -1);
46 if (ior == 0)
47 ACE_ERROR_RETURN ((LM_ERROR,
48 "An IOR must be specified\n"),
49 -1);
51 return 0;
54 class Task : public ACE_Task_Base
56 public:
57 Task (ACE_Thread_Manager &thread_manager,
58 CORBA::ORB_ptr orb);
60 int svc ();
62 CORBA::ORB_var orb_;
65 Task::Task (ACE_Thread_Manager &thread_manager,
66 CORBA::ORB_ptr orb)
67 : ACE_Task_Base (&thread_manager),
68 orb_ (CORBA::ORB::_duplicate (orb))
72 int
73 Task::svc ()
75 try
77 CORBA::Object_var object =
78 this->orb_->resolve_initial_references ("RTCurrent");
80 RTCORBA::Current_var current =
81 RTCORBA::Current::_narrow (object.in ());
83 default_thread_priority =
84 get_implicit_thread_CORBA_priority (this->orb_.in ());
86 object =
87 this->orb_->string_to_object (ior);
89 test_var test =
90 test::_narrow (object.in ());
92 for (int i = 0; i < iterations; i++)
94 current->the_priority (default_thread_priority);
96 CORBA::Short priority =
97 test->method ();
99 if (priority != TAO_INVALID_PRIORITY)
101 current->the_priority (priority);
103 test->prioritized_method ();
107 if (shutdown_server)
109 test->shutdown ();
112 catch (const CORBA::Exception& ex)
114 ex._tao_print_exception ("Unexpected exception!");
115 return -1;
118 return 0;
122 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
126 CORBA::ORB_var orb =
127 CORBA::ORB_init (argc, argv);
129 int result =
130 parse_args (argc, argv);
131 if (result != 0)
132 return result;
134 // Make sure we can support multiple priorities that are required
135 // for this test.
136 if (!check_supported_priorities (orb.in ()))
137 return 2;
139 // The following finds out the lowest priority for this
140 // scheduling policy. This will give us the biggest range on NT
141 // since the default priority is 0 where as the lowest priority
142 // is -15.
143 int minimum_priority =
144 ACE_Sched_Params::priority_min (orb->orb_core ()->orb_params ()->ace_sched_policy ());
146 // Thread Manager for managing task.
147 ACE_Thread_Manager thread_manager;
149 // Create task.
150 Task task (thread_manager,
151 orb.in ());
153 // Task activation flags.
154 long flags =
155 THR_NEW_LWP |
156 THR_JOINABLE |
157 orb->orb_core ()->orb_params ()->thread_creation_flags ();
159 // Activate task.
160 result =
161 task.activate (flags,
162 1, 0,
163 minimum_priority);
164 if (result == -1)
166 if (errno == EPERM)
168 ACE_ERROR_RETURN ((LM_ERROR,
169 "Cannot create thread with scheduling policy %C\n"
170 "because the user does not have the appropriate privileges, terminating program....\n"
171 "Check svc.conf options and/or run as root\n",
172 sched_policy_name (orb->orb_core ()->orb_params ()->ace_sched_policy ())),
175 else
176 // Unexpected error.
177 ACE_ASSERT (0);
180 // Wait for task to exit.
181 result =
182 thread_manager.wait ();
183 ACE_ASSERT (result != -1);
185 catch (const CORBA::Exception& ex)
187 ex._tao_print_exception ("Unexpected exception!");
188 return -1;
191 return 0;