TAO_IORManip_IIOP_Filter Class Reference

#include <IORManip_IIOP_Filter.h>

Inheritance diagram for TAO_IORManip_IIOP_Filter:

Inheritance graph
[legend]
Collaboration diagram for TAO_IORManip_IIOP_Filter:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 TAO_IORManip_IIOP_Filter (void)
 Constructor.
virtual ~TAO_IORManip_IIOP_Filter (void)
 Destructor.
virtual CORBA::Boolean compare_profile_info (const TAO_IORManip_IIOP_Filter::Profile_Info &left, const TAO_IORManip_IIOP_Filter::Profile_Info &right)
 Compares the profile to the profile info.
virtual CORBA::Boolean profile_info_matches (const TAO_IORManip_IIOP_Filter::Profile_Info &pinfo)

Protected Member Functions

virtual void filter_and_add (TAO_Profile *profile, TAO_MProfile &profiles, TAO_Profile *guideline=0)
 This is the bulk of the filtering code.

Private Member Functions

int fill_profile_info (TAO_Profile *profile, TAO_IORManip_IIOP_Filter::Profile_Info &pinfo)
 Fill in the Profile_Info with information from the profile.
int get_endpoints (TAO_Profile *profile, TAO::IIOPEndpointSequence &endpoints)
 Get the endpoint sequence from the profile.
TAO_IIOP_Profilecreate_profile (TAO_Profile *profile)
 Allocate a new IIOP Profile based on the profile passed in.

Classes

struct  Profile_Info

Detailed Description

Definition at line 39 of file IORManip_IIOP_Filter.h.


Constructor & Destructor Documentation

TAO_BEGIN_VERSIONED_NAMESPACE_DECL TAO_IORManip_IIOP_Filter::TAO_IORManip_IIOP_Filter ( void   ) 

Constructor.

Definition at line 16 of file IORManip_IIOP_Filter.cpp.

00017 {
00018 }

TAO_IORManip_IIOP_Filter::~TAO_IORManip_IIOP_Filter ( void   )  [virtual]

Destructor.

Definition at line 21 of file IORManip_IIOP_Filter.cpp.

00022 {
00023 }


Member Function Documentation

CORBA::Boolean TAO_IORManip_IIOP_Filter::compare_profile_info ( const TAO_IORManip_IIOP_Filter::Profile_Info left,
const TAO_IORManip_IIOP_Filter::Profile_Info right 
) [virtual]

Compares the profile to the profile info.

Definition at line 27 of file IORManip_IIOP_Filter.cpp.

References TAO_IORManip_IIOP_Filter::Profile_Info::host_name_, TAO_GIOP_Message_Version::major, TAO_GIOP_Message_Version::minor, TAO_IORManip_IIOP_Filter::Profile_Info::port_, and TAO_IORManip_IIOP_Filter::Profile_Info::version_.

Referenced by filter_and_add().

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 }

TAO_IIOP_Profile * TAO_IORManip_IIOP_Filter::create_profile ( TAO_Profile profile  )  [private]

Allocate a new IIOP Profile based on the profile passed in.

Definition at line 224 of file IORManip_IIOP_Filter.cpp.

References CORBA::SystemException::_tao_minor_code(), ACE_NEW_THROW_EX, CORBA::COMPLETED_NO, TAO_Profile::object_key(), TAO_Profile::orb_core(), TAO_Tagged_Components::set_component(), TAO_Profile::tagged_components(), TAO_TAG_ENDPOINTS, and TAO_Profile::version().

Referenced by filter_and_add().

00225 {
00226   ACE_INET_Addr addr;
00227   TAO_IIOP_Profile* new_profile = 0;
00228   ACE_NEW_THROW_EX (new_profile,
00229                    TAO_IIOP_Profile (addr,
00230                                      profile->object_key (),
00231                                      profile->version (),
00232                                      profile->orb_core ()),
00233                    CORBA::NO_MEMORY (
00234                      CORBA::SystemException::_tao_minor_code (
00235                        0,
00236                        ENOMEM),
00237                      CORBA::COMPLETED_NO));
00238 
00239   // Copy all of the tagged components
00240   const TAO_Tagged_Components& comps = profile->tagged_components ();
00241   new_profile->tagged_components () = comps;
00242 
00243   // Set the endpoints component to an empty list
00244   IOP::TaggedComponent tagged_component;
00245   tagged_component.tag = TAO_TAG_ENDPOINTS;
00246   new_profile->tagged_components ().set_component (tagged_component);
00247 
00248   return new_profile;
00249 }

