1 #include "Policy_Verifier.h"
2 #include "ace/OS_NS_string.h"
4 Policy_Verifier::Policy_Verifier ()
5 : rt_object_properties_ (0)
6 , rt_poa_properties_ (0)
9 ACE_OS::strcpy (this->base_object_ref_
,
10 ACE_TEXT("file://default.ior"));
11 ACE_OS::strcpy (this->overridden_object_ref_
,
12 ACE_TEXT("file://overridden.ior"));
15 Policy_Verifier::~Policy_Verifier ()
17 delete rt_object_properties_
;
18 delete rt_poa_properties_
;
22 Policy_Verifier::init (int argc
, ACE_TCHAR
*argv
[])
25 CORBA::ORB_init (argc
, argv
);
27 ACE_Arg_Shifter
arg_shifter (argc
, argv
);
29 while (arg_shifter
.is_anything_left ())
31 const ACE_TCHAR
*arg
= 0;
32 // IOR File Name Option.
33 if (0 != (arg
= arg_shifter
.get_the_parameter (ACE_TEXT("-POAConfigFile"))))
35 this->rt_poa_properties_
=
36 RT_Properties::read_from (arg
);
37 this->priority_bands_
=
38 this->rt_poa_properties_
->priority_bands ().length ();
40 else if (0 != (arg
= arg_shifter
.get_the_parameter (ACE_TEXT("-ObjectConfigFile"))))
42 this->rt_object_properties_
=
43 RT_Properties::read_from (arg
);
45 else if (0 != (arg
= arg_shifter
.get_the_parameter (ACE_TEXT("-BaseObjectIOR"))))
47 if (this->rt_poa_properties_
== 0)
49 ACE_NEW_THROW_EX (this->rt_poa_properties_
,
51 CORBA::NO_MEMORY (TAO::VMCID
,
52 CORBA::COMPLETED_NO
));
54 this->rt_poa_properties_
->ior_source (arg
);
55 ACE_OS::strcpy (this->base_object_ref_
, ACE_TEXT("file://"));
56 ACE_OS::strcat (this->base_object_ref_
,
57 this->rt_poa_properties_
->ior_source ());
59 else if (0 != (arg
= arg_shifter
.get_the_parameter (ACE_TEXT("-OverriddenIOR"))))
61 if (this->rt_object_properties_
== 0)
63 ACE_NEW_THROW_EX (this->rt_object_properties_
,
65 CORBA::NO_MEMORY (TAO::VMCID
,
66 CORBA::COMPLETED_NO
));
68 this->rt_object_properties_
->ior_source (arg
);
69 ACE_OS::strcpy (this->overridden_object_ref_
, ACE_TEXT("file://"));
70 ACE_OS::strcat (this->overridden_object_ref_
,
71 this->rt_object_properties_
->ior_source ());
75 arg_shifter
.consume_arg ();
79 if ((this->rt_poa_properties_
== 0) || (this->rt_object_properties_
== 0))
82 ACE_TEXT ("Configuration file missing!\n")));
86 // Get the Object references.
87 CORBA::Object_var object
= this->orb_
->string_to_object (this->base_object_ref_
);
89 if (!Policy_Verifier::check_reference (object
.in (), "Invalid IOR file!\n"))
92 this->base_object_
= Counter::_narrow (object
.in ());
94 if (!Policy_Verifier::check_reference (this->base_object_
.in (),
95 "Unable to convert the IOR to the proper object reference.\n"))
98 object
= this->orb_
->string_to_object (this->overridden_object_ref_
);
100 if (!Policy_Verifier::check_reference (object
.in (), "Invalid IOR file!\n"))
103 this->overridden_object_
= Counter::_narrow (object
.in ());
105 if (!Policy_Verifier::check_reference (this->overridden_object_
.in (),
106 "Unable to convert the IOR to the proper object reference.\n"))
113 Policy_Verifier::run ()
115 this->verify_reference (this->base_object_
.in (),
116 this->rt_poa_properties_
);
118 this->verify_reference (this->overridden_object_
.in (),
119 this->rt_object_properties_
);
123 Policy_Verifier::verify_reference (Counter_ptr object
,
124 RT_Properties
*rt_properties
)
128 CORBA::Policy_var policy_var
=
129 object
->_get_policy (RTCORBA::PRIORITY_MODEL_POLICY_TYPE
);
131 if (Policy_Verifier::check_reference (policy_var
.in (), "Unable to get Priority Policy.\n"))
133 RTCORBA::PriorityModelPolicy_var priority_policy
=
134 RTCORBA::PriorityModelPolicy::_narrow (policy_var
.in ());
136 RTCORBA::PriorityModel priority_model
=
137 priority_policy
->priority_model ();
139 RTCORBA::Priority priority
=
140 priority_policy
->server_priority ();
142 if (priority_model
== RTCORBA::SERVER_DECLARED
)
143 ACE_DEBUG ((LM_DEBUG
,
144 ACE_TEXT ("\n\nPriority Model: RTCORBA::SERVER_DECLARED\n")
147 ACE_DEBUG ((LM_DEBUG
,
148 ACE_TEXT ("Priority Model: %d\nCORBA Priority: %d\n\n"),
154 if (priority
!= rt_properties
->priority ())
155 ACE_DEBUG ((LM_DEBUG
,
156 ACE_TEXT ("Priority Value Mismatch.\n")));
159 policy_var
= object
->_get_policy (RTCORBA::PRIORITY_BANDED_CONNECTION_POLICY_TYPE
);
161 if (Policy_Verifier::check_reference (policy_var
.in (),
162 "Unable to get Priority Banded Policy\n"))
164 RTCORBA::PriorityBandedConnectionPolicy_var priority_banded_policy
=
165 RTCORBA::PriorityBandedConnectionPolicy::_narrow (policy_var
.in ());
168 if (Policy_Verifier::check_reference (priority_banded_policy
.in (),
169 "Unable to get Priority Banded Policy\n"))
171 // Here we have a priority banded connection policy.
173 RTCORBA::PriorityBands_var pb
=
174 priority_banded_policy
->priority_bands ();
175 unsigned int band_num
= pb
->length ();
176 if (band_num
!= this->priority_bands_
)
177 ACE_DEBUG ((LM_DEBUG
,
178 ACE_TEXT ("Mismatching Number of Priority Bands!\n")));
180 for (unsigned int i
= 0; i
< band_num
; ++i
)
182 ACE_DEBUG ((LM_DEBUG
,
183 ACE_TEXT ("Priority Band <%d>: (%d, %d)\n"),
190 if ((band_num
== rt_properties
->priority_bands ().length ()) &&
191 ((pb
[i
].low
!= rt_properties
->priority_bands ()[i
].low
) ||
192 (pb
[i
].high
!= rt_properties
->priority_bands ()[i
].high
)))
193 ACE_DEBUG ((LM_DEBUG
,
194 ACE_TEXT ("Mismatching Priority Band Range!\n")));
198 policy_var
= object
->_get_policy (RTCORBA::CLIENT_PROTOCOL_POLICY_TYPE
);
200 if (Policy_Verifier::check_reference (policy_var
.in (),
201 "Unable to get Client Protocol Policy\n"))
203 RTCORBA::ClientProtocolPolicy_var client_protocol_policy
=
204 RTCORBA::ClientProtocolPolicy::_narrow (policy_var
.in ());
206 RTCORBA::ProtocolList_var protocol_list
=
207 client_protocol_policy
->protocols ();
209 for (unsigned int i
= 0; i
< protocol_list
->length (); i
++)
210 ACE_DEBUG ((LM_DEBUG
,
211 ACE_TEXT ("\nThe Client Protocol Type: %d\n"),
212 protocol_list
[i
].protocol_type
));
216 catch (const CORBA::Exception
& ex
)
218 ex
._tao_print_exception ("CORBA Exception Raised");
224 Policy_Verifier::check_reference (CORBA::Object_ptr object
,
227 if (CORBA::is_nil (object
))
229 ACE_DEBUG ((LM_DEBUG
, msg
));