Go to the documentation of this file.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 82034 2008-06-18 11:59:23Z 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_i (const IOP::ServiceContext& context)
00091 {
00092
00093
00094 for (CORBA::ULong i = 0; i != this->service_context_.length (); ++i)
00095 {
00096 if (context.context_id == this->service_context_[i].context_id)
00097 {
00098 this->service_context_[i] = context;
00099 return;
00100 }
00101 }
00102
00103 this->add_context_i (context);
00104 }
00105
00106 void
00107 TAO_Service_Context::set_context_i (IOP::ServiceContext& context)
00108 {
00109 for (CORBA::ULong i = 0; i != this->service_context_.length (); ++i)
00110 {
00111 if (context.context_id == this->service_context_[i].context_id)
00112 {
00113 CORBA::ULong const max = context.context_data.maximum ();
00114 CORBA::ULong const len = context.context_data.length ();
00115 CORBA::Octet * const buf = context.context_data.get_buffer (1);
00116 this->service_context_[i].context_data.replace (max, len, buf, 1);
00117 return;
00118 }
00119 }
00120
00121 this->add_context_i (context);
00122 }
00123
00124 void
00125 TAO_Service_Context::add_context_i (IOP::ServiceContext& context)
00126 {
00127
00128
00129 CORBA::ULong const l = this->service_context_.length ();
00130 this->service_context_.length (l + 1);
00131 this->service_context_[l].context_id = context.context_id;
00132 CORBA::ULong const max = context.context_data.maximum ();
00133 CORBA::ULong const len = context.context_data.length ();
00134 CORBA::Octet* const buf = context.context_data.get_buffer (1);
00135 this->service_context_[l].context_data.replace (max, len, buf, 1);
00136 }
00137
00138 void
00139 TAO_Service_Context::add_context_i (const IOP::ServiceContext& context)
00140 {
00141
00142
00143 CORBA::ULong const l = this->service_context_.length ();
00144 this->service_context_.length (l + 1);
00145 this->service_context_[l] = context;
00146 }
00147
00148 int
00149 TAO_Service_Context::get_context (IOP::ServiceContext& context) const
00150 {
00151 for (CORBA::ULong i = 0; i != this->service_context_.length (); ++i)
00152 {
00153 if (context.context_id == this->service_context_[i].context_id)
00154 {
00155 context = this->service_context_[i];
00156 return 1;
00157 }
00158 }
00159
00160 return 0;
00161 }
00162
00163 int
00164 TAO_Service_Context::get_context (IOP::ServiceId id,
00165 const IOP::ServiceContext **context) const
00166 {
00167 for (CORBA::ULong i = 0; i != this->service_context_.length (); ++i)
00168 {
00169 if (id == this->service_context_[i].context_id)
00170 {
00171 *context = &this->service_context_[i];
00172 return 1;
00173 }
00174 }
00175
00176 return 0;
00177 }
00178
00179 int
00180 TAO_Service_Context::get_context (IOP::ServiceId id,
00181 IOP::ServiceContext_out context)
00182 {
00183 CORBA::ULong const len = this->service_context_.length ();
00184
00185 for (CORBA::ULong i = 0; i < len; ++i)
00186 {
00187 if (id == this->service_context_[i].context_id)
00188 {
00189 ACE_NEW_RETURN (context, IOP::ServiceContext, 0);
00190
00191 *(context.ptr ()) = this->service_context_[i];
00192
00193 return 1;
00194 }
00195 }
00196
00197 return 0;
00198 }
00199
00200 int
00201 TAO_Service_Context::encode (TAO_OutputCDR& cdr) const
00202 {
00203 return (cdr << this->service_context_);
00204 }
00205
00206 int
00207 TAO_Service_Context::decode (TAO_InputCDR& cdr)
00208 {
00209 if (!(cdr >> this->service_context_))
00210 {
00211 return 0;
00212 }
00213
00214 return 1;
00215 }
00216
00217 TAO_END_VERSIONED_NAMESPACE_DECL