Merge pull request #2222 from jwillemsen/jwi-dllexportwarning
[ACE_TAO.git] / TAO / tests / Bug_2677_Regression / DllORB.cpp
blobab2b7bb796e7a5ff6cf78211ad459b4c1d82417e
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 : failPrePostInit_ (3),
9 mv_orb_ (),
10 mv_rootPOA_ ()
14 DllORB::~DllORB ()
18 int
19 DllORB::init (int argc, ACE_TCHAR *argv[])
21 try
23 if (failPrePostInit_ < 3)
25 ACE_DEBUG ((LM_INFO,
26 ACE_TEXT ("Pre-ORB initialization ...\n")));
27 // -----------------------------------------------------------------
28 // Pre-ORB initialization steps necessary for proper DLL ORB
29 // support.
30 // -----------------------------------------------------------------
31 // Make sure TAO's singleton manager is initialized, and set to not
32 // register itself with the ACE_Object_Manager since it is under the
33 // control of the Service Configurator. If we register with the
34 // ACE_Object_Manager, then the ACE_Object_Manager will still hold
35 // (dangling) references to instances of objects created by this
36 // module and destroyed by this object when it is dynamically
37 // unloaded.
38 int register_with_object_manager = 0;
39 TAO_Singleton_Manager * p_tsm = TAO_Singleton_Manager::instance ();
40 int result = p_tsm->init (register_with_object_manager);
42 if (result == -1)
44 if (failPrePostInit_ == 0)
46 ACE_DEBUG ((LM_ERROR,
47 ACE_TEXT ("Pre-ORB initialization failed.\n")));
48 return -1;
50 else if (failPrePostInit_ < 2)
52 ACE_DEBUG ((LM_WARNING,
53 ACE_TEXT ("Pre-ORB initialization failed (ignored due to FailPrePostInit setting).\n")));
55 else
57 ACE_DEBUG ((LM_INFO,
58 ACE_TEXT ("Pre-ORB initialization failed (ignored due to FailPrePostInit setting).\n")));
61 else
63 ACE_DEBUG ((LM_INFO,
64 ACE_TEXT ("Pre-ORB initialization done.\n")));
68 // Initialize the ORB
69 mv_orb_ = CORBA::ORB_init (argc, argv);
70 if (CORBA::is_nil (mv_orb_.in ()))
72 ACE_DEBUG ((LM_ERROR, ACE_TEXT ("nil ORB\n")));
73 return -1;
76 CORBA::Object_var v_poa =
77 mv_orb_->resolve_initial_references ("RootPOA");
79 mv_rootPOA_ = PortableServer::POA::_narrow (v_poa.in ());
80 if (CORBA::is_nil (mv_rootPOA_.in ()))
82 ACE_DEBUG ((LM_ERROR, ACE_TEXT ("nil RootPOA\n")));
83 return -1;
86 mv_poaManager_ = mv_rootPOA_->the_POAManager ();
87 if (CORBA::is_nil (mv_poaManager_.in ()))
89 ACE_DEBUG ((LM_ERROR, ACE_TEXT ("nil POAManager\n")));
90 return -1;
93 mv_poaManager_->activate ();
95 catch (...)
97 ACE_DEBUG ((LM_ERROR, ACE_TEXT ("ERROR: exception\n")));
98 return -1;
101 return 0;
106 DllORB::fini ()
110 mv_poaManager_ = PortableServer::POAManager::_nil ();
112 // attempt to protect against sporadic BAD_INV_ORDER exceptions
113 ACE_OS::sleep (ACE_Time_Value (0, 500));
115 mv_orb_->shutdown (true);
117 catch (...)
119 ACE_DEBUG ((LM_ERROR, ACE_TEXT ("ERROR: exception\n")));
120 return -1;
125 mv_orb_->destroy ();
126 mv_orb_ = CORBA::ORB::_nil ();
128 catch (const CORBA::Exception& ex)
130 ex._tao_print_exception ("Exception caught:");
131 return -1;
134 if (failPrePostInit_ < 3)
136 // -----------------------------------------------------------------
137 // Post-ORB finalization steps necessary for proper DLL ORB
138 // support.
139 // -----------------------------------------------------------------
140 // Explicitly clean up singletons created by TAO before
141 // unloading this module.
142 TAO_Singleton_Manager * p_tsm = TAO_Singleton_Manager::instance ();
143 int result = p_tsm->fini ();
144 if (result == -1)
146 if (failPrePostInit_ == 0)
148 ACE_DEBUG ((LM_ERROR,
149 ACE_TEXT ("Post-ORB finalization failed.\n")));
150 return -1;
152 else if (failPrePostInit_ < 2)
154 ACE_DEBUG ((LM_WARNING,
155 ACE_TEXT ("Post-ORB finalization failed (ignored due to FailPrePostInit setting).\n")));
157 else
159 ACE_DEBUG ((LM_INFO,
160 ACE_TEXT ("Post-ORB finalization failed (ignored due to FailPrePostInit setting).\n")));
163 else
165 ACE_DEBUG ((LM_INFO,
166 ACE_TEXT ("Post-ORB finalization done.\n")));
170 return 0;
174 ACE_FACTORY_DEFINE (bug_2677_regression, DllORB)