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