Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / orbsvcs / tests / Notify / Bug_3252_Regression / DllOrb.cpp
blob2e9f2f5cf5c82e6dc38f111a211ed538e22632c2
1 #include "DllOrb.h"
2 #include "ace/Arg_Shifter.h"
3 #include "ace/Argv_Type_Converter.h"
4 #include "ace/OS_NS_unistd.h"
5 #include "tao/TAO_Singleton_Manager.h"
7 DllOrb::DllOrb ()
8 : ma_barrier_(),
9 mv_orb_ (),
10 mv_rootPOA_ ()
14 DllOrb::~DllOrb ()
18 int
19 DllOrb::init (int argc, ACE_TCHAR *argv[])
21 int threadCnt = 1;
23 try
25 ACE_Arg_Shifter as (argc, argv);
26 const ACE_TCHAR *currentArg = 0;
27 while (as.is_anything_left ())
29 if (0 != (currentArg = as.get_the_parameter (ACE_TEXT ("-NumThreads"))))
31 int num = ACE_OS::atoi (currentArg);
32 if (num >= 1)
33 threadCnt = num;
34 as.consume_arg ();
36 else
37 as.ignore_arg ();
40 // Initialize the ORB
41 mv_orb_ = CORBA::ORB_init (argc, argv);
42 if (CORBA::is_nil (mv_orb_.in ()))
44 ACE_DEBUG ((LM_ERROR, ACE_TEXT ("nil ORB\n")));
45 return -1;
48 CORBA::Object_var v_poa =
49 mv_orb_->resolve_initial_references ("RootPOA");
51 mv_rootPOA_ = PortableServer::POA::_narrow (v_poa.in ());
52 if (CORBA::is_nil (mv_rootPOA_.in ()))
54 ACE_DEBUG ((LM_ERROR, ACE_TEXT ("nil RootPOA\n")));
55 return -1;
58 mv_poaManager_ = mv_rootPOA_->the_POAManager ();
59 if (CORBA::is_nil (mv_poaManager_.in ()))
61 ACE_DEBUG ((LM_ERROR, ACE_TEXT ("nil POAManager\n")));
62 return -1;
65 mv_poaManager_->activate ();
67 catch (...)
69 ACE_DEBUG ((LM_ERROR, ACE_TEXT ("ERROR: exception\n")));
70 return -1;
73 ma_barrier_.reset (new ACE_Thread_Barrier (threadCnt + 1));
75 this->activate(
76 THR_NEW_LWP|THR_JOINABLE|THR_INHERIT_SCHED,
77 threadCnt);
78 ACE_DEBUG ((LM_INFO, ACE_TEXT ("init mp_barrier->wait() ...\n")));
79 ma_barrier_->wait();
80 ACE_DEBUG ((LM_INFO, ACE_TEXT ("init mp_barrier->wait() done\n")));
82 return 0;
85 int
86 DllOrb::fini ()
88 try
90 mv_poaManager_->deactivate (1, 1);
91 mv_poaManager_ = PortableServer::POAManager::_nil ();
93 // attempt to protect against sporadic BAD_INV_ORDER exceptions
94 ACE_OS::sleep (ACE_Time_Value (0, 500));
96 mv_rootPOA_->destroy (1, 1);
98 mv_rootPOA_ = PortableServer::POA::_nil ();
99 mv_orb_->shutdown (true);
101 ACE_DEBUG ((LM_ERROR, ACE_TEXT ("wait() ...\n")));
102 // wait for our threads to finish
103 wait();
104 ACE_DEBUG ((LM_ERROR, ACE_TEXT ("wait() done\n")));
106 ma_barrier_.reset ();
108 catch (...)
110 ACE_DEBUG ((LM_ERROR, ACE_TEXT ("ERROR: exception\n")));
111 return -1;
116 mv_orb_->destroy ();
117 mv_orb_ = CORBA::ORB::_nil ();
119 catch (const CORBA::Exception& ex)
121 ex._tao_print_exception ("Exception caught:");
122 return -1;
125 return 0;
128 int DllOrb::svc ()
130 ACE_DEBUG ((LM_INFO, ACE_TEXT ("svc mp_barrier->wait() ...\n")));
131 ma_barrier_->wait();
132 ACE_DEBUG ((LM_INFO, ACE_TEXT ("svc mp_barrier->wait() done\n")));
136 ACE_DEBUG ((LM_INFO, ACE_TEXT ("mv_orb->run ...\n")));
139 mv_orb_->run();
140 ACE_DEBUG ((LM_INFO, ACE_TEXT ("mv_orb->run returned\n")));
142 catch(CORBA::BAD_INV_ORDER const & rc_ex)
144 const CORBA::ULong VMCID = rc_ex.minor() & 0xFFFFF000U;
145 const CORBA::ULong minorCode = rc_ex.minor() & 0xFFFU;
146 if (VMCID == CORBA::OMGVMCID && minorCode == 4)
148 ACE_DEBUG ((LM_INFO, ACE_TEXT ("ignored 'CORBA::BAD_INV_ORDER: ORB has shutdown.'\n")));
150 else
152 throw;
155 ACE_DEBUG ((LM_INFO, ACE_TEXT ("mv_orb->run done\n")));
157 catch(...)
159 ACE_DEBUG ((LM_INFO, ACE_TEXT ("Exception\n")));
160 return -1;
163 return 0;
164 } /* end of DllOrb::svc () */
167 ACE_FACTORY_DEFINE (bug_3252, DllOrb)