Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tests / Bug_3251_Regression / DllOrb.cpp
blobb10f270e0b715883c4f63713d7ff9e8ab4f8a8a0
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"
8 DllOrb::DllOrb ()
10 ma_barrier_(),
11 mv_orb_ (),
12 mv_rootPOA_ ()
17 DllOrb::~DllOrb ()
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 (0 != (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 // Initialize the ORB
45 mv_orb_ = CORBA::ORB_init (argc, argv);
46 if (CORBA::is_nil (mv_orb_.in ()))
48 ACE_DEBUG ((LM_ERROR, ACE_TEXT ("nil ORB\n")));
49 return -1;
52 CORBA::Object_var v_poa =
53 mv_orb_->resolve_initial_references ("RootPOA");
55 mv_rootPOA_ = PortableServer::POA::_narrow (v_poa.in ());
56 if (CORBA::is_nil (mv_rootPOA_.in ()))
58 ACE_DEBUG ((LM_ERROR, ACE_TEXT ("nil RootPOA\n")));
59 return -1;
62 mv_poaManager_ = mv_rootPOA_->the_POAManager ();
63 if (CORBA::is_nil (mv_poaManager_.in ()))
65 ACE_DEBUG ((LM_ERROR, ACE_TEXT ("nil POAManager\n")));
66 return -1;
69 mv_poaManager_->activate ();
71 catch (...)
73 ACE_DEBUG ((LM_ERROR, ACE_TEXT ("ERROR: exception\n")));
74 return -1;
77 ma_barrier_.reset (new ACE_Thread_Barrier (threadCnt + 1));
79 this->activate(
80 THR_NEW_LWP|THR_JOINABLE|THR_INHERIT_SCHED,
81 threadCnt);
82 ACE_DEBUG ((LM_INFO, ACE_TEXT ("init mp_barrier->wait() ...\n")));
83 ma_barrier_->wait();
84 ACE_DEBUG ((LM_INFO, ACE_TEXT ("init mp_barrier->wait() done\n")));
86 return 0;
90 int
91 DllOrb::fini ()
93 try
95 mv_poaManager_->deactivate (1, 1);
96 mv_poaManager_ = PortableServer::POAManager::_nil ();
98 // attempt to protect against sporadic BAD_INV_ORDER exceptions
99 ACE_OS::sleep (ACE_Time_Value (0, 500));
101 mv_orb_->shutdown (true);
103 ACE_DEBUG ((LM_ERROR, ACE_TEXT ("wait() ...\n")));
104 // wait for our threads to finish
105 wait();
106 ACE_DEBUG ((LM_ERROR, ACE_TEXT ("wait() done\n")));
108 ma_barrier_.reset ();
110 catch (...)
112 ACE_DEBUG ((LM_ERROR, ACE_TEXT ("ERROR: exception\n")));
113 return -1;
118 mv_orb_->destroy ();
119 mv_orb_ = CORBA::ORB::_nil ();
121 catch (const CORBA::Exception& ex)
123 ex._tao_print_exception ("Exception caught:");
124 return -1;
127 return 0;
131 int DllOrb::svc ()
133 ACE_DEBUG ((LM_INFO, ACE_TEXT ("svc mp_barrier->wait() ...\n")));
134 ma_barrier_->wait();
135 ACE_DEBUG ((LM_INFO, ACE_TEXT ("svc mp_barrier->wait() done\n")));
139 ACE_DEBUG ((LM_INFO, ACE_TEXT ("mv_orb->run ...\n")));
142 mv_orb_->run();
143 ACE_DEBUG ((LM_INFO, ACE_TEXT ("mv_orb->run returned\n")));
145 catch(CORBA::BAD_INV_ORDER const & rc_ex)
147 const CORBA::ULong VMCID = rc_ex.minor() & 0xFFFFF000U;
148 const CORBA::ULong minorCode = rc_ex.minor() & 0xFFFU;
149 if (VMCID == CORBA::OMGVMCID && minorCode == 4)
151 ACE_DEBUG ((LM_INFO, ACE_TEXT ("ignored 'CORBA::BAD_INV_ORDER: ORB has shutdown.'\n")));
153 else
155 throw;
158 ACE_DEBUG ((LM_INFO, ACE_TEXT ("mv_orb->run done\n")));
160 catch(...)
162 ACE_DEBUG ((LM_INFO, ACE_TEXT ("Exception\n")));
163 return -1;
166 return 0;
167 } /* end of DllOrb::svc () */
170 ACE_FACTORY_DEFINE (bug_3251, DllOrb)