ACE+TAO-6_5_17
[ACE_TAO.git] / TAO / tests / Exposed_Policies / Policy_Verifier.cpp
blob81c07d0e08ca22bb256d894040d122d11772d831
1 #include "Policy_Verifier.h"
2 #include "ace/OS_NS_string.h"
4 Policy_Verifier::Policy_Verifier (void)
5 : rt_object_properties_ (0)
6 , rt_poa_properties_ (0)
7 , priority_bands_ (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 (void)
17 delete rt_object_properties_;
18 delete rt_poa_properties_;
21 bool
22 Policy_Verifier::init (int argc, ACE_TCHAR *argv[])
24 this->orb_ =
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_,
50 RT_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_,
64 RT_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 ());
73 else
75 arg_shifter.consume_arg ();
79 if ((this->rt_poa_properties_ == 0) || (this->rt_object_properties_ == 0))
81 ACE_DEBUG ((LM_DEBUG,
82 ACE_TEXT ("Configuration file missing!\n")));
83 return false;
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"))
90 return false;
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"))
96 return false;
98 object = this->orb_->string_to_object (this->overridden_object_ref_);
100 if (!Policy_Verifier::check_reference (object.in (), "Invalid IOR file!\n"))
101 return false;
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"))
107 return false;
109 return true;
112 void
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_);
122 void
123 Policy_Verifier::verify_reference (Counter_ptr object,
124 RT_Properties *rt_properties)
129 CORBA::Policy_var policy_var =
130 object->_get_policy (RTCORBA::PRIORITY_MODEL_POLICY_TYPE);
132 if (Policy_Verifier::check_reference (policy_var.in (), "Unable to get Priority Policy.\n"))
134 RTCORBA::PriorityModelPolicy_var priority_policy =
135 RTCORBA::PriorityModelPolicy::_narrow (policy_var.in ());
137 RTCORBA::PriorityModel priority_model =
138 priority_policy->priority_model ();
140 RTCORBA::Priority priority =
141 priority_policy->server_priority ();
143 if (priority_model == RTCORBA::SERVER_DECLARED)
144 ACE_DEBUG ((LM_DEBUG,
145 ACE_TEXT ("\n\nPriority Model: RTCORBA::SERVER_DECLARED\n")
148 ACE_DEBUG ((LM_DEBUG,
149 ACE_TEXT ("Priority Model: %d\nCORBA Priority: %d\n\n"),
150 priority_model,
151 priority
155 if (priority != rt_properties->priority ())
156 ACE_DEBUG ((LM_DEBUG,
157 ACE_TEXT ("Priority Value Mismatch.\n")));
160 policy_var = object->_get_policy (RTCORBA::PRIORITY_BANDED_CONNECTION_POLICY_TYPE);
162 if (Policy_Verifier::check_reference (policy_var.in (),
163 "Unable to get Priority Banded Policy\n"))
166 RTCORBA::PriorityBandedConnectionPolicy_var priority_banded_policy =
167 RTCORBA::PriorityBandedConnectionPolicy::_narrow (policy_var.in ());
170 if (Policy_Verifier::check_reference (priority_banded_policy.in (),
171 "Unable to get Priority Banded Policy\n"))
174 // Here we have a priority banded connection policy.
176 RTCORBA::PriorityBands_var pb =
177 priority_banded_policy->priority_bands ();
178 unsigned int band_num = pb->length ();
179 if (band_num != this->priority_bands_)
180 ACE_DEBUG ((LM_DEBUG,
181 ACE_TEXT ("Mismatching Number of Priority Bands!\n")));
183 for (unsigned int i = 0; i < band_num; ++i)
185 ACE_DEBUG ((LM_DEBUG,
186 ACE_TEXT ("Priority Band <%d>: (%d, %d)\n"),
188 pb[i].low,
189 pb[i].high
193 if ((band_num == rt_properties->priority_bands ().length ()) &&
194 ((pb[i].low != rt_properties->priority_bands ()[i].low) ||
195 (pb[i].high != rt_properties->priority_bands ()[i].high)))
196 ACE_DEBUG ((LM_DEBUG,
197 ACE_TEXT ("Mismatching Priority Band Range!\n")));
202 policy_var = object->_get_policy (RTCORBA::CLIENT_PROTOCOL_POLICY_TYPE);
204 if (Policy_Verifier::check_reference (policy_var.in (),
205 "Unable to get Client Protocol Policy\n"))
207 RTCORBA::ClientProtocolPolicy_var client_protocol_policy =
208 RTCORBA::ClientProtocolPolicy::_narrow (policy_var.in ());
210 RTCORBA::ProtocolList_var protocol_list =
211 client_protocol_policy->protocols ();
213 for (unsigned int i = 0; i < protocol_list->length (); i++)
214 ACE_DEBUG ((LM_DEBUG,
215 ACE_TEXT ("\nThe Client Protocol Type: %d\n"),
216 protocol_list[i].protocol_type));
221 catch (const CORBA::Exception& ex)
223 ex._tao_print_exception ("CORBA Exception Raised");
228 CORBA::Boolean
229 Policy_Verifier::check_reference (CORBA::Object_ptr object,
230 const char *msg)
232 if (CORBA::is_nil (object))
234 ACE_DEBUG ((LM_DEBUG, msg));
235 return 0;
237 return 1;