int TAO_IORManip_IIOP_Filter::fill_profile_info ( TAO_Profile profile,
TAO_IORManip_IIOP_Filter::Profile_Info pinfo 
) [private]

Fill in the Profile_Info with information from the profile.

Definition at line 161 of file IORManip_IIOP_Filter.cpp.

References TAO_Endpoint::addr_to_string(), ACE_OS::atoi(), TAO_Profile::endpoint(), TAO_IORManip_IIOP_Filter::Profile_Info::host_name_, TAO_IORManip_IIOP_Filter::Profile_Info::port_, ACE_OS::strchr(), TAO_Profile::version(), and TAO_IORManip_IIOP_Filter::Profile_Info::version_.

Referenced by filter_and_add().

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 }

void TAO_IORManip_IIOP_Filter::filter_and_add ( TAO_Profile profile,
TAO_MProfile profiles,
TAO_Profile guideline = 0 
) [protected, virtual]

This is the bulk of the filtering code.

Implements TAO_IORManip_Filter.

Definition at line 47 of file IORManip_IIOP_Filter.cpp.

References TAO_Profile::_decr_refcnt(), ACE_NEW, TAO_IIOP_Profile::add_endpoint(), TAO_MProfile::add_profile(), compare_profile_info(), create_profile(), TAO_IIOP_Profile::encode_endpoints(), TAO_IIOP_Profile::endpoint(), fill_profile_info(), get_endpoints(), TAO_IIOP_Endpoint::host(), TAO_IORManip_IIOP_Filter::Profile_Info::host_name_, TAO_IIOP_Endpoint::port(), TAO_IORManip_IIOP_Filter::Profile_Info::port_, TAO_Endpoint::priority(), profile_info_matches(), and CORBA::string_dup().

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           // Compare the current profile with the guideline profile
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       // Create a new profile with just the
00083       // components we are looking for
00084       TAO_IIOP_Profile* new_profile =
00085           this->create_profile (profile);
00086 
00087       // Set pinfo to match the current profile
00088       this->fill_profile_info (profile, pinfo);
00089 
00090       // Add each endpoint if it matches.  Begin from the end
00091       // of the sequence to preserve endpoint order, since <add_endpoint>
00092       // method reverses the order of endpoints in the list.
00093       for (CORBA::Long i = endpoints.length () - 1; i >= 0; i--) {
00094         // Set pinfo host name to the current endpoint host name
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             // Compare the current profile with the guideline profile
00106             matches = this->compare_profile_info (pinfo, ginfo);
00107           }
00108 
00109         if (matches)
00110           {
00111             // Set the main endpoint on the profile
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       // After adding the profile to the MProfile,
00154       // we must decrement the reference to avoid a memory leak
00155       new_profile->_decr_refcnt ();
00156     }
00157 }

int TAO_IORManip_IIOP_Filter::get_endpoints ( TAO_Profile profile,
TAO::IIOPEndpointSequence &  endpoints 
) [private]

Get the endpoint sequence from the profile.

Definition at line 190 of file IORManip_IIOP_Filter.cpp.

References TAO_Tagged_Components::get_component(), TAO_Profile::tagged_components(), and TAO_TAG_ENDPOINTS.

Referenced by filter_and_add().

00192 {
00193   // Reset the endpoints
00194   endpoints.length (0);
00195 
00196   // Get the endpoints tagged component
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   // Prepare the CDR for endpoint extraction
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   // Extract the Byte Order.
00210   CORBA::Boolean byte_order;
00211   if ((in_cdr >> ACE_InputCDR::to_boolean (byte_order)) == 0)
00212     return 0;
00213   in_cdr.reset_byte_order (static_cast<int> (byte_order));
00214 
00215   // Extract endpoints sequence.
00216   if ((in_cdr >> endpoints) == 0)
00217     return 0;
00218 
00219   return 1;
00220 }

CORBA::Boolean TAO_IORManip_IIOP_Filter::profile_info_matches ( const TAO_IORManip_IIOP_Filter::Profile_Info pinfo  )  [virtual]

Empty virtual method to match on the profile info. Users must provide an implementation to use the first form of sanitize_profiles().

Definition at line 39 of file IORManip_IIOP_Filter.cpp.

Referenced by filter_and_add().

00041 {
00042   return true;
00043 }


The documentation for this class was generated from the following files:
Generated on Tue Feb 2 17:43:37 2010 for TAO_IORManipulation by  doxygen 1.4.7