summaryrefslogtreecommitdiff
path: root/TAO/tao/Interceptor_List.cpp
blob: fa010b8745044715525ac688b553875dbcfacf97 (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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
// -*- C++ -*-
//
// $Id$

#include "tao/Interceptor_List.h"

#include "tao/CORBA_String.h"

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

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

// ****************************************************************

TAO_Interceptor_List::TAO_Interceptor_List (void)
{
}

TAO_Interceptor_List::~TAO_Interceptor_List (void)
{
}

size_t
TAO_Interceptor_List::add_interceptor_i (
    PortableInterceptor::Interceptor_ptr interceptor,
    CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   PortableInterceptor::ORBInitInfo::DuplicateName))
{
  if (!CORBA::is_nil (interceptor))
    {
      /// If the Interceptor is not anonymous, make sure an
      /// Interceptor with the same isn't already registered.
      CORBA::String_var name = interceptor->name (
        TAO_ENV_SINGLE_ARG_PARAMETER);
      ACE_CHECK_RETURN (0);

      size_t old_len = this->length ();

      if (ACE_OS_String::strlen (name.in ()) != 0)
        {
          // @@ This simple search algorithm isn't the greatest thing
          //    in the world, but since we only register interceptors
          //    when bootstrapping an ORB, there will be no run-time
          //    penalty.
          //
          //    Another source of inefficiency is that Interceptors
          //    duplicate their name each time the name() accessor is
          //    called!  This can slow down bootstrap time noticeably
          //    when registering a huge number of interceptors.  We
          //    could cache the names somewhere, but since this is
          //    only a bootstrapping issue there's no rush to
          //    implement such a scheme.

          /// Prevent interceptors with the same name from being
          /// registered.  Anonymous interceptors are okay.
          for (size_t i = 0; i < old_len; ++i)
            {
              CORBA::String_var existing_name =
                this->interceptor (i)->name ();
              if (ACE_OS_String::strcmp (existing_name.in (),
                                         name.in ()) == 0)
                ACE_THROW_RETURN
                  (PortableInterceptor::ORBInitInfo::DuplicateName (),
                   0);
            }
        }

      /// Increase the length of the Interceptor sequence by one.
      size_t new_len = old_len + 1;
      this->length (new_len);
	  return old_len;
    }
  else
    ACE_THROW_RETURN (CORBA::INV_OBJREF (
                        CORBA_SystemException::_tao_minor_code (
                          TAO_DEFAULT_MINOR_CODE,
                          EINVAL),
                        CORBA::COMPLETED_NO),
                      0);
}


// -------------------------------------------------------------------

#if TAO_HAS_INTERCEPTORS == 1

TAO_ClientRequestInterceptor_List::TAO_ClientRequestInterceptor_List (void)
  : interceptors_ ()
{
}

TAO_ClientRequestInterceptor_List::~TAO_ClientRequestInterceptor_List (void)
{
  size_t len = this->interceptors_.size ();

  for (size_t i = 0; i < len; ++i)
    CORBA::release (this->interceptors_[i]);
}

size_t
TAO_ClientRequestInterceptor_List::length (void)
{
  return this->interceptors_.size ();
}

void
TAO_ClientRequestInterceptor_List::length (size_t len)
{
  this->interceptors_.size (len);
}


PortableInterceptor::Interceptor_ptr
TAO_ClientRequestInterceptor_List::interceptor (size_t index)
{
  return this->interceptors_[index];
}

void
TAO_ClientRequestInterceptor_List::add_interceptor (
  PortableInterceptor::ClientRequestInterceptor_ptr interceptor,
  CORBA::Environment &ACE_TRY_ENV)
{
  size_t index = this->add_interceptor_i (interceptor,
                                          ACE_TRY_ENV);
  ACE_CHECK;

  // @@ Should we duplicate the reference here?
  this->interceptors_[index] =
    PortableInterceptor::ClientRequestInterceptor::_duplicate (interceptor);
}

// -------------------------------------------------------------------

TAO_ServerRequestInterceptor_List::TAO_ServerRequestInterceptor_List (void)
  : interceptors_ ()
{
}

TAO_ServerRequestInterceptor_List::~TAO_ServerRequestInterceptor_List (void)
{
  size_t len = this->interceptors_.size ();

  for (size_t i = 0; i < len; ++i)
    CORBA::release (this->interceptors_[i]);
}

size_t
TAO_ServerRequestInterceptor_List::length (void)
{
  return this->interceptors_.size ();
}

void
TAO_ServerRequestInterceptor_List::length (size_t len)
{
  this->interceptors_.size (len);
}

PortableInterceptor::Interceptor_ptr
TAO_ServerRequestInterceptor_List::interceptor (size_t index)
{
  return this->interceptors_[index];
}

void
TAO_ServerRequestInterceptor_List::add_interceptor (
  PortableInterceptor::ServerRequestInterceptor_ptr interceptor,
  CORBA::Environment &ACE_TRY_ENV)
{
  size_t index = this->add_interceptor_i (interceptor,
                                          ACE_TRY_ENV);
  ACE_CHECK;

  // @@ Should we duplicate the reference here?
  this->interceptors_[index] =
    PortableInterceptor::ServerRequestInterceptor::_duplicate (interceptor);
}

#endif  /* TAO_HAS_INTERCEPTORS == 1 */

// -------------------------------------------------------------------

TAO_IORInterceptor_List::TAO_IORInterceptor_List (void)
  : interceptors_ ()
{
}

TAO_IORInterceptor_List::~TAO_IORInterceptor_List (void)
{
  size_t len = this->interceptors_.size ();

  for (size_t i = 0; i < len; ++i)
    CORBA::release (this->interceptors_[i]);
}

size_t
TAO_IORInterceptor_List::length (void)
{
  return this->interceptors_.size ();
}

void
TAO_IORInterceptor_List::length (size_t len)
{
  this->interceptors_.size (len);
}

PortableInterceptor::Interceptor_ptr
TAO_IORInterceptor_List::interceptor (size_t index)
{
  return this->interceptors_[index];
}

void
TAO_IORInterceptor_List::add_interceptor (
  PortableInterceptor::IORInterceptor_ptr interceptor,
  CORBA::Environment &ACE_TRY_ENV)
{
  size_t index = this->add_interceptor_i (interceptor,
                                          ACE_TRY_ENV);
  ACE_CHECK;

  // @@ Should we duplicate the reference here?
  this->interceptors_[index] =
    PortableInterceptor::IORInterceptor::_duplicate (interceptor);
}


#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)

# if TAO_HAS_INTERCEPTORS == 1

template class ACE_Array_Base<PortableInterceptor::ClientRequestInterceptor_ptr>;
template class ACE_Array_Base<PortableInterceptor::ServerRequestInterceptor_ptr>;

# endif  /* TAO_HAS_INTERCEPTORS == 1 */

template class ACE_Array_Base<PortableInterceptor::IORInterceptor_ptr>;

#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)

# if TAO_HAS_INTERCEPTORS == 1

#pragma instantiate ACE_Array_Base<PortableInterceptor::ClientRequestInterceptor_ptr>
#pragma instantiate ACE_Array_Base<PortableInterceptor::ServerRequestInterceptor_ptr>

# endif  /* TAO_HAS_INTERCEPTORS == 1 */

#pragma instantiate ACE_Array_Base<PortableInterceptor::IORInterceptor_ptr>

#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */