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 mv_orb_
= CORBA::ORB_init (argc
, argv
);
93 if (CORBA::is_nil (mv_orb_
.in ()))
95 ACE_DEBUG ((LM_ERROR
, ACE_TEXT ("nil ORB\n")));
99 CORBA::Object_var v_poa
=
100 mv_orb_
->resolve_initial_references ("RootPOA");
102 mv_rootPOA_
= PortableServer::POA::_narrow (v_poa
.in ());
103 if (CORBA::is_nil (mv_rootPOA_
.in ()))
105 ACE_DEBUG ((LM_ERROR
, ACE_TEXT ("nil RootPOA\n")));
109 mv_poaManager_
= mv_rootPOA_
->the_POAManager ();
110 if (CORBA::is_nil (mv_poaManager_
.in ()))
112 ACE_DEBUG ((LM_ERROR
, ACE_TEXT ("nil POAManager\n")));
116 mv_poaManager_
->activate ();
120 ACE_DEBUG ((LM_ERROR
, ACE_TEXT ("ERROR: exception\n")));
124 mp_barrier_
= new ACE_Thread_Barrier (threadCnt
+ 1);
126 this->activate (THR_NEW_LWP
|THR_JOINABLE
|THR_INHERIT_SCHED
, threadCnt
);
127 mp_barrier_
->wait ();
138 mv_poaManager_
->deactivate (1, 1);
139 mv_poaManager_
= PortableServer::POAManager::_nil ();
141 // attempt to protect against sporadic BAD_INV_ORDER exceptions
142 ACE_OS::sleep (ACE_Time_Value (0, 500));
144 mv_orb_
->shutdown (true);
148 ACE_DEBUG ((LM_ERROR
, ACE_TEXT ("ERROR: exception\n")));
152 // wait for our threads to finish
161 mv_orb_
= CORBA::ORB::_nil ();
163 catch (const CORBA::Exception
& ex
)
165 ex
._tao_print_exception ("Exception caught:");
169 if (failPrePostInit_
< 3)
171 // -----------------------------------------------------------------
172 // Post-ORB finalization steps necessary for proper DLL ORB
174 // -----------------------------------------------------------------
175 // Explicitly clean up singletons created by TAO before
176 // unloading this module.
177 TAO_Singleton_Manager
* p_tsm
= TAO_Singleton_Manager::instance ();
178 int result
= p_tsm
->fini ();
181 if (failPrePostInit_
== 0)
183 ACE_DEBUG ((LM_ERROR
,
184 ACE_TEXT ("Post-ORB finalization failed.\n")));
187 else if (failPrePostInit_
< 2)
189 ACE_DEBUG ((LM_WARNING
,
190 ACE_TEXT ("Post-ORB finalization failed (ignored due to FailPrePostInit setting).\n")));
195 ACE_TEXT ("Post-ORB finalization failed (ignored due to FailPrePostInit setting).\n")));
201 ACE_TEXT ("Post-ORB finalization done.\n")));
211 mp_barrier_
->wait ();
221 ACE_DEBUG ((LM_ERROR
, ACE_TEXT ("ERROR: exception\n")));
229 ACE_FACTORY_DEFINE (bug2936
, DllORB
)