summaryrefslogtreecommitdiff
path: root/TAO/tao/Service_Context.cpp
blob: bd4fe1fc218d72db8e6ab839c3a7ef51de1946f5 (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
#include "tao/Service_Context.h"


ACE_RCSID(tao, Service_Context, "$Id$")

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


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...
  CORBA::ULong length = cdr.total_length ();
  context.context_data.length (length);
  CORBA::Octet *buf = context.context_data.get_buffer ();

  for (const ACE_Message_Block *i = cdr.begin ();
       i != 0;
       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...
  CORBA::ULong length = cdr.total_length ();
  context.context_data.length (length);
  CORBA::Octet *buf = context.context_data.get_buffer ();

  for (const ACE_Message_Block *i = cdr.begin ();
       i != 0;
       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);
}

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

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 appropiate 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 max = context.context_data.maximum ();
          CORBA::ULong len = context.context_data.length ();
          CORBA::Octet* 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 appropiate action.
  CORBA::ULong l = this->service_context_.length ();
  this->service_context_.length (l + 1);
  this->service_context_[l].context_id = context.context_id;
  CORBA::ULong max = context.context_data.maximum ();
  CORBA::ULong len = context.context_data.length ();
  CORBA::Octet* 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 appropiate action.
  CORBA::ULong 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::encode (TAO_OutputCDR& cdr) const
{
  return (cdr << this->service_context_);
}

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

  return 1;
}