Use =default for skeleton copy constructor
[ACE_TAO.git] / TAO / tests / RTCORBA / Thread_Pool / client.cpp
blob26ebd2508b169e45dbc0e2c54ae7740b2c3cc644
1 #include "ace/Get_Opt.h"
2 #include "testC.h"
3 #include "tao/RTCORBA/RTCORBA.h"
4 #include "tao/ORB_Core.h"
5 #include "ace/Task.h"
6 #include "ace/OS_NS_unistd.h"
7 #include "../check_supported_priorities.cpp"
9 const ACE_TCHAR *ior = ACE_TEXT("file://ior_1");
10 int iterations = 6;
11 int shutdown_server = 0;
13 int
14 parse_args (int argc, ACE_TCHAR *argv[])
16 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("xk:i:"));
17 int c;
19 while ((c = get_opts ()) != -1)
20 switch (c)
22 case 'x':
23 shutdown_server = 1;
24 break;
26 case 'k':
27 ior = get_opts.opt_arg ();
28 break;
30 case 'i':
31 iterations = ACE_OS::atoi (get_opts.opt_arg ());
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 // Indicates successful parsing of the command line
47 return 0;
50 class Task : public ACE_Task_Base
52 public:
53 Task (ACE_Thread_Manager &thread_manager,
54 CORBA::ORB_ptr orb);
56 int svc ();
58 CORBA::ORB_var orb_;
61 Task::Task (ACE_Thread_Manager &thread_manager,
62 CORBA::ORB_ptr orb)
63 : ACE_Task_Base (&thread_manager),
64 orb_ (CORBA::ORB::_duplicate (orb))
68 int
69 Task::svc ()
71 try
73 CORBA::Object_var object =
74 this->orb_->string_to_object (ior);
76 test_var test =
77 test::_narrow (object.in ());
79 object =
80 this->orb_->resolve_initial_references ("RTCurrent");
82 RTCORBA::Current_var current =
83 RTCORBA::Current::_narrow (object.in ());
85 // We need to set the client thread CORBA priority
86 current->the_priority (get_implicit_thread_CORBA_priority (this->orb_.in ()));
88 pid_t pid =
89 ACE_OS::getpid ();
91 for (int i = 0; i != iterations; ++i)
93 CORBA::Long r =
94 test->method (pid,
95 i);
97 ACE_ASSERT (r == i);
98 // Assert disappears on with optimizations on.
99 ACE_UNUSED_ARG (r);
102 if (shutdown_server)
104 test->shutdown ();
107 catch (const CORBA::Exception& ex)
109 ex._tao_print_exception ("Exception caught:");
110 return -1;
113 return 0;
117 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
121 CORBA::ORB_var orb =
122 CORBA::ORB_init (argc, argv);
124 int result =
125 parse_args (argc, argv);
126 if (result != 0)
127 return result;
129 // Thread Manager for managing task.
130 ACE_Thread_Manager thread_manager;
132 // Create task.
133 Task task (thread_manager,
134 orb.in ());
136 // Task activation flags.
137 long flags =
138 THR_NEW_LWP |
139 THR_JOINABLE |
140 orb->orb_core ()->orb_params ()->thread_creation_flags ();
142 // Activate task.
143 result =
144 task.activate (flags);
145 if (result == -1)
147 if (errno == EPERM)
149 ACE_ERROR_RETURN ((LM_ERROR,
150 "Cannot create thread with scheduling policy %s\n"
151 "because the user does not have the appropriate privileges, terminating program....\n"
152 "Check svc.conf options and/or run as root\n",
153 sched_policy_name (orb->orb_core ()->orb_params ()->ace_sched_policy ())),
156 else
157 // Unexpected error.
158 ACE_ASSERT (0);
161 // Wait for task to exit.
162 result =
163 thread_manager.wait ();
164 ACE_ASSERT (result != -1);
166 catch (const CORBA::Exception& ex)
168 ex._tao_print_exception ("Exception caught");
169 return -1;
172 return 0;