Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / orbsvcs / tests / Notify / Bug_3646d_Regression / DllORB.cpp
blobc6735f16c80306dfedb5f1543fb08a0a9275d6e3
1 #include "DllORB.h"
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"
9 DllORB::DllORB ()
10 : failPrePostInit_ (3),
11 mp_barrier_ (0),
12 mv_orb_ (),
13 mv_rootPOA_ ()
17 DllORB::~DllORB ()
19 delete mp_barrier_;
22 int
23 DllORB::init (int argc, ACE_TCHAR *argv[])
25 int threadCnt = 1;
27 try
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);
36 if (num >= 1)
37 threadCnt = num;
38 as.consume_arg ();
40 else
41 as.ignore_arg ();
44 if (failPrePostInit_ < 3)
46 ACE_DEBUG ((LM_INFO,
47 ACE_TEXT ("Pre-ORB initialization ...\n")));
48 // -----------------------------------------------------------------
49 // Pre-ORB initialization steps necessary for proper DLL ORB
50 // support.
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
58 // unloaded.
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);
63 if (result == -1)
65 if (failPrePostInit_ == 0)
67 ACE_DEBUG ((LM_ERROR,
68 ACE_TEXT ("Pre-ORB initialization failed.\n")));
69 return -1;
71 else if (failPrePostInit_ < 2)
73 ACE_DEBUG ((LM_WARNING,
74 ACE_TEXT ("Pre-ORB initialization failed (ignored due to FailPrePostInit setting).\n")));
76 else
78 ACE_DEBUG ((LM_INFO,
79 ACE_TEXT ("Pre-ORB initialization failed (ignored due to FailPrePostInit setting).\n")));
82 else
84 ACE_DEBUG ((LM_INFO,
85 ACE_TEXT ("Pre-ORB initialization done.\n")));
89 // Initialize the ORB
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")));
94 return -1;
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")));
104 return -1;
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")));
111 return -1;
114 mv_poaManager_->activate ();
116 catch (...)
118 ACE_DEBUG ((LM_ERROR, ACE_TEXT ("ERROR: exception\n")));
119 return -1;
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 ();
127 return 0;
132 DllORB::fini ()
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 (true);
144 catch (...)
146 ACE_DEBUG ((LM_ERROR, ACE_TEXT ("ERROR: exception\n")));
147 return -1;
150 // wait for our threads to finish
151 this->wait ();
153 delete mp_barrier_;
154 mp_barrier_ = 0;
158 mv_orb_->destroy ();
159 mv_orb_ = CORBA::ORB::_nil ();
161 catch (const CORBA::Exception& ex)
163 ex._tao_print_exception ("Exception caught:");
164 return -1;
167 if (failPrePostInit_ < 3)
169 // -----------------------------------------------------------------
170 // Post-ORB finalization steps necessary for proper DLL ORB
171 // support.
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 ();
177 if (result == -1)
179 if (failPrePostInit_ == 0)
181 ACE_DEBUG ((LM_ERROR,
182 ACE_TEXT ("Post-ORB finalization failed.\n")));
183 return -1;
185 else if (failPrePostInit_ < 2)
187 ACE_DEBUG ((LM_WARNING,
188 ACE_TEXT ("Post-ORB finalization failed (ignored due to FailPrePostInit setting).\n")));
190 else
192 ACE_DEBUG ((LM_INFO,
193 ACE_TEXT ("Post-ORB finalization failed (ignored due to FailPrePostInit setting).\n")));
196 else
198 ACE_DEBUG ((LM_INFO,
199 ACE_TEXT ("Post-ORB finalization done.\n")));
203 return 0;
207 int DllORB::svc ()
209 mp_barrier_->wait ();
211 int result = 0;
215 mv_orb_->run ();
217 catch (...)
219 ACE_DEBUG ((LM_ERROR, ACE_TEXT ("ERROR: exception\n")));
220 result = 1;
223 return result;
227 ACE_FACTORY_DEFINE (bug3646d, DllORB)