1 // -- App. Specific Include --
2 #include "Policy_Tester.h"
3 #include "RT_Properties.h"
7 #include "ace/Arg_Shifter.h"
8 #include "ace/OS_NS_stdio.h"
10 // -- RTCORBA Include --
11 #include "tao/RTCORBA/RT_Policy_i.h"
13 // -- RTCORBA Include --
14 #include "tao/RTCORBA/RT_ORB.h"
16 #include "tao/ORB_Constants.h"
17 #include "tao/ORB_Core.h"
22 PortableServer::POAManager_var poa_manager
=
23 this->child_poa_
->the_POAManager ();
25 poa_manager
->activate ();
31 Policy_Tester::init (int argc
,
34 // ORB Initialization.
36 CORBA::ORB_init (argc
, argv
);
38 // Get a reference to the RT-ORB.
39 CORBA::Object_var object
=
40 this->orb_
->resolve_initial_references ("RTORB");
42 this->rt_orb_
= RTCORBA::RTORB::_narrow (object
.in ());
44 // Here we parse the command line paramether passed
45 // to the application.
47 ACE_Arg_Shifter
arg_shifter (argc
, argv
);
49 while (arg_shifter
.is_anything_left ())
51 const ACE_TCHAR
*arg
= 0;
52 // IOR File Name Option.
53 if (0 != (arg
= arg_shifter
.get_the_parameter (ACE_TEXT("-POAConfigFile"))))
55 this->rt_poa_properties_
=
56 RT_Properties::read_from (arg
);
58 else if (0 != (arg
= arg_shifter
.get_the_parameter (ACE_TEXT("-ObjectConfigFile"))))
60 this->rt_object_properties_
=
61 RT_Properties::read_from (arg
);
63 else if (0 != (arg
= arg_shifter
.get_the_parameter (ACE_TEXT("-BaseObjectIOR"))))
65 if (this->rt_poa_properties_
== 0)
67 ACE_NEW_THROW_EX (this->rt_poa_properties_
,
69 CORBA::NO_MEMORY (TAO::VMCID
,
70 CORBA::COMPLETED_NO
));
72 this->rt_poa_properties_
->ior_source (arg
);
74 else if (0 != (arg
= arg_shifter
.get_the_parameter (ACE_TEXT("-OverriddenIOR"))))
76 if (this->rt_object_properties_
== 0)
78 ACE_NEW_THROW_EX (this->rt_object_properties_
,
80 CORBA::NO_MEMORY (TAO::VMCID
,
81 CORBA::COMPLETED_NO
));
83 this->rt_object_properties_
->ior_source (arg
);
86 arg_shifter
.consume_arg ();
89 if ((this->rt_poa_properties_
== 0) || (this->rt_object_properties_
== 0))
92 ACE_TEXT ("Configuration file missing!")));
97 this->create_objects ();
106 Policy_Tester::check_reference (CORBA::Object_ptr object
,
109 if (CORBA::is_nil (object
))
111 ACE_DEBUG ((LM_DEBUG
, msg
));
119 Policy_Tester::create_objects ()
121 CORBA::PolicyList poa_policy_list
;
122 poa_policy_list
.length (3);
124 // Create the priority policy using the RT-ORB.
125 RTCORBA::Priority priority
= this->rt_poa_properties_
->priority ();
127 this->rt_orb_
->create_priority_model_policy (RTCORBA::SERVER_DECLARED
,
130 // Create priority Banded Connection Policy.
131 RTCORBA::PriorityBands poa_priority_bands
=
132 this->rt_poa_properties_
->priority_bands ();
135 this->rt_orb_
->create_priority_banded_connection_policy (poa_priority_bands
);
137 // Client Protocol Policy.
138 RTCORBA::ProtocolList protocol_list
;
139 protocol_list
.length (1);
141 protocol_list
[0].protocol_type
= IOP::TAG_INTERNET_IOP
;
142 protocol_list
[0].orb_protocol_properties
=
143 TAO_Protocol_Properties_Factory::create_orb_protocol_property (IOP::TAG_INTERNET_IOP
);
145 protocol_list
[0].transport_protocol_properties
=
146 TAO_Protocol_Properties_Factory::create_transport_protocol_property (IOP::TAG_INTERNET_IOP
,
147 this->orb_
->orb_core ());
150 this->rt_orb_
->create_client_protocol_policy (protocol_list
);
152 CORBA::Object_var object
=
153 this->orb_
->resolve_initial_references ("RootPOA");
156 PortableServer::POA::_narrow (object
.in ());
158 PortableServer::POAManager_var poa_mgr
=
159 PortableServer::POAManager::_nil ();
162 this->poa_
->create_POA ("Child_POA",
167 RTPortableServer::POA::_narrow (object
.in ());
169 // Create a Corba Object reference, using the policies
170 // set at the POA level.
172 this->child_poa_
->create_reference ("IDL:Counter:1.0");
174 ACE_DEBUG ((LM_DEBUG
,
175 ACE_TEXT ("Reference Created!\n")));
177 if (!check_reference (object
.in (),
178 "Unable to create Object!\n"))
181 Counter_var base_object
= Counter::_narrow (object
.in ());
183 if (!check_reference (base_object
.in(),
184 "Unable to create a Object!\n"))
187 CORBA::String_var ior
=
188 this->orb_
->object_to_string (base_object
.in ());
190 ACE_DEBUG ((LM_DEBUG
,
191 ACE_TEXT ("Activated as <%C>\n"), ior
.in ()));
193 FILE *output_file
= ACE_OS::fopen (this->rt_poa_properties_
->ior_source (), "w");
194 if (output_file
== 0)
195 ACE_ERROR_RETURN ((LM_ERROR
,
196 ACE_TEXT ("Cannot open output file for writing IOR: %s"),
197 this->rt_poa_properties_
->ior_source ()),
199 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
200 ACE_OS::fclose (output_file
);
202 // Now we create an object that overrides some of the policies
203 // set at the POA level.
206 // Create a Corba Object reference, using the policies
207 // set at the POA level.
210 this->child_poa_
->create_reference_with_priority
212 this->rt_object_properties_
->priority ());
214 ACE_DEBUG ((LM_DEBUG
,
215 ACE_TEXT ("Reference Created!\n")));
217 if (!check_reference (object
.in (),
218 "Unable to create a Counter Object!\n"))
221 Counter_var over_object
= Counter::_narrow (object
.in ());
223 if (!check_reference (over_object
.in(),
224 "Unable to create Object!\n"))
228 CORBA::String_var o_ior
=
229 this->orb_
->object_to_string (over_object
.in ());
231 ACE_DEBUG ((LM_DEBUG
,
232 ACE_TEXT ("Activated as <%C>\n"), o_ior
.in ()));
234 output_file
= ACE_OS::fopen (this->rt_object_properties_
->ior_source (), "w");
236 if (output_file
== 0)
237 ACE_ERROR_RETURN ((LM_ERROR
,
238 ACE_TEXT ("Cannot open output file for writing IOR: %s"),
239 this->rt_object_properties_
->ior_source ()),
241 ACE_OS::fprintf (output_file
, "%s", o_ior
.in ());
242 ACE_OS::fclose (output_file
);
247 Policy_Tester::shutdown ()
249 this->orb_
->shutdown (false);