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),
25 DllORB::init (int argc
, ACE_TCHAR
*argv
[])
31 ACE_Arg_Shifter
as (argc
, argv
);
32 const ACE_TCHAR
*currentArg
= 0;
33 while (as
.is_anything_left ())
35 if ((currentArg
= as
.get_the_parameter (ACE_TEXT ("-NumThreads"))))
37 int num
= ACE_OS::atoi (currentArg
);
46 if (failPrePostInit_
< 3)
49 ACE_TEXT ("Pre-ORB initialization ...\n")));
50 // -----------------------------------------------------------------
51 // Pre-ORB initialization steps necessary for proper DLL ORB
53 // -----------------------------------------------------------------
54 // Make sure TAO's singleton manager is initialized, and set to not
55 // register itself with the ACE_Object_Manager since it is under the
56 // control of the Service Configurator. If we register with the
57 // ACE_Object_Manager, then the ACE_Object_Manager will still hold
58 // (dangling) references to instances of objects created by this
59 // module and destroyed by this object when it is dynamically
61 int register_with_object_manager
= 0;
62 TAO_Singleton_Manager
* p_tsm
= TAO_Singleton_Manager::instance ();
63 int result
= p_tsm
->init (register_with_object_manager
);
67 if (failPrePostInit_
== 0)
70 ACE_TEXT ("Pre-ORB initialization failed.\n")));
73 else if (failPrePostInit_
< 2)
75 ACE_DEBUG ((LM_WARNING
,
76 ACE_TEXT ("Pre-ORB initialization failed (ignored due to FailPrePostInit setting).\n")));
81 ACE_TEXT ("Pre-ORB initialization failed (ignored due to FailPrePostInit setting).\n")));
87 ACE_TEXT ("Pre-ORB initialization done.\n")));
92 ACE_Argv_Type_Converter
argcon (argc
, argv
);
93 mv_orb_
= CORBA::ORB_init (argcon
.get_argc (), argcon
.get_TCHAR_argv ());
94 if (CORBA::is_nil (mv_orb_
.in ()))
96 ACE_DEBUG ((LM_ERROR
, ACE_TEXT ("nil ORB\n")));
100 CORBA::Object_var v_poa
=
101 mv_orb_
->resolve_initial_references ("RootPOA");
103 mv_rootPOA_
= PortableServer::POA::_narrow (v_poa
.in ());
104 if (CORBA::is_nil (mv_rootPOA_
.in ()))
106 ACE_DEBUG ((LM_ERROR
, ACE_TEXT ("nil RootPOA\n")));
110 mv_poaManager_
= mv_rootPOA_
->the_POAManager ();
111 if (CORBA::is_nil (mv_poaManager_
.in ()))
113 ACE_DEBUG ((LM_ERROR
, ACE_TEXT ("nil POAManager\n")));
117 mv_poaManager_
->activate ();
121 ACE_DEBUG ((LM_ERROR
, ACE_TEXT ("ERROR: exception\n")));
125 mp_barrier_
= new ACE_Thread_Barrier (threadCnt
+ 1);
127 this->activate (THR_NEW_LWP
|THR_JOINABLE
|THR_INHERIT_SCHED
, threadCnt
);
128 mp_barrier_
->wait ();
139 mv_poaManager_
->deactivate (1, 1);
140 mv_poaManager_
= PortableServer::POAManager::_nil ();
142 // attempt to protect against sporadic BAD_INV_ORDER exceptions
143 ACE_OS::sleep (ACE_Time_Value (0, 500));
145 mv_orb_
->shutdown (1);
149 ACE_DEBUG ((LM_ERROR
, ACE_TEXT ("ERROR: exception\n")));
153 // wait for our threads to finish
162 mv_orb_
= CORBA::ORB::_nil ();
164 catch (const CORBA::Exception
& ex
)
166 ex
._tao_print_exception ("Exception caught:");
170 if (failPrePostInit_
< 3)
172 // -----------------------------------------------------------------
173 // Post-ORB finalization steps necessary for proper DLL ORB
175 // -----------------------------------------------------------------
176 // Explicitly clean up singletons created by TAO before
177 // unloading this module.
178 TAO_Singleton_Manager
* p_tsm
= TAO_Singleton_Manager::instance ();
179 int result
= p_tsm
->fini ();
182 if (failPrePostInit_
== 0)
184 ACE_DEBUG ((LM_ERROR
,
185 ACE_TEXT ("Post-ORB finalization failed.\n")));
188 else if (failPrePostInit_
< 2)
190 ACE_DEBUG ((LM_WARNING
,
191 ACE_TEXT ("Post-ORB finalization failed (ignored due to FailPrePostInit setting).\n")));
196 ACE_TEXT ("Post-ORB finalization failed (ignored due to FailPrePostInit setting).\n")));
202 ACE_TEXT ("Post-ORB finalization done.\n")));
212 mp_barrier_
->wait ();
222 ACE_DEBUG ((LM_ERROR
, ACE_TEXT ("ERROR: exception\n")));
230 ACE_FACTORY_DEFINE (bug3486
, DllORB
)