00001
00002
00003 #include "tao/Service_Context.h"
00004 #include "tao/CDR.h"
00005
00006 #if !defined (__ACE_INLINE__)
00007 # include "tao/Service_Context.inl"
00008 #endif
00009
00010 #include "ace/OS_NS_string.h"
00011
00012 ACE_RCSID (tao,
00013 Service_Context,
00014 "Service_Context.cpp,v 1.12 2006/04/19 09:07:09 jwillemsen Exp")
00015
00016
00017 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00018
00019 void
00020 TAO_Service_Context::set_context_i (IOP::ServiceId id,
00021 TAO_OutputCDR &cdr)
00022 {
00023 IOP::ServiceContext context;
00024 context.context_id = id;
00025
00026
00027 size_t const length = cdr.total_length ();
00028 context.context_data.length (static_cast<CORBA::ULong> (length));
00029 CORBA::Octet *buf = context.context_data.get_buffer ();
00030
00031 for (const ACE_Message_Block *i = cdr.begin ();
00032 i != 0;
00033 i = i->cont ())
00034 {
00035 ACE_OS::memcpy (buf, i->rd_ptr (), i->length ());
00036 buf += i->length ();
00037 }
00038
00039 this->set_context_i (context);
00040 }
00041
00042 void
00043 TAO_Service_Context::set_context_i (IOP::ServiceContext &context,
00044 TAO_OutputCDR &cdr)
00045 {
00046
00047 size_t const length = cdr.total_length ();
00048 context.context_data.length (static_cast<CORBA::ULong> (length));
00049 CORBA::Octet *buf = context.context_data.get_buffer ();
00050
00051 for (const ACE_Message_Block *i = cdr.begin ();
00052 i != 0;
00053 i = i->cont ())
00054 {
00055 ACE_OS::memcpy (buf, i->rd_ptr (), i->length ());
00056 buf += i->length ();
00057 }
00058 }
00059
00060 void
00061 TAO_Service_Context::set_context (const IOP::ServiceContext &context)
00062 {
00063 this->add_context_i (context);
00064 }
00065
00066 int
00067 TAO_Service_Context::set_context (const IOP::ServiceContext &context,
00068 CORBA::Boolean replace)
00069 {
00070 for (CORBA::ULong i = 0; i != this->service_context_.length (); ++i)
00071 {
00072 if (context.context_id == this->service_context_[i].context_id)
00073 {
00074 if (replace)
00075 {
00076 this->service_context_[i] = context;
00077 return 1;
00078 }
00079 else
00080 {
00081 return 0;
00082 }
00083 }
00084 }
00085
00086 this->add_context_i (context);
00087 return 1;
00088 }
00089
00090 void
00091 TAO_Service_Context::set_context (IOP::ServiceContext &context)
00092 {
00093 this->add_context_i (context);
00094 }
00095
00096 void
00097 TAO_Service_Context::set_context_i (const IOP::ServiceContext& context)
00098 {
00099
00100
00101 for (CORBA::ULong i = 0; i != this->service_context_.length (); ++i)
00102 {
00103 if (context.context_id == this->service_context_[i].context_id)
00104 {
00105 this->service_context_[i] = context;
00106 return;
00107 }
00108 }
00109
00110 this->add_context_i (context);
00111 }
00112
00113 void
00114 TAO_Service_Context::set_context_i (IOP::ServiceContext& context)
00115 {
00116 for (CORBA::ULong i = 0; i != this->service_context_.length (); ++i)
00117 {
00118 if (context.context_id == this->service_context_[i].context_id)
00119 {
00120 CORBA::ULong const max = context.context_data.maximum ();
00121 CORBA::ULong const len = context.context_data.length ();
00122 CORBA::Octet * const buf = context.context_data.get_buffer (1);
00123 this->service_context_[i].context_data.replace (max, len, buf, 1);
00124 return;
00125 }
00126 }
00127
00128 this->add_context_i (context);
00129 }
00130
00131 void
00132 TAO_Service_Context::add_context_i (IOP::ServiceContext& context)
00133 {
00134
00135
00136 CORBA::ULong const l = this->service_context_.length ();
00137 this->service_context_.length (l + 1);
00138 this->service_context_[l].context_id = context.context_id;
00139 CORBA::ULong const max = context.context_data.maximum ();
00140 CORBA::ULong const len = context.context_data.length ();
00141 CORBA::Octet* const buf = context.context_data.get_buffer (1);
00142 this->service_context_[l].context_data.replace (max, len, buf, 1);
00143 }
00144
00145 void
00146 TAO_Service_Context::add_context_i (const IOP::ServiceContext& context)
00147 {
00148
00149
00150 CORBA::ULong const l = this->service_context_.length ();
00151 this->service_context_.length (l + 1);
00152 this->service_context_[l] = context;
00153 }
00154
00155 int
00156 TAO_Service_Context::get_context (IOP::ServiceContext& context) const
00157 {
00158 for (CORBA::ULong i = 0; i != this->service_context_.length (); ++i)
00159 {
00160 if (context.context_id == this->service_context_[i].context_id)
00161 {
00162 context = this->service_context_[i];
00163 return 1;
00164 }
00165 }
00166
00167 return 0;
00168 }
00169
00170 int
00171 TAO_Service_Context::get_context (IOP::ServiceId id,
00172 const IOP::ServiceContext **context) const
00173 {
00174 for (CORBA::ULong i = 0; i != this->service_context_.length (); ++i)
00175 {
00176 if (id == this->service_context_[i].context_id)
00177 {
00178 *context = &this->service_context_[i];
00179 return 1;
00180 }
00181 }
00182
00183 return 0;
00184 }
00185
00186 int
00187 TAO_Service_Context::get_context (IOP::ServiceId id,
00188 IOP::ServiceContext_out context)
00189 {
00190 CORBA::ULong const len = this->service_context_.length ();
00191
00192 for (CORBA::ULong i = 0; i < len; ++i)
00193 {
00194 if (id == this->service_context_[i].context_id)
00195 {
00196 ACE_NEW_RETURN (context, IOP::ServiceContext, 0);
00197
00198 *(context.ptr ()) = this->service_context_[i];
00199
00200 return 1;
00201 }
00202 }
00203
00204 return 0;
00205 }
00206
00207 int
00208 TAO_Service_Context::encode (TAO_OutputCDR& cdr) const
00209 {
00210 return (cdr << this->service_context_);
00211 }
00212
00213 int
00214 TAO_Service_Context::decode (TAO_InputCDR& cdr)
00215 {
00216 if ((cdr >> this->service_context_) == 0)
00217 {
00218 return 0;
00219 }
00220
00221 return 1;
00222 }
00223
00224 TAO_END_VERSIONED_NAMESPACE_DECL