1 #include "tao/PI/ORBInitializer_Registry_Impl.h"
2 #include "tao/PI/ORBInitInfo.h"
3 #include "tao/PI/PICurrent.h"
4 #include "tao/PI/PI_ORBInitializer.h"
5 #include "tao/PI/ClientRequestInterceptor_Factory_Impl.h"
6 #include "tao/PI/PICurrent_Loader.h"
7 #include "tao/PI/PolicyFactory_Loader.h"
9 #include "tao/ORB_Core.h"
10 #include "tao/ORB_Constants.h"
12 #include "ace/Static_Object_Lock.h"
13 #include "ace/Recursive_Thread_Mutex.h"
14 #include "ace/Log_Msg.h"
15 #include "ace/CORBA_macros.h"
17 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
19 TAO::ORBInitializer_Registry::ORBInitializer_Registry ()
26 TAO::ORBInitializer_Registry::init (int, ACE_TCHAR
*[])
28 #if !defined (TAO_AS_STATIC_LIBS) && (TAO_HAS_INTERCEPTORS == 1)
29 ACE_Service_Config::process_directive
30 (ace_svc_desc_TAO_ClientRequestInterceptor_Adapter_Factory_Impl
);
32 ACE_Service_Config::process_directive
33 (ace_svc_desc_TAO_PICurrent_Loader
);
35 PortableInterceptor::ORBInitializer_ptr temp_orb_initializer
=
36 PortableInterceptor::ORBInitializer::_nil ();
38 PortableInterceptor::ORBInitializer_var orb_initializer
;
42 /// Register the PI ORBInitializer.
44 ACE_NEW_THROW_EX (temp_orb_initializer
,
45 TAO_PI_ORBInitializer
,
47 CORBA::SystemException::_tao_minor_code (
50 CORBA::COMPLETED_NO
));
52 orb_initializer
= temp_orb_initializer
;
54 this->register_orb_initializer (orb_initializer
.in ());
56 catch (const ::CORBA::Exception
& ex
)
58 if (TAO_debug_level
> 0)
60 ex
._tao_print_exception ("(%P|%t) Caught exception:");
64 #endif /* !TAO_AS_STATIC_LIBS && TAO_HAS_INTERCEPTORS == 1 */
69 TAO::ORBInitializer_Registry::fini ()
71 ACE_GUARD_RETURN (TAO_SYNCH_RECURSIVE_MUTEX
,
76 // Release all initializers in the array
77 size_t const initializer_count (this->initializers_
.size ());
78 for (size_t i
= initializer_count
; i
> 0;)
81 if (TAO_debug_level
> 8)
83 TAOLIB_DEBUG((LM_DEBUG
, ACE_TEXT("TAO (%P|%t) - ORBInitializer_Registry::fini clearing %d @%@\n"),
84 i
, this->initializers_
[i
].operator->()
87 this->initializers_
[i
] = PortableInterceptor::ORBInitializer::_nil();
94 TAO::ORBInitializer_Registry::register_orb_initializer (
95 PortableInterceptor::ORBInitializer_ptr init
)
97 if (!CORBA::is_nil (init
))
99 ACE_GUARD (TAO_SYNCH_RECURSIVE_MUTEX
,
103 // Increase the length of the ORBInitializer array by one.
104 size_t const cur_len
= this->initializers_
.size ();
105 size_t const new_len
= cur_len
+ 1;
106 if (this->initializers_
.size (new_len
) != 0)
107 throw ::CORBA::INTERNAL ();
109 // Add the given ORBInitializer to the sequence.
110 if (TAO_debug_level
> 8)
112 TAOLIB_DEBUG((LM_DEBUG
, ACE_TEXT("TAO (%P|%t) - ORBInitializer_Registry::register_orb_initializer %d @%@\n"),
117 this->initializers_
[cur_len
] =
118 PortableInterceptor::ORBInitializer::_duplicate (init
);
121 throw ::CORBA::INV_OBJREF (
122 CORBA::SystemException::_tao_minor_code (
125 CORBA::COMPLETED_NO
);
129 TAO::ORBInitializer_Registry::pre_init (
130 TAO_ORB_Core
*orb_core
,
133 PortableInterceptor::SlotId
&slotid
)
135 ACE_GUARD_RETURN (TAO_SYNCH_RECURSIVE_MUTEX
,
140 size_t const initializer_count (this->initializers_
.size ());
142 if (initializer_count
> 0)
144 TAO_ORBInitInfo
* orb_init_info_temp
= 0;
146 ACE_NEW_THROW_EX (orb_init_info_temp
,
147 TAO_ORBInitInfo (orb_core
,
152 CORBA::SystemException::_tao_minor_code (
155 CORBA::COMPLETED_NO
));
157 TAO_ORBInitInfo_var orb_init_info_
= orb_init_info_temp
;
159 for (size_t i
= 0; i
< initializer_count
; ++i
)
161 this->initializers_
[i
]->pre_init (orb_init_info_
.in ());
164 slotid
= orb_init_info_temp
->slot_count ();
166 // Invalidate the ORBInitInfo instance to prevent future
167 // modifications to the ORB. This behavior complies with the
168 // PortableInterceptor specification.
169 orb_init_info_temp
->invalidate ();
172 return initializer_count
;
176 TAO::ORBInitializer_Registry::post_init (
177 size_t pre_init_count
,
178 TAO_ORB_Core
*orb_core
,
181 PortableInterceptor::SlotId slotid
)
183 if (pre_init_count
> 0)
185 ACE_GUARD (TAO_SYNCH_RECURSIVE_MUTEX
,
189 TAO_ORBInitInfo
* orb_init_info_temp
= 0;
191 ACE_NEW_THROW_EX (orb_init_info_temp
,
192 TAO_ORBInitInfo (orb_core
,
197 CORBA::SystemException::_tao_minor_code (
200 CORBA::COMPLETED_NO
));
202 TAO_ORBInitInfo_var orb_init_info_
= orb_init_info_temp
;
204 for (size_t i
= 0; i
< pre_init_count
; ++i
)
206 this->initializers_
[i
]->post_init (orb_init_info_
.in ());
209 #if TAO_HAS_INTERCEPTORS == 1
210 CORBA::Object_ptr picurrent_ptr
= orb_core
->pi_current ();
211 PortableInterceptor::SlotId slot_count
= orb_init_info_
->slot_count ();
213 if (CORBA::is_nil (picurrent_ptr
) && slot_count
!= 0)
215 // Force instantiation of the PICurrent object. If we do not do it
216 // now, the slot count will be lost.
217 CORBA::Object_var tmp
= orb_core
->resolve_picurrent ();
218 picurrent_ptr
= orb_core
->pi_current ();
221 if (!CORBA::is_nil (picurrent_ptr
))
223 TAO::PICurrent
*pi
= dynamic_cast <TAO::PICurrent
*> (picurrent_ptr
);
227 pi
->initialize (slot_count
);
230 #endif /* TAO_HAS_INTERCEPTORS == 1 */
232 // Invalidate the ORBInitInfo instance to prevent future
233 // modifications to the ORB. This behavior complies with the
234 // PortableInterceptor specification.
235 orb_init_info_temp
->invalidate ();
239 ACE_STATIC_SVC_DEFINE (ORBInitializer_Registry
,
240 ACE_TEXT ("ORBInitializer_Registry"),
242 &ACE_SVC_NAME (ORBInitializer_Registry
),
243 ACE_Service_Type::DELETE_THIS
| ACE_Service_Type::DELETE_OBJ
,
246 ACE_FACTORY_NAMESPACE_DEFINE (TAO_PI
, ORBInitializer_Registry
, TAO::ORBInitializer_Registry
)
248 TAO_END_VERSIONED_NAMESPACE_DECL