Tagged_Components.cpp

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

Generated on Thu Nov 9 11:54:23 2006 for TAO by doxygen 1.3.6