1 #include "tao/PI/PI_includeC.h"
2 #include "tao/ORB_Constants.h"
5 #include "ace/os_include/os_stddef.h"
6 #include "ace/Log_Msg.h"
9 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
13 template <typename InterceptorType
, typename DetailsType
>
14 Interceptor_List
<InterceptorType
,DetailsType
>::Interceptor_List ()
18 template <typename InterceptorType
, typename DetailsType
>
19 typename Interceptor_List
<InterceptorType
,DetailsType
>::RegisteredInterceptor
&
20 Interceptor_List
<InterceptorType
,DetailsType
>::registered_interceptor (
23 return this->interceptors_
[index
];
26 template <typename InterceptorType
, typename DetailsType
>
27 typename Interceptor_List
<InterceptorType
,DetailsType
>::InterceptorType_ptr_type
28 Interceptor_List
<InterceptorType
,DetailsType
>::interceptor (size_t index
)
30 return this->interceptors_
[index
].interceptor_
.in ();
33 template <typename InterceptorType
, typename DetailsType
>
35 Interceptor_List
<InterceptorType
,DetailsType
>::size () const
37 return this->interceptors_
.size ();
40 template <typename InterceptorType
, typename DetailsType
>
42 Interceptor_List
<InterceptorType
,DetailsType
>::add_interceptor (
43 InterceptorType_ptr_type interceptor
)
45 if (!CORBA::is_nil (interceptor
))
47 size_t const old_len
= this->interceptors_
.size ();
49 // Don't bother checking the name for duplicates if no
50 // interceptors have been registered. This saves an
54 /// If the Interceptor is not anonymous, make sure an
55 /// Interceptor with the same isn't already registered.
56 CORBA::String_var name
= interceptor
->name ();
58 if (std::strlen (name
.in ()) != 0)
60 // @@ This simple search algorithm isn't the greatest
61 // thing in the world, but since we only register
62 // interceptors when bootstrapping an ORB, there will
63 // be no runtime penalty.
65 // Another source of inefficiency is that
66 // Interceptors duplicate their name each time the
67 // name() accessor is called! This can slow down
68 // bootstrap time noticeably when registering a huge
69 // number of interceptors. We could cache the names
70 // somewhere, but since this is only a bootstrapping
71 // issue there's no rush to implement such a scheme.
73 // Prevent interceptors with the same name from being
74 // registered. Anonymous interceptors are okay.
75 for (size_t i
= 0; i
< old_len
; ++i
)
77 CORBA::String_var existing_name
=
78 this->interceptor (i
)->name ();
80 if (ACE_OS::strcmp (existing_name
.in (), name
.in ()) == 0)
82 throw PortableInterceptor::ORBInitInfo::DuplicateName ();
88 /// Increase the length of the Interceptor sequence by one.
89 size_t const new_len
= old_len
+ 1;
90 this->interceptors_
.size (new_len
);
92 // Add the interceptor
93 this->interceptors_
[old_len
].interceptor_
=
94 InterceptorType::_duplicate (interceptor
);
100 CORBA::SystemException::_tao_minor_code (
104 CORBA::COMPLETED_NO
);
108 template <typename InterceptorType
, typename DetailsType
>
110 Interceptor_List
<InterceptorType
,DetailsType
>::add_interceptor (
111 InterceptorType_ptr_type interceptor
,
112 const CORBA::PolicyList
& policies
115 if (!CORBA::is_nil (interceptor
))
117 size_t const old_len
= this->interceptors_
.size ();
119 // Don't bother checking the name for duplicates if no
120 // interceptors have been registered. This saves an
124 /// If the Interceptor is not anonymous, make sure an
125 /// Interceptor with the same isn't already registered.
126 CORBA::String_var name
= interceptor
->name ();
128 if (std::strlen (name
.in ()) != 0)
130 // @@ This simple search algorithm isn't the greatest
131 // thing in the world, but since we only register
132 // interceptors when bootstrapping an ORB, there will
133 // be no runtime penalty.
135 // Another source of inefficiency is that
136 // Interceptors duplicate their name each time the
137 // name() accessor is called! This can slow down
138 // bootstrap time noticeably when registering a huge
139 // number of interceptors. We could cache the names
140 // somewhere, but since this is only a bootstrapping
141 // issue there's no rush to implement such a scheme.
143 // Prevent interceptors with the same name from being
144 // registered. Anonymous interceptors are okay.
145 for (size_t i
= 0; i
< old_len
; ++i
)
147 CORBA::String_var existing_name
=
148 this->interceptor (i
)->name ();
150 if (ACE_OS::strcmp (existing_name
.in (),
153 throw PortableInterceptor::ORBInitInfo::DuplicateName ();
159 // Create a DetailsType object, and attempt to apply the policies.
161 details
.apply_policies(policies
);
163 /// Increase the length of the Interceptor sequence by one.
164 size_t const new_len
= old_len
+ 1;
165 this->interceptors_
.size (new_len
);
167 // Add the interceptor
168 this->interceptors_
[old_len
].interceptor_
=
169 InterceptorType::_duplicate (interceptor
);
172 this->interceptors_
[old_len
].details_
= details
;
178 CORBA::SystemException::_tao_minor_code (
182 CORBA::COMPLETED_NO
);
186 template <typename InterceptorType
, typename DetailsType
>
188 Interceptor_List
<InterceptorType
,DetailsType
>::destroy_interceptors (
191 size_t const len
= this->interceptors_
.size ();
196 for (size_t k
= 0; k
< len
; ++k
)
198 // Destroy the interceptors in reverse order in case the
199 // array list is only partially destroyed and another
200 // invocation occurs afterwards.
203 this->interceptor (k
)->destroy ();
205 // Since Interceptor::destroy() can throw an exception,
206 // decrease the size of the interceptor array incrementally
207 // since some interceptors may not have been destroyed yet.
208 // Note that this size reduction is fast since no memory is
209 // actually deallocated.
210 this->interceptors_
.size (ilen
);
215 // Exceptions should not be propagated beyond this call.
216 if (TAO_debug_level
> 3)
218 TAOLIB_DEBUG ((LM_DEBUG
,
219 ACE_TEXT ("TAO (%P|%t) - Exception in ")
220 ACE_TEXT ("Interceptor_List")
221 ACE_TEXT ("::destroy_interceptors ()\n")));
227 TAO_END_VERSIONED_NAMESPACE_DECL