00001
00002
00003 #include "tao/IORManipulation/IORManip_IIOP_Filter.h"
00004
00005 #if defined (TAO_HAS_IIOP) && (TAO_HAS_IIOP != 0)
00006
00007 #include "tao/IORManipulation/IORManip_Loader.h"
00008 #include "tao/IIOP_Profile.h"
00009 #include "tao/MProfile.h"
00010
00011 ACE_RCSID (IORManip_IIOP_Filter, IORManip_IIOP_Filter, "$Id: IORManip_IIOP_Filter.cpp 78285 2007-05-08 11:14:41Z elliott_c $")
00012
00013 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00014
00015 TAO_IORManip_IIOP_Filter::TAO_IORManip_IIOP_Filter (void)
00016 {
00017 }
00018
00019
00020 TAO_IORManip_IIOP_Filter::~TAO_IORManip_IIOP_Filter (void)
00021 {
00022 }
00023
00024
00025 CORBA::Boolean
00026 TAO_IORManip_IIOP_Filter::compare_profile_info (
00027 const TAO_IORManip_IIOP_Filter::Profile_Info& left,
00028 const TAO_IORManip_IIOP_Filter::Profile_Info& right)
00029 {
00030 return (left.version_.major == right.version_.major &&
00031 left.version_.minor == right.version_.minor &&
00032 left.port_ == right.port_ &&
00033 left.host_name_ == right.host_name_);
00034 }
00035
00036
00037 CORBA::Boolean
00038 TAO_IORManip_IIOP_Filter::profile_info_matches (
00039 const TAO_IORManip_IIOP_Filter::Profile_Info&)
00040 {
00041 return true;
00042 }
00043
00044
00045 void
00046 TAO_IORManip_IIOP_Filter::filter_and_add (TAO_Profile* profile,
00047 TAO_MProfile& new_profiles,
00048 TAO_Profile* guideline)
00049 {
00050 TAO_IORManip_IIOP_Filter::Profile_Info ginfo;
00051 TAO_IORManip_IIOP_Filter::Profile_Info pinfo;
00052 TAO::IIOPEndpointSequence endpoints;
00053
00054 this->fill_profile_info (guideline, ginfo);
00055 this->get_endpoints (profile, endpoints);
00056 if (endpoints.length () == 0)
00057 {
00058 CORBA::Boolean matches = false;
00059 this->fill_profile_info (profile, pinfo);
00060
00061 if (guideline == 0)
00062 {
00063 matches = this->profile_info_matches (pinfo);
00064 }
00065 else
00066 {
00067
00068 matches = this->compare_profile_info (pinfo, ginfo);
00069 }
00070
00071 if (matches)
00072 {
00073 if (new_profiles.add_profile (profile) == -1)
00074 {
00075 throw CORBA::NO_MEMORY ();
00076 }
00077 }
00078 }
00079 else
00080 {
00081
00082
00083 TAO_IIOP_Profile* new_profile =
00084 this->create_profile (profile);
00085
00086
00087 this->fill_profile_info (profile, pinfo);
00088
00089
00090
00091
00092 for (CORBA::Long i = endpoints.length () - 1; i >= 0; i--) {
00093
00094 pinfo.host_name_ = endpoints[i].host.in ();
00095 pinfo.port_ = endpoints[i].port;
00096
00097 CORBA::Boolean matches = false;
00098 if (guideline == 0)
00099 {
00100 matches = this->profile_info_matches (pinfo);
00101 }
00102 else
00103 {
00104
00105 matches = this->compare_profile_info (pinfo, ginfo);
00106 }
00107
00108 if (matches)
00109 {
00110
00111 if (i == 0)
00112 {
00113 TAO_IIOP_Endpoint* ep = dynamic_cast<TAO_IIOP_Endpoint*> (
00114 new_profile->endpoint ());
00115 if (ep == 0)
00116 {
00117 new_profile->_decr_refcnt ();
00118 return;
00119 }
00120 else
00121 {
00122 ep->host (CORBA::string_dup (endpoints[i].host));
00123 ep->port (endpoints[i].port);
00124 ep->priority (endpoints[i].priority);
00125 }
00126 }
00127 else
00128 {
00129 TAO_IIOP_Endpoint *endpoint = 0;
00130 ACE_NEW (endpoint,
00131 TAO_IIOP_Endpoint (endpoints[i].host,
00132 endpoints[i].port,
00133 endpoints[i].priority));
00134 if (endpoint == 0)
00135 {
00136 new_profile->_decr_refcnt ();
00137 return;
00138 }
00139
00140 new_profile->add_endpoint (endpoint);
00141 }
00142 }
00143 }
00144
00145 if (new_profiles.add_profile (new_profile) == -1)
00146 {
00147 throw CORBA::NO_MEMORY ();
00148 }
00149
00150 new_profile->encode_endpoints ();
00151
00152
00153
00154 new_profile->_decr_refcnt ();
00155 }
00156 }
00157
00158
00159 int
00160 TAO_IORManip_IIOP_Filter::fill_profile_info (
00161 TAO_Profile* profile,
00162 TAO_IORManip_IIOP_Filter::Profile_Info& pinfo)
00163 {
00164 static const int host_length = 384;
00165 int status = 0;
00166 if (profile != 0)
00167 {
00168 char host[host_length] = "";
00169 if (profile->endpoint ()->addr_to_string (host, host_length) != -1)
00170 {
00171 char* delim = ACE_OS::strchr (host, ':');
00172 if (delim != 0)
00173 {
00174 *delim = '\0';
00175 pinfo.port_ = ACE_OS::atoi (delim + 1);
00176 status = 1;
00177 }
00178 }
00179
00180 pinfo.host_name_ = host;
00181 pinfo.version_ = profile->version ();
00182 }
00183
00184 return status;
00185 }
00186
00187
00188 int
00189 TAO_IORManip_IIOP_Filter::get_endpoints (TAO_Profile* profile,
00190 TAO::IIOPEndpointSequence& endpoints)
00191 {
00192
00193 endpoints.length (0);
00194
00195
00196 const TAO_Tagged_Components& comps = profile->tagged_components ();
00197 IOP::TaggedComponent tagged_component;
00198 tagged_component.tag = TAO_TAG_ENDPOINTS;
00199 comps.get_component (tagged_component);
00200
00201
00202 const CORBA::Octet *buf =
00203 tagged_component.component_data.get_buffer ();
00204
00205 TAO_InputCDR in_cdr (reinterpret_cast<const char*> (buf),
00206 tagged_component.component_data.length ());
00207
00208
00209 CORBA::Boolean byte_order;
00210 if ((in_cdr >> ACE_InputCDR::to_boolean (byte_order)) == 0)
00211 return 0;
00212 in_cdr.reset_byte_order (static_cast<int> (byte_order));
00213
00214
00215 if ((in_cdr >> endpoints) == 0)
00216 return 0;
00217
00218 return 1;
00219 }
00220
00221
00222 TAO_IIOP_Profile*
00223 TAO_IORManip_IIOP_Filter::create_profile (TAO_Profile* profile)
00224 {
00225 ACE_INET_Addr addr;
00226 TAO_IIOP_Profile* new_profile = 0;
00227 ACE_NEW_THROW_EX (new_profile,
00228 TAO_IIOP_Profile (addr,
00229 profile->object_key (),
00230 profile->version (),
00231 profile->orb_core ()),
00232 CORBA::NO_MEMORY (
00233 CORBA::SystemException::_tao_minor_code (
00234 0,
00235 ENOMEM),
00236 CORBA::COMPLETED_NO));
00237
00238
00239 const TAO_Tagged_Components& comps = profile->tagged_components ();
00240 new_profile->tagged_components () = comps;
00241
00242
00243 IOP::TaggedComponent tagged_component;
00244 tagged_component.tag = TAO_TAG_ENDPOINTS;
00245 new_profile->tagged_components ().set_component (tagged_component);
00246
00247 return new_profile;
00248 }
00249
00250 TAO_END_VERSIONED_NAMESPACE_DECL
00251
00252 #endif