s/Uint/UInt/g
[ACE_TAO.git] / TAO / tao / Tagged_Components.cpp
bloba93161ce9fefaffb07f4fabdca18ca211850d207
1 #include "tao/Tagged_Components.h"
2 #include "tao/CDR.h"
4 #if !defined (__ACE_INLINE__)
5 # include "tao/Tagged_Components.inl"
6 #endif /* ! __ACE_INLINE__ */
8 #include "ace/OS_NS_string.h"
10 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
12 void
13 TAO_Tagged_Components::set_orb_type (CORBA::ULong orb_type)
15 this->orb_type_ = orb_type;
16 this->orb_type_set_ = 1;
18 TAO_OutputCDR cdr;
19 cdr << ACE_OutputCDR::from_boolean (TAO_ENCAP_BYTE_ORDER);
20 cdr << this->orb_type_;
22 this->set_component_i (IOP::TAG_ORB_TYPE, cdr);
25 void
26 TAO_Tagged_Components::set_code_sets (
27 const CONV_FRAME::CodeSetComponentInfo &ci)
29 this->code_sets_ = ci;
30 this->code_sets_set_ = 1;
32 TAO_OutputCDR cdr;
33 cdr << ACE_OutputCDR::from_boolean (TAO_ENCAP_BYTE_ORDER);
34 cdr << this->code_sets_;
36 this->set_component_i (IOP::TAG_CODE_SETS, cdr);
39 void
40 TAO_Tagged_Components::set_code_sets (CONV_FRAME::CodeSetComponentInfo &ci)
42 this->set_code_sets_i (this->code_sets_.ForCharData, ci.ForCharData);
43 this->set_code_sets_i (this->code_sets_.ForWcharData, ci.ForWcharData);
44 this->code_sets_set_ = 1;
46 TAO_OutputCDR cdr;
47 cdr << ACE_OutputCDR::from_boolean (TAO_ENCAP_BYTE_ORDER);
48 cdr << this->code_sets_;
50 this->set_component_i (IOP::TAG_CODE_SETS, cdr);
53 void
54 TAO_Tagged_Components::set_code_sets_i (
55 CONV_FRAME::CodeSetComponent &lhs,
56 CONV_FRAME::CodeSetComponent &rhs)
58 lhs.native_code_set = rhs.native_code_set;
59 CORBA::ULong const max = rhs.conversion_code_sets.maximum ();
60 CORBA::ULong const len = rhs.conversion_code_sets.length ();
61 CONV_FRAME::CodeSetId *buffer = rhs.conversion_code_sets.get_buffer (true);
62 lhs.conversion_code_sets.replace (max, len, buffer, true);
65 // ****************************************************************
67 void
68 TAO_Tagged_Components::set_component_i (IOP::ComponentId tag,
69 TAO_OutputCDR &cdr)
71 IOP::TaggedComponent component;
72 component.tag = tag;
74 // Make a *copy* of the CDR stream...
75 size_t length = cdr.total_length ();
76 component.component_data.length (static_cast<CORBA::ULong> (length));
77 CORBA::Octet *buf = component.component_data.get_buffer ();
79 for (const ACE_Message_Block *i = cdr.begin ();
80 i != nullptr;
81 i = i->cont ())
83 ACE_OS::memcpy (buf, i->rd_ptr (), i->length ());
84 buf += i->length ();
87 this->set_component_i (component);
90 void
91 TAO_Tagged_Components::set_component (const IOP::TaggedComponent& component)
93 if (this->known_tag (component.tag))
95 this->set_known_component_i (component);
98 if (this->unique_tag (component.tag))
100 this->set_component_i (component);
102 else
104 this->add_component_i (component);
108 void
109 TAO_Tagged_Components::set_component (IOP::TaggedComponent& component)
111 if (this->known_tag (component.tag))
113 this->set_known_component_i (component);
116 if (this->unique_tag (component.tag))
118 this->set_component_i (component);
120 else
122 this->add_component_i (component);
126 void
127 TAO_Tagged_Components::set_known_component_i (
128 const IOP::TaggedComponent& component)
130 TAO_InputCDR cdr (reinterpret_cast<const char*> (
131 component.component_data.get_buffer ()),
132 component.component_data.length ());
134 CORBA::Boolean byte_order;
136 if (!(cdr >> ACE_InputCDR::to_boolean (byte_order)))
138 return;
141 cdr.reset_byte_order (static_cast<int> (byte_order));
143 if (component.tag == IOP::TAG_ORB_TYPE)
145 CORBA::ULong orb_type;
147 if (!(cdr >> orb_type))
149 return;
152 this->orb_type_ = orb_type;
153 this->orb_type_set_ = 1;
155 else if (component.tag == IOP::TAG_CODE_SETS)
157 CONV_FRAME::CodeSetComponentInfo ci;
159 if (!(cdr >> ci))
161 return;
164 this->set_code_sets_i (this->code_sets_.ForCharData, ci.ForCharData);
165 this->set_code_sets_i (this->code_sets_.ForWcharData, ci.ForWcharData);
166 this->code_sets_set_ = 1;
170 void
171 TAO_Tagged_Components::set_component_i (const IOP::TaggedComponent& component)
173 // @@ TODO Some components can show up multiple times, others
174 // can't find out and take appropriate action.
175 for (CORBA::ULong i = 0; i != this->components_.length (); ++i)
177 if (component.tag == this->components_[i].tag)
179 this->components_[i] = component;
180 return;
184 this->add_component_i (component);
187 void
188 TAO_Tagged_Components::set_component_i (IOP::TaggedComponent& component)
190 for (CORBA::ULong i = 0; i != this->components_.length (); ++i)
192 if (component.tag == this->components_[i].tag)
194 CORBA::ULong max = component.component_data.maximum ();
195 CORBA::ULong len = component.component_data.length ();
196 CORBA::Octet* buf = component.component_data.get_buffer (1);
197 this->components_[i].component_data.replace (max, len, buf, 1);
198 return;
202 this->add_component_i (component);
205 void
206 TAO_Tagged_Components::add_component_i (IOP::TaggedComponent& component)
208 // @@ TODO Some components can show up multiple times, others
209 // can't find out and take appropriate action.
210 CORBA::ULong l = this->components_.length ();
211 this->components_.length (l + 1);
212 this->components_[l].tag = component.tag;
213 CORBA::ULong max = component.component_data.maximum ();
214 CORBA::ULong len = component.component_data.length ();
215 CORBA::Octet* buf = component.component_data.get_buffer (1);
216 this->components_[l].component_data.replace (max, len, buf, 1);
219 void
220 TAO_Tagged_Components::add_component_i (const IOP::TaggedComponent& component)
222 // @@ TODO Some components can show up multiple times, others
223 // can't find out and take appropriate action.
224 CORBA::ULong l = this->components_.length ();
225 this->components_.length (l + 1);
226 this->components_[l] = component;
230 TAO_Tagged_Components::remove_component (IOP::ComponentId id)
232 if (this->known_tag (id))
234 return this->remove_known_component_i (id);
236 else
238 return this->remove_component_i (id);
243 TAO_Tagged_Components::remove_known_component_i (IOP::ComponentId tag)
245 if (tag == IOP::TAG_ORB_TYPE)
247 this->orb_type_ = 0;
248 this->orb_type_set_ = 0;
249 return 1;
251 else if (tag == IOP::TAG_CODE_SETS)
253 this->code_sets_set_ = 0;
254 return 1;
256 else
258 return 0;
263 TAO_Tagged_Components::remove_component_i (IOP::ComponentId tag)
265 CORBA::ULong src = 0, dest = 0;
266 CORBA::ULong len = this->components_.length ();
268 for (;src != len;++src)
270 if ( tag != this->components_[src].tag)
272 this->components_[dest] = this->components_[src];
273 ++dest;
277 this->components_.length (dest);
278 return src - dest;
282 TAO_Tagged_Components::get_component (IOP::TaggedComponent& component) const
284 for (CORBA::ULong i = 0; i != this->components_.length (); ++i)
286 if (component.tag == this->components_[i].tag)
288 component = this->components_[i];
289 return 1;
293 return 0;
296 // ****************************************************************
299 TAO_Tagged_Components::encode (TAO_OutputCDR& cdr) const
301 return (cdr << this->components_);
305 TAO_Tagged_Components::decode (TAO_InputCDR& cdr)
307 // Mark the well-known components as removed
308 this->orb_type_set_ = 0;
309 this->code_sets_set_ = 0;
311 if (!(cdr >> this->components_))
313 return 0;
316 CORBA::ULong const l = this->components_.length ();
318 for (CORBA::ULong i = 0; i != l; ++i)
320 const IOP::TaggedComponent &component = this->components_[i];
322 if (this->known_tag (component.tag))
324 this->set_known_component_i (component);
328 return 1;
331 TAO_END_VERSIONED_NAMESPACE_DECL