3 #include "tao/Messaging/Messaging.h"
4 #include "tao/AnyTypeCode/Any.h"
5 #include "tao/AnyTypeCode/TAOA.h"
7 #include "tao/Object_T.h"
8 #include "ace/Get_Opt.h"
10 #include "ace/OS_NS_time.h"
13 int niterations
= 100;
16 parse_args (int argc
, ACE_TCHAR
*argv
[])
18 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("n:i:"));
21 while ((c
= get_opts ()) != -1)
25 nthreads
= ACE_OS::atoi (get_opts
.opt_arg ());
28 niterations
= ACE_OS::atoi (get_opts
.opt_arg ());
32 ACE_ERROR_RETURN ((LM_ERROR
,
40 // Indicates successful parsing of the command line
45 * Run the client thread
47 * Use the ACE_Task_Base class to run the client threads.
49 class Manipulation
: public ACE_Task_Base
52 Manipulation (CORBA::ORB_ptr orb
,
56 /// The thread entry point.
57 virtual int svc (void);
60 void perform_iteration (unsigned int *seed
,
61 CORBA::PolicyList_var
&policies
,
62 CORBA::PolicyManager_ptr policy_manager
,
63 CORBA::PolicyCurrent_ptr policy_current
);
69 /// The test object reference
72 /// The number of iterations on this thread
77 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
82 CORBA::ORB_init (argc
, argv
);
84 if (parse_args (argc
, argv
) != 0)
87 CORBA::Object_var object
=
88 orb
->string_to_object ("corbaloc:iiop:localhost:12345/FakeIOR");
91 TAO::Narrow_Utils
<Test
>::unchecked_narrow (object
.in ());
93 if (CORBA::is_nil (test
.in ()))
95 ACE_ERROR_RETURN ((LM_ERROR
,
96 "Object reference is nil\n"),
100 Manipulation
manipulation (orb
.in (),
103 if (manipulation
.activate (THR_NEW_LWP
| THR_JOINABLE
,
105 ACE_ERROR_RETURN ((LM_ERROR
,
106 "Cannot activate manipulation threads\n"),
109 manipulation
.thr_mgr ()->wait ();
111 ACE_DEBUG ((LM_DEBUG
, "threads finished\n"));
115 catch (const CORBA::Exception
& ex
)
117 ex
._tao_print_exception ("Caught exception:");
124 // ****************************************************************
126 Manipulation::Manipulation (CORBA::ORB_ptr orb
,
129 : orb_ (CORBA::ORB::_duplicate (orb
)),
130 test_ (Test::_duplicate (test
)),
131 niterations_ (niterations
)
136 Manipulation::perform_iteration (unsigned int *seed
,
137 CORBA::PolicyList_var
&policies
,
138 CORBA::PolicyManager_ptr policy_manager
,
139 CORBA::PolicyCurrent_ptr policy_current
)
143 int r
= ACE_OS::rand_r (seed
);
145 const int ADD_OBJECT_POLICY
= 0;
146 const int ADD_CURRENT_POLICY
= 1;
147 const int ADD_MANAGER_POLICY
= 2;
149 const int SET_OBJECT_POLICY
= 3;
150 const int SET_CURRENT_POLICY
= 4;
151 const int SET_MANAGER_POLICY
= 5;
153 const int SAVE_CURRENT_POLICIES
= 6;
154 const int RESTORE_CURRENT_POLICIES
= 7;
155 const int SAVE_MANAGER_POLICIES
= 8;
156 // const int RESTORE_MANAGER_POLICIES = 9;
157 const int LAST_OPERATION
= 10;
158 int operation
= r
% LAST_OPERATION
;
160 if (operation
== ADD_OBJECT_POLICY
161 || operation
== ADD_CURRENT_POLICY
162 || operation
== ADD_MANAGER_POLICY
163 || operation
== SET_OBJECT_POLICY
164 || operation
== SET_CURRENT_POLICY
165 || operation
== SET_MANAGER_POLICY
)
167 CORBA::Policy_var policy
;
170 CORBA::ULong policy_type
= 0;
172 int type
= ACE_OS::rand_r (seed
) % 3;
175 TimeBase::TimeT value
= 0;
179 Messaging::RELATIVE_RT_TIMEOUT_POLICY_TYPE
;
183 TAO::BufferingConstraint value
;
187 TAO::BUFFERING_CONSTRAINT_POLICY_TYPE
;
189 else // type == 2 (or something else)
191 Messaging::SyncScope value
= 0;
195 Messaging::SYNC_SCOPE_POLICY_TYPE
;
198 policy
= this->orb_
->create_policy (policy_type
,
201 CORBA::SetOverrideType override_type
= CORBA::SET_OVERRIDE
;
202 if (operation
== ADD_OBJECT_POLICY
203 || operation
== ADD_CURRENT_POLICY
204 || operation
== ADD_MANAGER_POLICY
)
206 override_type
= CORBA::ADD_OVERRIDE
;
209 CORBA::PolicyList
policy_list (1);
210 policy_list
.length (1);
211 policy_list
[0] = CORBA::Policy::_duplicate (policy
.in ());
213 if (operation
== ADD_OBJECT_POLICY
214 || operation
== SET_OBJECT_POLICY
)
216 CORBA::Object_var tmp
=
217 this->test_
->_set_policy_overrides (policy_list
,
220 else if (operation
== ADD_CURRENT_POLICY
221 || operation
== SET_CURRENT_POLICY
)
223 policy_current
->set_policy_overrides (policy_list
,
228 // operation == ADD_CURRENT_POLICY
229 // || operation == SET_CURRENT_POLICY)
230 policy_manager
->set_policy_overrides (policy_list
,
233 policy_list
[0]->destroy ();
235 else if (operation
== SAVE_CURRENT_POLICIES
)
237 CORBA::PolicyTypeSeq types
;
239 policy_current
->get_policy_overrides (types
);
241 else if (operation
== SAVE_MANAGER_POLICIES
)
243 CORBA::PolicyTypeSeq types
;
245 policy_manager
->get_policy_overrides (types
);
247 else if (operation
== RESTORE_CURRENT_POLICIES
)
249 if (policies
.ptr () != 0)
251 policy_current
->set_policy_overrides (policies
.in (),
252 CORBA::SET_OVERRIDE
);
255 else // operation == RESTORE_MANAGER_POLICIES)
257 if (policies
.ptr () != 0)
259 policy_manager
->set_policy_overrides (policies
.in (),
260 CORBA::SET_OVERRIDE
);
264 catch (const CORBA::Exception
&)
266 // Ignore all exceptions
272 Manipulation::svc (void)
277 static_cast<unsigned int> (ACE_OS::gethrtime ());
278 CORBA::Object_var object
=
279 this->orb_
->resolve_initial_references ("ORBPolicyManager");
281 CORBA::PolicyManager_var policy_manager
=
282 CORBA::PolicyManager::_narrow (object
.in ());
285 this->orb_
->resolve_initial_references ("PolicyCurrent");
287 CORBA::PolicyCurrent_var policy_current
=
288 CORBA::PolicyCurrent::_narrow (object
.in ());
290 for (int i
= 0; i
!= this->niterations_
; ++i
)
292 CORBA::PolicyList_var policies
;
293 this->perform_iteration (&seed
,
295 policy_manager
.in (),
296 policy_current
.in ());
299 catch (const CORBA::Exception
& ex
)
301 ex
._tao_print_exception ("Manipulation: exception raised");