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)
30 #if defined (ACE_HAS_THREADS)
35 int DllOrb::init (int argc
, ACE_TCHAR
*argv
[])
38 int threadCnt
= this->m_nthreads_
;
42 ACE_Arg_Shifter
as (argc
, argv
);
43 const ACE_TCHAR
*currentArg
= 0;
44 while (as
.is_anything_left ())
46 if (0 != (currentArg
= as
.get_the_parameter (ACE_TEXT ("-t"))))
48 int num
= ACE_OS::atoi (currentArg
);
57 if (m_failPrePostInit
< 3)
59 ACE_DEBUG((LM_DEBUG
, "TEST (%P|%t) Pre-ORB initialization ...\n"));
61 // -----------------------------------------------------------------
62 // Pre-ORB initialization steps necessary for proper DLL ORB
64 // -----------------------------------------------------------------
65 // Make sure TAO's singleton manager is initialized, and set to not
66 // register itself with the ACE_Object_Manager since it is under the
67 // control of the Service Configurator. If we register with the
68 // ACE_Object_Manager, then the ACE_Object_Manager will still hold
69 // (dangling) references to instances of objects created by this
70 // module and destroyed by this object when it is dynamically
72 int register_with_object_manager
= 0;
73 TAO_Singleton_Manager
* p_tsm
= TAO_Singleton_Manager::instance ();
74 result
= p_tsm
->init (register_with_object_manager
);
76 if (result
== -1 && m_failPrePostInit
== 0)
81 mv_orb
= CORBA::ORB_init (argc
, argv
);
82 if (CORBA::is_nil (mv_orb
.in ()))
85 CORBA::Object_var v_poa
= mv_orb
->resolve_initial_references ("RootPOA");
87 mv_rootPOA
= PortableServer::POA::_narrow (v_poa
.in ());
88 if (CORBA::is_nil (mv_rootPOA
.in ()))
91 mv_poaManager
= mv_rootPOA
->the_POAManager ();
92 if (CORBA::is_nil (mv_poaManager
.in ()))
95 mv_poaManager
->activate ();
97 catch(CORBA::Exception
& ex
)
99 ex
._tao_print_exception (ACE_TEXT ("(%P|%t) init failed:"));
104 ACE_ERROR_RETURN ((LM_ERROR
,
105 ACE_TEXT ("(%P|%t) init failed\n")),
109 #if defined (ACE_HAS_THREADS)
110 mp_barrier
= new ACE_Thread_Barrier (threadCnt
+ 1);
113 THR_NEW_LWP
|THR_JOINABLE
|THR_INHERIT_SCHED
,
122 int DllOrb::fini (void)
128 #if !defined (CORBA_E_COMPACT) && !defined (CORBA_E_MICRO) && !defined (TAO_HAS_MINIMUM_POA)
129 mv_poaManager
->deactivate(1, 1);
131 mv_poaManager
= PortableServer::POAManager::_nil();
133 // attempt to protect against sporadic BAD_INV_ORDER exceptions
134 ACE_OS::sleep(ACE_Time_Value(0, 500));
138 catch(CORBA::Exception
& ex
)
140 ex
._tao_print_exception (ACE_TEXT ("(%P|%t) fini failed:"));
145 ACE_ERROR_RETURN ((LM_ERROR
,
146 ACE_TEXT ("(%P|%t) fini failed to deactivate/shutdown\n")),
151 // wait for our threads to finish
154 #if defined (ACE_HAS_THREADS)
162 mv_orb
= CORBA::ORB::_nil();
164 catch(CORBA::Exception
& ex
)
166 ex
._tao_print_exception (
168 "(%P|%t) init failed to destroy the orb:"));
172 if (m_failPrePostInit
< 3)
174 ACE_DEBUG((LM_DEBUG
, "TEST (%P|%t) Post-ORB finalization ...\n"));
176 // -----------------------------------------------------------------
177 // Post-ORB finalization steps necessary for proper DLL ORB
179 // -----------------------------------------------------------------
180 // Explicitly clean up singletons created by TAO before
181 // unloading this module.
182 TAO_Singleton_Manager
* p_tsm
= TAO_Singleton_Manager::instance();
183 result
= p_tsm
->fini();
184 if (result
== -1 && m_failPrePostInit
== 0)
185 ACE_ERROR_RETURN ((LM_ERROR
,
186 ACE_TEXT ("(%P|%t) fini failed to destroy TAO_Singleton_Manager\n")),
193 int DllOrb::svc (void)
195 #if defined (ACE_HAS_THREADS)
203 catch(CORBA::BAD_INV_ORDER
const & rc_ex
)
205 const CORBA::ULong VMCID
= rc_ex
.minor() & 0xFFFFF000U
;
206 const CORBA::ULong minorCode
= rc_ex
.minor() & 0xFFFU
;
207 if (VMCID
!= CORBA::OMGVMCID
|| minorCode
!= 4)
208 ACE_ERROR_RETURN ((LM_ERROR
,
209 ACE_TEXT ("(%P|%t) svc exits (-1)\n")),
212 catch(CORBA::Exception
& ex
)
214 ex
._tao_print_exception (ACE_TEXT ("(%P|%t) svc - orb->run() failed:"));
219 ACE_ERROR_RETURN ((LM_ERROR
,
220 ACE_TEXT ("(%P|%t) svc got some exception\n")),
226 ACE_FACTORY_DEFINE (DllOrb
, DllOrb
)