Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tao / PI / Interceptor_List_T.cpp
blob929797f21c14669e78d88e68e1201c9a7d3f1040
1 #include "tao/PI/PI_includeC.h"
2 #include "tao/ORB_Constants.h"
3 #include "tao/debug.h"
5 #include "ace/os_include/os_stddef.h"
6 #include "ace/Log_Msg.h"
7 #include <cstring>
9 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
11 namespace TAO
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 (
21 size_t index)
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>
34 size_t
35 Interceptor_List<InterceptorType,DetailsType>::size () const
37 return this->interceptors_.size ();
40 template <typename InterceptorType, typename DetailsType>
41 void
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
51 // allocation.
52 if (old_len > 0)
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);
96 else
98 throw
99 CORBA::INV_OBJREF (
100 CORBA::SystemException::_tao_minor_code (
102 EINVAL
104 CORBA::COMPLETED_NO);
108 template <typename InterceptorType, typename DetailsType>
109 void
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
121 // allocation.
122 if (old_len > 0)
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 (),
151 name.in ()) == 0)
153 throw PortableInterceptor::ORBInitInfo::DuplicateName ();
159 // Create a DetailsType object, and attempt to apply the policies.
160 DetailsType details;
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);
171 // Set the details
172 this->interceptors_[old_len].details_ = details;
174 else
176 throw
177 CORBA::INV_OBJREF (
178 CORBA::SystemException::_tao_minor_code (
180 EINVAL
182 CORBA::COMPLETED_NO);
186 template <typename InterceptorType, typename DetailsType>
187 void
188 Interceptor_List<InterceptorType,DetailsType>::destroy_interceptors (
189 void)
191 size_t const len = this->interceptors_.size ();
192 size_t ilen = len;
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.
201 --ilen;
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);
213 catch (...)
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