2 #include "ace/Get_Opt.h"
3 #include "tao/ORB_Core.h"
5 #include "tao/RTCORBA/RTCORBA.h"
6 #include "tao/RTPortableServer/RTPortableServer.h"
7 #include "../check_supported_priorities.cpp"
9 class Test_i
: public POA_Test
12 // An implementation for the Test interface in test.idl
15 Test_i (CORBA::ORB_ptr orb
);
18 void test_method (CORBA::Short priority
);
20 //FUZZ: disable check_for_lack_ACE_OS
22 //FUZZ: enable check_for_lack_ACE_OS
29 Test_i::Test_i (CORBA::ORB_ptr orb
)
30 : orb_ (CORBA::ORB::_duplicate (orb
))
35 Test_i::test_method (CORBA::Short priority
)
37 // Use RTCurrent to find out the CORBA priority of the current
40 CORBA::Object_var obj
=
41 this->orb_
->resolve_initial_references ("RTCurrent");
43 RTCORBA::Current_var current
=
44 RTCORBA::Current::_narrow (obj
.in ());
46 if (CORBA::is_nil (obj
.in ()))
47 throw CORBA::INTERNAL ();
49 CORBA::Short servant_thread_priority
=
50 current
->the_priority ();
52 // Print out the info.
53 if (servant_thread_priority
!= priority
)
55 "ERROR: servant thread priority is not equal"
56 "to method argument.\n"));
59 "Server_Declared priority: %d "
60 "Servant thread priority: %d\n",
61 priority
, servant_thread_priority
));
65 Test_i::shutdown (void)
67 this->orb_
->shutdown (0);
70 //*************************************************************************
72 const ACE_TCHAR
*ior_output_file1
= ACE_TEXT("test1.ior");
73 const ACE_TCHAR
*ior_output_file2
= ACE_TEXT("test2.ior");
74 CORBA::Short poa_priority
= -1;
75 CORBA::Short object_priority
= -1;
77 // Parse command-line arguments.
79 parse_args (int argc
, ACE_TCHAR
*argv
[])
81 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("p:o:a:b:"));
84 while ((c
= get_opts ()) != -1)
88 ior_output_file1
= get_opts
.opt_arg ();
92 ior_output_file2
= get_opts
.opt_arg ();
96 result
= ::sscanf (ACE_TEXT_ALWAYS_CHAR (get_opts
.opt_arg ()),
99 if (result
== 0 || result
== EOF
)
100 ACE_ERROR_RETURN ((LM_ERROR
,
101 "Unable to process <-a> option"),
106 result
= ::sscanf (ACE_TEXT_ALWAYS_CHAR (get_opts
.opt_arg ()),
109 if (result
== 0 || result
== EOF
)
110 ACE_ERROR_RETURN ((LM_ERROR
,
111 "Unable to process <-b> option"),
117 ACE_ERROR_RETURN ((LM_ERROR
,
122 "-b <object_priority> "
129 || object_priority
< 0)
130 ACE_ERROR_RETURN ((LM_ERROR
,
131 "Valid poa and object priorities must be"
132 " specified.\nSee README file for more info\n"),
139 check_for_nil (CORBA::Object_ptr obj
, const char *msg
)
141 if (CORBA::is_nil (obj
))
142 ACE_ERROR_RETURN ((LM_ERROR
,
143 "ERROR: Object reference <%C> is nil\n",
151 create_object (RTPortableServer::POA_ptr poa
,
154 CORBA::Short priority
,
155 const ACE_TCHAR
*filename
)
157 // Register with poa.
158 PortableServer::ObjectId_var id
;
161 id
= poa
->activate_object_with_priority (server_impl
,
164 id
= poa
->activate_object (server_impl
);
167 CORBA::Object_var server
=
168 poa
->id_to_reference (id
.in ());
170 // Print out the IOR.
171 CORBA::String_var ior
=
172 orb
->object_to_string (server
.in ());
174 ACE_DEBUG ((LM_DEBUG
, "<%C>\n\n", ior
.in ()));
176 // Print ior to the file.
179 FILE *output_file
= ACE_OS::fopen (filename
, "w");
180 if (output_file
== 0)
181 ACE_ERROR_RETURN ((LM_ERROR
,
182 "Cannot open output file for writing IOR: %s",
185 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
186 ACE_OS::fclose (output_file
);
192 class Task
: public ACE_Task_Base
196 Task (ACE_Thread_Manager
&thread_manager
,
205 Task::Task (ACE_Thread_Manager
&thread_manager
,
207 : ACE_Task_Base (&thread_manager
),
208 orb_ (CORBA::ORB::_duplicate (orb
))
218 CORBA::Object_var object
=
219 this->orb_
->resolve_initial_references ("RTORB");
220 RTCORBA::RTORB_var rt_orb
= RTCORBA::RTORB::_narrow (object
.in ());
221 if (check_for_nil (rt_orb
.in (), "RTORB") == -1)
226 this->orb_
->resolve_initial_references("RootPOA");
227 PortableServer::POA_var root_poa
=
228 PortableServer::POA::_narrow (object
.in ());
229 if (check_for_nil (root_poa
.in (), "RootPOA") == -1)
233 PortableServer::POAManager_var poa_manager
=
234 root_poa
->the_POAManager ();
236 // Create child POA with SERVER_DECLARED PriorityModelPolicy,
237 // and MULTIPLE_ID id uniqueness policy (so we can use one
238 // servant to create several objects).
239 CORBA::PolicyList poa_policy_list
;
240 poa_policy_list
.length (2);
242 rt_orb
->create_priority_model_policy (RTCORBA::SERVER_DECLARED
,
246 root_poa
->create_id_uniqueness_policy (PortableServer::MULTIPLE_ID
);
248 PortableServer::POA_var child_poa
=
249 root_poa
->create_POA ("Child_POA",
253 RTPortableServer::POA_var rt_poa
=
254 RTPortableServer::POA::_narrow (child_poa
.in ());
255 if (check_for_nil (rt_poa
.in (), "RTPOA") == -1)
259 Test_i
server_impl (this->orb_
.in ());
261 // Create object 1 (it will inherit POA's priority).
263 ACE_DEBUG ((LM_DEBUG
, "\nActivated object one as "));
264 result
= create_object (rt_poa
.in (), this->orb_
.in (), &server_impl
,
265 -1, ior_output_file1
);
269 // Create object 2 (override POA's priority).
270 ACE_DEBUG ((LM_DEBUG
, "\nActivated object two as "));
271 result
= create_object (rt_poa
.in (), this->orb_
.in (), &server_impl
,
272 object_priority
, ior_output_file2
);
276 // Activate POA manager.
277 poa_manager
->activate ();
279 // Start ORB event loop.
282 ACE_DEBUG ((LM_DEBUG
, "Server ORB event loop finished\n\n"));
284 catch (const CORBA::Exception
& ex
)
286 ex
._tao_print_exception (
287 "Unexpected exception caught in Server_Declared test server:");
295 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
301 CORBA::ORB_init (argc
, argv
);
304 if (parse_args (argc
, argv
) != 0)
307 // Make sure we can support multiple priorities that are required
309 if (!check_supported_priorities (orb
.in ()))
312 // Thread Manager for managing task.
313 ACE_Thread_Manager thread_manager
;
316 Task
task (thread_manager
,
319 // Task activation flags.
323 orb
->orb_core ()->orb_params ()->thread_creation_flags ();
327 task
.activate (flags
);
332 ACE_ERROR_RETURN ((LM_ERROR
,
333 "Cannot create thread with scheduling policy %s\n"
334 "because the user does not have the appropriate privileges, terminating program....\n"
335 "Check svc.conf options and/or run as root\n",
336 sched_policy_name (orb
->orb_core ()->orb_params ()->ace_sched_policy ())),
344 // Wait for task to exit.
346 thread_manager
.wait ();
347 ACE_ASSERT (result
!= -1);
349 catch (const CORBA::Exception
& ex
)
351 ex
._tao_print_exception ("Exception caught");