Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tao / Service_Context.cpp
blob7f29afdd6bc64df43bd21ee930891c1df2b6bd55
1 // -*- C++ -*-
2 #include "tao/Service_Context.h"
3 #include "tao/CDR.h"
5 #if !defined (__ACE_INLINE__)
6 # include "tao/Service_Context.inl"
7 #endif /* ! __ACE_INLINE__ */
9 #include "ace/OS_NS_string.h"
11 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
13 void
14 TAO_Service_Context::set_context_i (IOP::ServiceId id, TAO_OutputCDR &cdr)
16 IOP::ServiceContext context;
17 context.context_id = id;
19 // Make a *copy* of the CDR stream...
20 size_t const length = cdr.total_length ();
21 context.context_data.length (static_cast<CORBA::ULong> (length));
22 CORBA::Octet *buf = context.context_data.get_buffer ();
24 for (const ACE_Message_Block *i = cdr.begin ();
25 i != nullptr;
26 i = i->cont ())
28 ACE_OS::memcpy (buf, i->rd_ptr (), i->length ());
29 buf += i->length ();
32 this->set_context_i (context);
35 void
36 TAO_Service_Context::set_context_i (IOP::ServiceContext &context,
37 TAO_OutputCDR &cdr)
39 // Make a *copy* of the CDR stream...
40 size_t const length = cdr.total_length ();
41 context.context_data.length (static_cast<CORBA::ULong> (length));
42 CORBA::Octet *buf = context.context_data.get_buffer ();
44 for (const ACE_Message_Block *i = cdr.begin ();
45 i != nullptr;
46 i = i->cont ())
48 ACE_OS::memcpy (buf, i->rd_ptr (), i->length ());
49 buf += i->length ();
53 void
54 TAO_Service_Context::set_context (const IOP::ServiceContext &context)
56 this->add_context_i (context);
59 int
60 TAO_Service_Context::set_context (const IOP::ServiceContext &context,
61 CORBA::Boolean replace)
63 for (CORBA::ULong i = 0; i != this->service_context_.length (); ++i)
65 if (context.context_id == this->service_context_[i].context_id)
67 if (replace)
69 this->service_context_[i] = context;
70 return 1;
72 else
74 return 0;
79 this->add_context_i (context);
80 return 1;
83 void
84 TAO_Service_Context::set_context_i (const IOP::ServiceContext& context)
86 // @@ TODO Some contexts can show up multiple times, others
87 // can't find out and take appropriate action.
88 for (CORBA::ULong i = 0; i != this->service_context_.length (); ++i)
90 if (context.context_id == this->service_context_[i].context_id)
92 this->service_context_[i] = context;
93 return;
97 this->add_context_i (context);
100 void
101 TAO_Service_Context::set_context_i (IOP::ServiceContext& context)
103 for (CORBA::ULong i = 0; i != this->service_context_.length (); ++i)
105 if (context.context_id == this->service_context_[i].context_id)
107 CORBA::ULong const max = context.context_data.maximum ();
108 CORBA::ULong const len = context.context_data.length ();
109 CORBA::Octet * const buf = context.context_data.get_buffer (1);
110 this->service_context_[i].context_data.replace (max, len, buf, 1);
111 return;
115 this->add_context_i (context);
118 void
119 TAO_Service_Context::add_context_i (IOP::ServiceContext& context)
121 // @@ TODO Some contexts can show up multiple times, others
122 // can't find out and take appropriate action.
123 CORBA::ULong const l = this->service_context_.length ();
124 this->service_context_.length (l + 1);
125 this->service_context_[l].context_id = context.context_id;
126 CORBA::ULong const max = context.context_data.maximum ();
127 CORBA::ULong const len = context.context_data.length ();
128 CORBA::Octet* const buf = context.context_data.get_buffer (1);
129 this->service_context_[l].context_data.replace (max, len, buf, 1);
132 void
133 TAO_Service_Context::add_context_i (const IOP::ServiceContext& context)
135 // @@ TODO Some contexts can show up multiple times, others
136 // can't find out and take appropriate action.
137 CORBA::ULong const l = this->service_context_.length ();
138 this->service_context_.length (l + 1);
139 this->service_context_[l] = context;
143 TAO_Service_Context::get_context (IOP::ServiceContext& context) const
145 for (CORBA::ULong i = 0; i != this->service_context_.length (); ++i)
147 if (context.context_id == this->service_context_[i].context_id)
149 context = this->service_context_[i];
150 return 1;
154 return 0;
158 TAO_Service_Context::get_context (IOP::ServiceId id,
159 const IOP::ServiceContext **context) const
161 for (CORBA::ULong i = 0; i != this->service_context_.length (); ++i)
163 if (id == this->service_context_[i].context_id)
165 *context = &this->service_context_[i];
166 return 1;
170 return 0;
174 TAO_Service_Context::get_context (IOP::ServiceId id,
175 IOP::ServiceContext_out context)
177 CORBA::ULong const len = this->service_context_.length ();
179 for (CORBA::ULong i = 0; i < len; ++i)
181 if (id == this->service_context_[i].context_id)
183 ACE_NEW_RETURN (context, IOP::ServiceContext, 0);
185 *(context.ptr ()) = this->service_context_[i];
187 return 1;
191 return 0;
195 TAO_Service_Context::encode (TAO_OutputCDR& cdr) const
197 return (cdr << this->service_context_);
201 TAO_Service_Context::decode (TAO_InputCDR& cdr)
203 if (!(cdr >> this->service_context_))
205 return 0;
208 return 1;
211 TAO_END_VERSIONED_NAMESPACE_DECL