Tagged_Components.cpp

Go to the documentation of this file.
00001 // $Id: Tagged_Components.cpp 76962 2007-02-08 16:29:30Z johnnyw $
00002 
00003 #include "tao/Tagged_Components.h"
00004 #include "tao/CDR.h"
00005 
00006 #if !defined (__ACE_INLINE__)
00007 # include "tao/Tagged_Components.inl"
00008 #endif /* ! __ACE_INLINE__ */
00009 
00010 #include "ace/OS_NS_string.h"
00011 
00012 ACE_RCSID (tao,
00013            Tagged_Components,
00014            "$Id: Tagged_Components.cpp 76962 2007-02-08 16:29:30Z johnnyw $")
00015 
00016 
00017 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00018 
00019 void
00020 TAO_Tagged_Components::set_orb_type (CORBA::ULong orb_type)
00021 {
00022   this->orb_type_ = orb_type;
00023   this->orb_type_set_ = 1;
00024 
00025   TAO_OutputCDR cdr;
00026   cdr << ACE_OutputCDR::from_boolean (TAO_ENCAP_BYTE_ORDER);
00027   cdr << this->orb_type_;
00028 
00029   this->set_component_i (IOP::TAG_ORB_TYPE, cdr);
00030 }
00031 
00032 void
00033 TAO_Tagged_Components::set_code_sets (
00034     const CONV_FRAME::CodeSetComponentInfo &ci)
00035 {
00036   this->code_sets_ = ci;
00037   this->code_sets_set_ = 1;
00038 
00039   TAO_OutputCDR cdr;
00040   cdr << ACE_OutputCDR::from_boolean (TAO_ENCAP_BYTE_ORDER);
00041   cdr << this->code_sets_;
00042 
00043   this->set_component_i (IOP::TAG_CODE_SETS, cdr);
00044 }
00045 
00046 void
00047 TAO_Tagged_Components::set_code_sets (CONV_FRAME::CodeSetComponentInfo &ci)
00048 {
00049   this->set_code_sets_i (this->code_sets_.ForCharData, ci.ForCharData);
00050   this->set_code_sets_i (this->code_sets_.ForWcharData, ci.ForWcharData);
00051   this->code_sets_set_ = 1;
00052 
00053   TAO_OutputCDR cdr;
00054   cdr << ACE_OutputCDR::from_boolean (TAO_ENCAP_BYTE_ORDER);
00055   cdr << this->code_sets_;
00056 
00057   this->set_component_i (IOP::TAG_CODE_SETS, cdr);
00058 }
00059 
00060 void
00061 TAO_Tagged_Components::set_code_sets_i (
00062     CONV_FRAME::CodeSetComponent &lhs,
00063     CONV_FRAME::CodeSetComponent &rhs)
00064 {
00065   lhs.native_code_set = rhs.native_code_set;
00066   CORBA::ULong max = rhs.conversion_code_sets.maximum ();
00067   CORBA::ULong len = rhs.conversion_code_sets.length ();
00068   CONV_FRAME::CodeSetId *buffer = rhs.conversion_code_sets.get_buffer (1);
00069   lhs.conversion_code_sets.replace (max, len, buffer, 1);
00070 }
00071 
00072 // ****************************************************************
00073 
00074 void
00075 TAO_Tagged_Components::set_component_i (IOP::ComponentId tag,
00076                                         TAO_OutputCDR &cdr)
00077 {
00078   IOP::TaggedComponent component;
00079   component.tag = tag;
00080 
00081   // Make a *copy* of the CDR stream...
00082   size_t length = cdr.total_length ();
00083   component.component_data.length (static_cast<CORBA::ULong> (length));
00084   CORBA::Octet *buf = component.component_data.get_buffer ();
00085 
00086   for (const ACE_Message_Block *i = cdr.begin ();
00087        i != 0;
00088        i = i->cont ())
00089     {
00090       ACE_OS::memcpy (buf, i->rd_ptr (), i->length ());
00091       buf += i->length ();
00092     }
00093 
00094   this->set_component_i (component);
00095 }
00096 
00097 void
00098 TAO_Tagged_Components::set_component (const IOP::TaggedComponent& component)
00099 {
00100   if (this->known_tag (component.tag))
00101     {
00102       this->set_known_component_i (component);
00103     }
00104 
00105   if (this->unique_tag (component.tag))
00106     {
00107       this->set_component_i (component);
00108     }
00109   else
00110     {
00111       this->add_component_i (component);
00112     }
00113 }
00114 
00115 void
00116 TAO_Tagged_Components::set_component (IOP::TaggedComponent& component)
00117 {
00118   if (this->known_tag (component.tag))
00119     {
00120       this->set_known_component_i (component);
00121     }
00122 
00123   if (this->unique_tag (component.tag))
00124     {
00125       this->set_component_i (component);
00126     }
00127   else
00128     {
00129       this->add_component_i (component);
00130     }
00131 }
00132 
00133 void
00134 TAO_Tagged_Components::set_known_component_i (
00135     const IOP::TaggedComponent& component)
00136 {
00137   TAO_InputCDR cdr (reinterpret_cast<const char*> (
00138                       component.component_data.get_buffer ()),
00139                     component.component_data.length ());
00140 
00141   CORBA::Boolean byte_order;
00142 
00143   if ((cdr >> ACE_InputCDR::to_boolean (byte_order)) == 0)
00144     {
00145       return;
00146     }
00147 
00148   cdr.reset_byte_order (static_cast<int> (byte_order));
00149 
00150   if (component.tag == IOP::TAG_ORB_TYPE)
00151     {
00152       CORBA::ULong orb_type;
00153 
00154       if ((cdr >> orb_type) == 0)
00155         {
00156           return;
00157         }
00158 
00159       this->orb_type_ = orb_type;
00160       this->orb_type_set_ = 1;
00161     }
00162   else if (component.tag == IOP::TAG_CODE_SETS)
00163     {
00164       CONV_FRAME::CodeSetComponentInfo ci;
00165 
00166       if ((cdr >> ci) == 0)
00167         {
00168           return;
00169         }
00170 
00171       this->set_code_sets_i (this->code_sets_.ForCharData, ci.ForCharData);
00172       this->set_code_sets_i (this->code_sets_.ForWcharData, ci.ForWcharData);
00173       this->code_sets_set_ = 1;
00174     }
00175 }
00176 
00177 void
00178 TAO_Tagged_Components::set_component_i (const IOP::TaggedComponent& component)
00179 {
00180   // @@ TODO Some components can show up multiple times, others
00181   //    can't find out and take appropiate action.
00182   for (CORBA::ULong i = 0; i != this->components_.length (); ++i)
00183     {
00184       if (component.tag == this->components_[i].tag)
00185         {
00186           this->components_[i] = component;
00187           return;
00188         }
00189     }
00190 
00191   this->add_component_i (component);
00192 }
00193 
00194 void
00195 TAO_Tagged_Components::set_component_i (IOP::TaggedComponent& component)
00196 {
00197   for (CORBA::ULong i = 0; i != this->components_.length (); ++i)
00198     {
00199       if (component.tag == this->components_[i].tag)
00200         {
00201           CORBA::ULong max = component.component_data.maximum ();
00202           CORBA::ULong len = component.component_data.length ();
00203           CORBA::Octet* buf = component.component_data.get_buffer (1);
00204           this->components_[i].component_data.replace (max, len, buf, 1);
00205           return;
00206         }
00207     }
00208 
00209   this->add_component_i (component);
00210 }
00211 
00212 void
00213 TAO_Tagged_Components::add_component_i (IOP::TaggedComponent& component)
00214 {
00215   // @@ TODO Some components can show up multiple times, others
00216   //    can't find out and take appropiate action.
00217   CORBA::ULong l = this->components_.length ();
00218   this->components_.length (l + 1);
00219   this->components_[l].tag = component.tag;
00220   CORBA::ULong max = component.component_data.maximum ();
00221   CORBA::ULong len = component.component_data.length ();
00222   CORBA::Octet* buf = component.component_data.get_buffer (1);
00223   this->components_[l].component_data.replace (max, len, buf, 1);
00224 }
00225 
00226 void
00227 TAO_Tagged_Components::add_component_i (const IOP::TaggedComponent& component)
00228 {
00229   // @@ TODO Some components can show up multiple times, others
00230   //    can't find out and take appropiate action.
00231   CORBA::ULong l = this->components_.length ();
00232   this->components_.length (l + 1);
00233   this->components_[l] = component;
00234 }
00235 
00236 int
00237 TAO_Tagged_Components::remove_component (IOP::ComponentId id)
00238 {
00239   if (this->known_tag (id))
00240     {
00241       return this->remove_known_component_i (id);
00242     }
00243   else
00244     {
00245       return this->remove_component_i (id);
00246     }
00247 }
00248 
00249 int
00250 TAO_Tagged_Components::remove_known_component_i (IOP::ComponentId tag)
00251 {
00252   if (tag == IOP::TAG_ORB_TYPE)
00253     {
00254       this->orb_type_ = 0;
00255       this->orb_type_set_ = 0;
00256       return 1;
00257     }
00258   else if (tag == IOP::TAG_CODE_SETS)
00259     {
00260       this->code_sets_set_ = 0;
00261       return 1;
00262     }
00263   else
00264     {
00265       return 0;
00266     }
00267 }
00268 
00269 int
00270 TAO_Tagged_Components::remove_component_i (IOP::ComponentId tag)
00271 {
00272   CORBA::ULong src = 0, dest = 0;
00273   CORBA::ULong len = this->components_.length ();
00274 
00275   for (;src != len;++src)
00276     {
00277       if ( tag != this->components_[src].tag)
00278         {
00279           this->components_[dest] = this->components_[src];
00280           ++dest;
00281         }
00282     }
00283 
00284   this->components_.length (dest);
00285   return src - dest;
00286 }
00287 
00288 int
00289 TAO_Tagged_Components::get_component (IOP::TaggedComponent& component) const
00290 {
00291   for (CORBA::ULong i = 0; i != this->components_.length (); ++i)
00292     {
00293       if (component.tag == this->components_[i].tag)
00294         {
00295           component = this->components_[i];
00296           return 1;
00297         }
00298     }
00299 
00300   return 0;
00301 }
00302 
00303 // ****************************************************************
00304 
00305 int
00306 TAO_Tagged_Components::encode (TAO_OutputCDR& cdr) const
00307 {
00308   return (cdr << this->components_);
00309 }
00310 
00311 int
00312 TAO_Tagged_Components::decode (TAO_InputCDR& cdr)
00313 {
00314   // Mark the well-known components as removed
00315   this->orb_type_set_ = 0;
00316   this->code_sets_set_ = 0;
00317 
00318   if ((cdr >> this->components_) == 0)
00319     {
00320       return 0;
00321     }
00322 
00323   CORBA::ULong const l = this->components_.length ();
00324 
00325   for (CORBA::ULong i = 0; i != l; ++i)
00326     {
00327       const IOP::TaggedComponent &component = this->components_[i];
00328 
00329       if (this->known_tag (component.tag))
00330         {
00331           this->set_known_component_i (component);
00332         }
00333     }
00334 
00335   return 1;
00336 }
00337 
00338 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Tue Feb 2 17:37:52 2010 for TAO by  doxygen 1.4.7