2 #include "tao/Service_Context.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
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 ();
28 ACE_OS::memcpy (buf
, i
->rd_ptr (), i
->length ());
32 this->set_context_i (context
);
36 TAO_Service_Context::set_context_i (IOP::ServiceContext
&context
,
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 ();
48 ACE_OS::memcpy (buf
, i
->rd_ptr (), i
->length ());
54 TAO_Service_Context::set_context (const IOP::ServiceContext
&context
)
56 this->add_context_i (context
);
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
)
69 this->service_context_
[i
] = context
;
79 this->add_context_i (context
);
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
;
97 this->add_context_i (context
);
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);
115 this->add_context_i (context
);
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);
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
];
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
];
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
];
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_
))
211 TAO_END_VERSIONED_NAMESPACE_DECL