PG_Utils.cpp

Go to the documentation of this file.
00001 #include "orbsvcs/PortableGroup/PG_Utils.h"
00002 
00003 #include "tao/MProfile.h"
00004 #include "tao/Profile.h"
00005 #include "tao/Stub.h"
00006 #include "tao/Tagged_Components.h"
00007 #include "tao/CDR.h"
00008 
00009 #include "ace/OS_NS_string.h"
00010 
00011 
00012 ACE_RCSID (PortableGroup,
00013            PG_Utils,
00014            "PG_Utils.cpp,v 1.8 2006/03/14 06:14:34 jtc Exp")
00015 
00016 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00017 
00018 namespace TAO
00019 {
00020   /*static*/ CORBA::Boolean
00021   PG_Utils::set_tagged_component (
00022       PortableGroup::ObjectGroup *&ior,
00023       PortableGroup::TagGroupTaggedComponent &tg)
00024   {
00025     if (ior->_stubobj () == 0)
00026       return 0;
00027 
00028     // We need to apply the property for every profile in the IOR
00029     TAO_MProfile &tmp_pfiles =
00030       ior->_stubobj ()->base_profiles ();
00031 
00032     // Create the output CDR stream
00033     TAO_OutputCDR cdr;
00034 
00035     IOP::TaggedComponent tagged_components;
00036     tagged_components.tag = IOP::TAG_FT_GROUP;
00037 
00038     // Encode the property in to the tagged_components
00039     CORBA::Boolean retval =
00040       PG_Utils::encode_properties (cdr,
00041                                    tg);
00042 
00043     if (retval == 0)
00044       return retval;
00045 
00046     // Get the length of the CDR stream
00047     CORBA::ULong length = static_cast<CORBA::ULong> (cdr.total_length ());
00048 
00049     // Set the length
00050     tagged_components.component_data.length (length);
00051 
00052     // Get the pointer to the underlying buffer
00053     CORBA::Octet *buf =
00054       tagged_components.component_data.get_buffer ();
00055 
00056     for (const ACE_Message_Block *i = cdr.begin ();
00057          i != 0;
00058          i = i->cont ())
00059       {
00060 
00061         ACE_OS::memcpy (buf, i->rd_ptr (), i->length ());
00062         buf += i->length ();
00063       }
00064     const IOP::TaggedComponent &tmp_tc = tagged_components;
00065 
00066     // Get the profile count.
00067     CORBA::ULong count =
00068       ior->_stubobj ()->base_profiles ().profile_count ();
00069 
00070     // Go through every profile and set the TaggedComponent field
00071     for (CORBA::ULong p_idx = 0; p_idx < count ; ++p_idx)
00072       {
00073         // Get the tagged components in the profile
00074         TAO_Tagged_Components &tag_comp =
00075           tmp_pfiles.get_profile (p_idx)->tagged_components ();
00076 
00077         // Finally set the <tagged_component> in the
00078         // <TAO_Tagged_Component>
00079         tag_comp.set_component (tmp_tc);
00080       }
00081 
00082     // Success
00083     return 1;
00084   }
00085 
00086   /*static*/ CORBA::Boolean
00087   PG_Utils::get_tagged_component (
00088       PortableGroup::ObjectGroup *&ior,
00089       PortableGroup::TagGroupTaggedComponent &tg)
00090   {
00091     if (ior->_stubobj () == 0)
00092       return 0;
00093 
00094     TAO_MProfile &mprofile =
00095       ior->_stubobj ()->base_profiles ();
00096 
00097     // Looking for a tagged component with a TAG_FT_GROUP flag.
00098     IOP::TaggedComponent tc;
00099     tc.tag = IOP::TAG_FT_GROUP;
00100 
00101     CORBA::ULong count =
00102       mprofile.profile_count ();
00103 
00104     for (CORBA::ULong i = 0;
00105          i < count;
00106          i++)
00107       {
00108 
00109         // Get the Tagged Components
00110         const TAO_Tagged_Components &pfile_tagged =
00111           mprofile.get_profile (i)->tagged_components ();
00112 
00113         // Look for the primary
00114         if (pfile_tagged.get_component (tc) == 1)
00115           {
00116             TAO_InputCDR cdr (reinterpret_cast<const char*> (tc.component_data.get_buffer ()),
00117                             tc.component_data.length ());
00118 
00119             CORBA::Boolean byte_order;
00120 
00121             cdr >> ACE_InputCDR::to_boolean (byte_order);
00122 
00123             if (!cdr.good_bit ())
00124               return 0;
00125 
00126             cdr.reset_byte_order (static_cast<int> (byte_order));
00127 
00128             cdr >> tg;
00129 
00130             if (cdr.good_bit ())
00131               return 1;
00132           }
00133       }
00134 
00135     return 0;
00136   }
00137 
00138   CORBA::Boolean
00139   PG_Utils::encode_properties (
00140       TAO_OutputCDR &cdr,
00141       PortableGroup::TagGroupTaggedComponent &tg)
00142   {
00143     cdr << ACE_OutputCDR::from_boolean (TAO_ENCAP_BYTE_ORDER);
00144 
00145     if (!cdr.good_bit ())
00146       return 0;
00147 
00148     // the version info
00149     cdr << tg.component_version;
00150 
00151     if (!cdr.good_bit ())
00152       return 0;
00153 
00154     // the domain id
00155     cdr << tg.group_domain_id.in ();
00156 
00157     if (!cdr.good_bit ())
00158       return 0;
00159 
00160     // Object group id
00161     cdr << tg.object_group_id;
00162 
00163     if (!cdr.good_bit ())
00164       return 0;
00165 
00166     // Object group reference version
00167     cdr << tg.object_group_ref_version;
00168 
00169     if (!cdr.good_bit ())
00170       return 0;
00171 
00172     return cdr.good_bit ();
00173   }
00174 }
00175 
00176 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Thu Nov 9 14:03:34 2006 for TAO_PortableGroup by doxygen 1.3.6