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