Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tests / Bug_3251_Regression / PersistentPoa.cpp
blobf5c5e4cbc49c22b3fcd7092379dcee814f42008f
1 #include "ace/Arg_Shifter.h"
2 #include "tao/PortableServer/POAManager.h"
3 #include "tao/PortableServer/PortableServer.h"
5 #include "PersistentPoa.h"
7 PersistentPoa::PersistentPoa ()
11 PersistentPoa::~PersistentPoa () noexcept
15 int PersistentPoa::init (int argc, ACE_TCHAR *argv[])
17 ACE_Arg_Shifter as (argc, argv);
18 m_poaName = std::string (ACE_TEXT_ALWAYS_CHAR (as.get_current ()));
19 as.ignore_arg ();
21 std::string orbName (ACE_TEXT_ALWAYS_CHAR (as.get_current()));
22 as.ignore_arg ();
24 while (as.is_anything_left ())
26 as.ignore_arg();
29 try
31 // left out all safety checks
32 DllOrb * p_orb = ACE_Dynamic_Service<DllOrb>::instance (orbName.c_str ());
33 mv_orb = p_orb->orb ();
34 CORBA::Object_var v_poa = mv_orb->resolve_initial_references ("RootPOA");
35 mv_rootPOA = PortableServer::POA::_narrow (v_poa.in ());
37 // Policies for the new POA
38 CORBA::PolicyList policies (3);
39 policies.length (3);
40 policies[0] = mv_rootPOA->create_thread_policy (PortableServer::ORB_CTRL_MODEL);
41 policies[1] = mv_rootPOA->create_lifespan_policy (PortableServer::PERSISTENT);
42 policies[2] = mv_rootPOA->create_id_assignment_policy (PortableServer::USER_ID);
44 mv_thisPOA = mv_rootPOA->create_POA (
45 m_poaName.c_str (),
46 PortableServer::POAManager::_nil (),
47 policies);
49 mv_poaManager = mv_thisPOA->the_POAManager ();
50 mv_poaManager->activate ();
52 catch (...)
54 ACE_DEBUG ((LM_ERROR, ACE_TEXT ("activate failed\n")));
55 return -1;
58 ACE_DEBUG ((LM_ERROR, ACE_TEXT ("POA activated\n")));
60 return 0;
64 int PersistentPoa::fini ()
66 try
68 mv_poaManager->deactivate (1, 1);
69 mv_poaManager = PortableServer::POAManager::_nil ();
71 mv_thisPOA->destroy (1, 1);
72 mv_thisPOA = PortableServer::POA::_nil ();
74 catch(...)
76 ACE_DEBUG ((LM_ERROR, ACE_TEXT ("deactivate failed\n")));
77 return -1;
80 ACE_DEBUG ((LM_ERROR, ACE_TEXT ("POA deactivated\n")));
82 return 0;
86 ACE_FACTORY_DEFINE (bug_3251, PersistentPoa)