summaryrefslogtreecommitdiff
path: root/TAO/tao/Service_Context.cpp
blob: 7f29afdd6bc64df43bd21ee930891c1df2b6bd55 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
// -*- C++ -*-
#include "tao/Service_Context.h"
#include "tao/CDR.h"

#if !defined (__ACE_INLINE__)
# include "tao/Service_Context.inl"
#endif /* ! __ACE_INLINE__ */

#include "ace/OS_NS_string.h"

TAO_BEGIN_VERSIONED_NAMESPACE_DECL

void
TAO_Service_Context::set_context_i (IOP::ServiceId id, TAO_OutputCDR &cdr)
{
  IOP::ServiceContext context;
  context.context_id = id;

  // Make a *copy* of the CDR stream...
  size_t const length = cdr.total_length ();
  context.context_data.length (static_cast<CORBA::ULong> (length));
  CORBA::Octet *buf = context.context_data.get_buffer ();

  for (const ACE_Message_Block *i = cdr.begin ();
       i != nullptr;
       i = i->cont ())
    {
      ACE_OS::memcpy (buf, i->rd_ptr (), i->length ());
      buf += i->length ();
    }

  this->set_context_i (context);
}

void
TAO_Service_Context::set_context_i (IOP::ServiceContext &context,
                                    TAO_OutputCDR &cdr)
{
  // Make a *copy* of the CDR stream...
  size_t const length = cdr.total_length ();
  context.context_data.length (static_cast<CORBA::ULong> (length));
  CORBA::Octet *buf = context.context_data.get_buffer ();

  for (const ACE_Message_Block *i = cdr.begin ();
       i != nullptr;
       i = i->cont ())
    {
      ACE_OS::memcpy (buf, i->rd_ptr (), i->length ());
      buf += i->length ();
    }
}

void
TAO_Service_Context::set_context (const IOP::ServiceContext &context)
{
  this->add_context_i (context);
}

int
TAO_Service_Context::set_context (const IOP::ServiceContext &context,
                                  CORBA::Boolean replace)
{
  for (CORBA::ULong i = 0; i != this->service_context_.length (); ++i)
    {
      if (context.context_id == this->service_context_[i].context_id)
        {
          if (replace)
            {
              this->service_context_[i] = context;
              return 1;
            }
          else
            {
              return 0;
            }
        }
    }

  this->add_context_i (context);
  return 1;
}

void
TAO_Service_Context::set_context_i (const IOP::ServiceContext& context)
{
  // @@ TODO Some contexts can show up multiple times, others
  //    can't find out and take appropriate action.
  for (CORBA::ULong i = 0; i != this->service_context_.length (); ++i)
    {
      if (context.context_id == this->service_context_[i].context_id)
        {
          this->service_context_[i] = context;
          return;
        }
    }

  this->add_context_i (context);
}

void
TAO_Service_Context::set_context_i (IOP::ServiceContext& context)
{
  for (CORBA::ULong i = 0; i != this->service_context_.length (); ++i)
    {
      if (context.context_id == this->service_context_[i].context_id)
        {
          CORBA::ULong const max = context.context_data.maximum ();
          CORBA::ULong const len = context.context_data.length ();
          CORBA::Octet * const buf = context.context_data.get_buffer (1);
          this->service_context_[i].context_data.replace (max, len, buf, 1);
          return;
        }
    }

  this->add_context_i (context);
}

void
TAO_Service_Context::add_context_i (IOP::ServiceContext& context)
{
  // @@ TODO Some contexts can show up multiple times, others
  //    can't find out and take appropriate action.
  CORBA::ULong const l = this->service_context_.length ();
  this->service_context_.length (l + 1);
  this->service_context_[l].context_id = context.context_id;
  CORBA::ULong const max = context.context_data.maximum ();
  CORBA::ULong const len = context.context_data.length ();
  CORBA::Octet* const buf = context.context_data.get_buffer (1);
  this->service_context_[l].context_data.replace (max, len, buf, 1);
}

void
TAO_Service_Context::add_context_i (const IOP::ServiceContext& context)
{
  // @@ TODO Some contexts can show up multiple times, others
  //    can't find out and take appropriate action.
  CORBA::ULong const l = this->service_context_.length ();
  this->service_context_.length (l + 1);
  this->service_context_[l] = context;
}

int
TAO_Service_Context::get_context (IOP::ServiceContext& context) const
{
  for (CORBA::ULong i = 0; i != this->service_context_.length (); ++i)
    {
      if (context.context_id == this->service_context_[i].context_id)
        {
          context = this->service_context_[i];
          return 1;
        }
    }

  return 0;
}

int
TAO_Service_Context::get_context (IOP::ServiceId id,
                                  const IOP::ServiceContext **context) const
{
  for (CORBA::ULong i = 0; i != this->service_context_.length (); ++i)
    {
      if (id == this->service_context_[i].context_id)
        {
          *context = &this->service_context_[i];
          return 1;
        }
    }

  return 0;
}

int
TAO_Service_Context::get_context (IOP::ServiceId id,
                                  IOP::ServiceContext_out context)
{
  CORBA::ULong const len = this->service_context_.length ();

  for (CORBA::ULong i = 0; i < len; ++i)
    {
      if (id == this->service_context_[i].context_id)
        {
          ACE_NEW_RETURN (context, IOP::ServiceContext, 0);

          *(context.ptr ()) = this->service_context_[i];

          return 1;
        }
    }

  return 0;
}

int
TAO_Service_Context::encode (TAO_OutputCDR& cdr) const
{
  return (cdr << this->service_context_);
}

int
TAO_Service_Context::decode (TAO_InputCDR& cdr)
{
  if (!(cdr >> this->service_context_))
    {
      return 0;
    }

  return 1;
}

TAO_END_VERSIONED_NAMESPACE_DECL