2 * @author Iliyan jeliazkov <iliyan@ociweb.com>
3 * @author Lothar Werzinger <lothar@tradescape.biz>
6 #include "ace/Arg_Shifter.h"
7 #include "ace/SString.h"
8 #include "ace/OS_NS_unistd.h"
10 #include "tao/corba.h"
11 #include "tao/TAO_Singleton_Manager.h"
15 DllOrb::DllOrb (int nthreads
)
17 m_nthreads_ (nthreads
),
19 #if defined (ACE_HAS_THREADS)
27 DllOrb::~DllOrb () noexcept
29 #if defined (ACE_HAS_THREADS)
34 int DllOrb::init (int argc
, ACE_TCHAR
*argv
[])
37 int threadCnt
= this->m_nthreads_
;
41 ACE_Arg_Shifter
as (argc
, argv
);
42 const ACE_TCHAR
*currentArg
= 0;
43 while (as
.is_anything_left ())
45 if (0 != (currentArg
= as
.get_the_parameter (ACE_TEXT ("-t"))))
47 int num
= ACE_OS::atoi (currentArg
);
56 if (m_failPrePostInit
< 3)
58 ACE_DEBUG((LM_DEBUG
, "TEST (%P|%t) Pre-ORB initialization ...\n"));
60 // -----------------------------------------------------------------
61 // Pre-ORB initialization steps necessary for proper DLL ORB
63 // -----------------------------------------------------------------
64 // Make sure TAO's singleton manager is initialized, and set to not
65 // register itself with the ACE_Object_Manager since it is under the
66 // control of the Service Configurator. If we register with the
67 // ACE_Object_Manager, then the ACE_Object_Manager will still hold
68 // (dangling) references to instances of objects created by this
69 // module and destroyed by this object when it is dynamically
71 int register_with_object_manager
= 0;
72 TAO_Singleton_Manager
* p_tsm
= TAO_Singleton_Manager::instance ();
73 result
= p_tsm
->init (register_with_object_manager
);
75 if (result
== -1 && m_failPrePostInit
== 0)
80 mv_orb
= CORBA::ORB_init (argc
, argv
);
81 if (CORBA::is_nil (mv_orb
.in ()))
84 CORBA::Object_var v_poa
= mv_orb
->resolve_initial_references ("RootPOA");
86 mv_rootPOA
= PortableServer::POA::_narrow (v_poa
.in ());
87 if (CORBA::is_nil (mv_rootPOA
.in ()))
90 mv_poaManager
= mv_rootPOA
->the_POAManager ();
91 if (CORBA::is_nil (mv_poaManager
.in ()))
94 mv_poaManager
->activate ();
96 catch(CORBA::Exception
& ex
)
98 ex
._tao_print_exception (ACE_TEXT ("(%P|%t) init failed:"));
103 ACE_ERROR_RETURN ((LM_ERROR
,
104 ACE_TEXT ("(%P|%t) init failed\n")),
108 #if defined (ACE_HAS_THREADS)
109 mp_barrier
= new ACE_Thread_Barrier (threadCnt
+ 1);
112 THR_NEW_LWP
|THR_JOINABLE
|THR_INHERIT_SCHED
,
126 #if !defined (CORBA_E_COMPACT) && !defined (CORBA_E_MICRO) && !defined (TAO_HAS_MINIMUM_POA)
127 mv_poaManager
->deactivate(1, 1);
129 mv_poaManager
= PortableServer::POAManager::_nil();
131 // attempt to protect against sporadic BAD_INV_ORDER exceptions
132 ACE_OS::sleep(ACE_Time_Value(0, 500));
134 mv_orb
->shutdown(true);
136 catch(CORBA::Exception
& ex
)
138 ex
._tao_print_exception (ACE_TEXT ("(%P|%t) fini failed:"));
143 ACE_ERROR_RETURN ((LM_ERROR
,
144 ACE_TEXT ("(%P|%t) fini failed to deactivate/shutdown\n")),
149 // wait for our threads to finish
152 #if defined (ACE_HAS_THREADS)
160 mv_orb
= CORBA::ORB::_nil();
162 catch(CORBA::Exception
& ex
)
164 ex
._tao_print_exception (
166 "(%P|%t) init failed to destroy the orb:"));
170 if (m_failPrePostInit
< 3)
172 ACE_DEBUG((LM_DEBUG
, "TEST (%P|%t) Post-ORB finalization ...\n"));
174 // -----------------------------------------------------------------
175 // Post-ORB finalization steps necessary for proper DLL ORB
177 // -----------------------------------------------------------------
178 // Explicitly clean up singletons created by TAO before
179 // unloading this module.
180 TAO_Singleton_Manager
* p_tsm
= TAO_Singleton_Manager::instance();
181 result
= p_tsm
->fini();
182 if (result
== -1 && m_failPrePostInit
== 0)
183 ACE_ERROR_RETURN ((LM_ERROR
,
184 ACE_TEXT ("(%P|%t) fini failed to destroy TAO_Singleton_Manager\n")),
193 #if defined (ACE_HAS_THREADS)
201 catch(CORBA::BAD_INV_ORDER
const & rc_ex
)
203 const CORBA::ULong VMCID
= rc_ex
.minor() & 0xFFFFF000U
;
204 const CORBA::ULong minorCode
= rc_ex
.minor() & 0xFFFU
;
205 if (VMCID
!= CORBA::OMGVMCID
|| minorCode
!= 4)
206 ACE_ERROR_RETURN ((LM_ERROR
,
207 ACE_TEXT ("(%P|%t) svc exits (-1)\n")),
210 catch(CORBA::Exception
& ex
)
212 ex
._tao_print_exception (ACE_TEXT ("(%P|%t) svc - orb->run() failed:"));
217 ACE_ERROR_RETURN ((LM_ERROR
,
218 ACE_TEXT ("(%P|%t) svc got some exception\n")),
224 ACE_FACTORY_DEFINE (DllOrb
, DllOrb
)