Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tao / IORInterceptor / IORInterceptor_Adapter_Impl.cpp
blobd4aa38b8341c445e8003714cdce203e84a321e7c
1 // -*- C++ -*-
2 #include "tao/IORInterceptor/IORInterceptor_Adapter_Impl.h"
3 #include "tao/IORInterceptor/IORInfo.h"
4 #include "tao/debug.h"
5 #include "tao/ORB_Constants.h"
6 #include "tao/PI/PI.h"
7 #include "tao/PortableServer/Root_POA.h"
8 #include "tao/PortableServer/Non_Servant_Upcall.h"
10 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
12 TAO_IORInterceptor_Adapter_Impl::~TAO_IORInterceptor_Adapter_Impl ()
16 void
17 TAO_IORInterceptor_Adapter_Impl::add_interceptor (
18 PortableInterceptor::IORInterceptor_ptr i)
20 this->ior_interceptor_list_.add_interceptor (i);
23 void
24 TAO_IORInterceptor_Adapter_Impl::add_interceptor (
25 PortableInterceptor::IORInterceptor_ptr i,
26 const CORBA::PolicyList& policies)
28 this->ior_interceptor_list_.add_interceptor (i, policies);
31 void
32 TAO_IORInterceptor_Adapter_Impl::destroy_interceptors ()
34 this->ior_interceptor_list_.destroy_interceptors ();
36 delete this;
39 void
40 TAO_IORInterceptor_Adapter_Impl::establish_components (TAO_Root_POA* poa)
42 size_t const interceptor_count = this->ior_interceptor_list_.size ();
44 if (interceptor_count == 0)
45 return;
47 TAO_IORInfo *tao_info = 0;
48 ACE_NEW_THROW_EX (tao_info,
49 TAO_IORInfo (poa),
50 CORBA::NO_MEMORY (
51 CORBA::SystemException::_tao_minor_code (
52 TAO::VMCID,
53 ENOMEM),
54 CORBA::COMPLETED_NO));
56 PortableInterceptor::IORInfo_var info = tao_info;
58 // Release the POA during IORInterceptor calls to avoid potential
59 // deadlocks.
60 TAO::Portable_Server::Non_Servant_Upcall non_servant_upcall (*poa);
61 ACE_UNUSED_ARG (non_servant_upcall);
63 for (size_t i = 0; i < interceptor_count; ++i)
65 try
67 this->ior_interceptor_list_.interceptor (i)->establish_components (
68 info.in ());
70 catch (const ::CORBA::Exception& ex)
72 // According to the Portable Interceptors specification,
73 // IORInterceptor::establish_components() must not throw an
74 // exception. If it does, then the ORB is supposed to
75 // ignore it and continue processing the remaining
76 // IORInterceptors.
77 if (TAO_debug_level > 1)
79 CORBA::String_var name =
80 this->ior_interceptor_list_.interceptor (i)->name ();
81 // @@ What do we do if we get an exception here?
83 if (name.in () != 0)
85 TAOLIB_DEBUG ((LM_WARNING,
86 "(%P|%t) Exception thrown while processing "
87 "IORInterceptor \"%C\">\n",
88 name.in ()));
91 ex._tao_print_exception (
92 "Ignoring exception in "
93 "IORInterceptor::establish_components");
98 tao_info->components_established ();
100 this->components_established (info.in ());
102 // The IORInfo instance is no longer valid. Invalidate it to
103 // prevent the user from peforming "illegal" operations.
104 tao_info->invalidate ();
107 void
108 TAO_IORInterceptor_Adapter_Impl::components_established (
109 PortableInterceptor::IORInfo_ptr info)
111 // Iterate over the registered IOR interceptors so that they may be
112 // given the opportunity to add tagged components to the profiles
113 // for this servant.
114 size_t const interceptor_count = this->ior_interceptor_list_.size ();
116 // All the establish_components() interception points have been
117 // invoked. Now call the components_established() interception point
118 // on all the IORInterceptors.
119 for (size_t j = 0; j < interceptor_count; ++j)
123 PortableInterceptor::IORInterceptor_ptr ior_interceptor =
124 this->ior_interceptor_list_.interceptor (j);
126 PortableInterceptor::IORInterceptor_3_0_var ior_3_interceptor =
127 PortableInterceptor::IORInterceptor_3_0::_narrow (ior_interceptor);
128 if (!CORBA::is_nil (ior_3_interceptor.in ()))
130 ior_3_interceptor->components_established (info);
133 catch (const ::CORBA::Exception&)
135 throw ::CORBA::OBJ_ADAPTER (CORBA::OMGVMCID | 6,
136 CORBA::COMPLETED_NO);
141 void
142 TAO_IORInterceptor_Adapter_Impl::adapter_state_changed (
143 const TAO::ObjectReferenceTemplate_Array &array_obj_ref_template,
144 PortableInterceptor::AdapterState state)
146 size_t const interceptor_count = this->ior_interceptor_list_.size ();
148 if (interceptor_count == 0)
149 return;
151 PortableInterceptor::ObjectReferenceTemplateSeq seq_obj_ref_template;
153 seq_obj_ref_template.length (
154 static_cast <CORBA::ULong> (array_obj_ref_template.size()));
156 for (size_t counter = 0; counter < array_obj_ref_template.size(); ++counter)
158 PortableInterceptor::ObjectReferenceTemplate *member =
159 array_obj_ref_template[counter];
161 CORBA::add_ref (member);
163 seq_obj_ref_template[static_cast<CORBA::ULong> (counter)] = member;
166 for (size_t i = 0; i < interceptor_count; ++i)
168 PortableInterceptor::IORInterceptor_ptr ior_interceptor =
169 this->ior_interceptor_list_.interceptor (i);
171 PortableInterceptor::IORInterceptor_3_0_var ior_3_interceptor =
172 PortableInterceptor::IORInterceptor_3_0::_narrow (ior_interceptor);
173 if (!CORBA::is_nil (ior_3_interceptor.in ()))
175 ior_3_interceptor->adapter_state_changed (seq_obj_ref_template, state);
180 void
181 TAO_IORInterceptor_Adapter_Impl::adapter_manager_state_changed (
182 const char * id,
183 PortableInterceptor::AdapterState state)
185 /// Whenever the POAManager state is changed, the
186 /// adapter_manager_state_changed method is to be invoked on all the IOR
187 /// Interceptors.
188 size_t const interceptor_count = this->ior_interceptor_list_.size ();
190 if (interceptor_count == 0)
191 return;
193 for (size_t i = 0; i < interceptor_count; ++i)
195 PortableInterceptor::IORInterceptor_ptr ior_interceptor =
196 this->ior_interceptor_list_.interceptor (i);
198 PortableInterceptor::IORInterceptor_3_0_var ior_3_interceptor =
199 PortableInterceptor::IORInterceptor_3_0::_narrow (ior_interceptor);
200 if (!CORBA::is_nil (ior_3_interceptor.in ()))
202 ior_3_interceptor->adapter_manager_state_changed (id, state);
207 TAO_END_VERSIONED_NAMESPACE_DECL