2 #include "ace/Barrier.h"
3 #include "ace/Arg_Shifter.h"
4 #include "ace/Argv_Type_Converter.h"
5 #include "ace/OS_NS_unistd.h"
6 #include "tao/TAO_Singleton_Manager.h"
10 : failPrePostInit_ (3),
23 DllORB::init (int argc
, ACE_TCHAR
*argv
[])
29 ACE_Arg_Shifter
as (argc
, argv
);
30 const ACE_TCHAR
*currentArg
= 0;
31 while (as
.is_anything_left ())
33 if ((currentArg
= as
.get_the_parameter (ACE_TEXT ("-NumThreads"))))
35 int num
= ACE_OS::atoi (currentArg
);
44 if (failPrePostInit_
< 3)
47 ACE_TEXT ("Pre-ORB initialization ...\n")));
48 // -----------------------------------------------------------------
49 // Pre-ORB initialization steps necessary for proper DLL ORB
51 // -----------------------------------------------------------------
52 // Make sure TAO's singleton manager is initialized, and set to not
53 // register itself with the ACE_Object_Manager since it is under the
54 // control of the Service Configurator. If we register with the
55 // ACE_Object_Manager, then the ACE_Object_Manager will still hold
56 // (dangling) references to instances of objects created by this
57 // module and destroyed by this object when it is dynamically
59 int register_with_object_manager
= 0;
60 TAO_Singleton_Manager
* p_tsm
= TAO_Singleton_Manager::instance ();
61 int result
= p_tsm
->init (register_with_object_manager
);
65 if (failPrePostInit_
== 0)
68 ACE_TEXT ("Pre-ORB initialization failed.\n")));
71 else if (failPrePostInit_
< 2)
73 ACE_DEBUG ((LM_WARNING
,
74 ACE_TEXT ("Pre-ORB initialization failed (ignored due to FailPrePostInit setting).\n")));
79 ACE_TEXT ("Pre-ORB initialization failed (ignored due to FailPrePostInit setting).\n")));
85 ACE_TEXT ("Pre-ORB initialization done.\n")));
90 mv_orb_
= CORBA::ORB_init (argc
, argv
);
91 if (CORBA::is_nil (mv_orb_
.in ()))
93 ACE_DEBUG ((LM_ERROR
, ACE_TEXT ("nil ORB\n")));
97 CORBA::Object_var v_poa
=
98 mv_orb_
->resolve_initial_references ("RootPOA");
100 mv_rootPOA_
= PortableServer::POA::_narrow (v_poa
.in ());
101 if (CORBA::is_nil (mv_rootPOA_
.in ()))
103 ACE_DEBUG ((LM_ERROR
, ACE_TEXT ("nil RootPOA\n")));
107 mv_poaManager_
= mv_rootPOA_
->the_POAManager ();
108 if (CORBA::is_nil (mv_poaManager_
.in ()))
110 ACE_DEBUG ((LM_ERROR
, ACE_TEXT ("nil POAManager\n")));
114 mv_poaManager_
->activate ();
118 ACE_DEBUG ((LM_ERROR
, ACE_TEXT ("ERROR: exception\n")));
122 mp_barrier_
= new ACE_Thread_Barrier (threadCnt
+ 1);
124 this->activate (THR_NEW_LWP
|THR_JOINABLE
|THR_INHERIT_SCHED
, threadCnt
);
125 mp_barrier_
->wait ();
136 mv_poaManager_
->deactivate (1, 1);
137 mv_poaManager_
= PortableServer::POAManager::_nil ();
139 // attempt to protect against sporadic BAD_INV_ORDER exceptions
140 ACE_OS::sleep (ACE_Time_Value (0, 500));
142 mv_orb_
->shutdown (1);
146 ACE_DEBUG ((LM_ERROR
, ACE_TEXT ("ERROR: exception\n")));
150 // wait for our threads to finish
159 mv_orb_
= CORBA::ORB::_nil ();
161 catch (const CORBA::Exception
& ex
)
163 ex
._tao_print_exception ("Exception caught:");
167 if (failPrePostInit_
< 3)
169 // -----------------------------------------------------------------
170 // Post-ORB finalization steps necessary for proper DLL ORB
172 // -----------------------------------------------------------------
173 // Explicitly clean up singletons created by TAO before
174 // unloading this module.
175 TAO_Singleton_Manager
* p_tsm
= TAO_Singleton_Manager::instance ();
176 int result
= p_tsm
->fini ();
179 if (failPrePostInit_
== 0)
181 ACE_DEBUG ((LM_ERROR
,
182 ACE_TEXT ("Post-ORB finalization failed.\n")));
185 else if (failPrePostInit_
< 2)
187 ACE_DEBUG ((LM_WARNING
,
188 ACE_TEXT ("Post-ORB finalization failed (ignored due to FailPrePostInit setting).\n")));
193 ACE_TEXT ("Post-ORB finalization failed (ignored due to FailPrePostInit setting).\n")));
199 ACE_TEXT ("Post-ORB finalization done.\n")));
209 mp_barrier_
->wait ();
219 ACE_DEBUG ((LM_ERROR
, ACE_TEXT ("ERROR: exception\n")));
227 ACE_FACTORY_DEFINE (bug3663
, DllORB
)