Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / tests / Bug_2936_Regression / PersistentPOA.cpp
blobf2ffdd12f740b9b5da8588cbf7b2d7454cf707c6
2 #include "ace/Arg_Shifter.h"
3 #include "tao/PortableServer/POAManager.h"
4 #include "tao/PortableServer/PortableServer.h"
6 #include "PersistentPOA.h"
7 #include "DllORB.h"
9 const ACE_TCHAR *POAname_ = 0;
10 const ACE_TCHAR *ORBname_ = 0;
12 PersistentPoa::PersistentPoa ()
16 PersistentPoa::~PersistentPoa () noexcept
20 int PersistentPoa::init (int argc, ACE_TCHAR *argv[])
22 int result = 0;
24 ACE_Arg_Shifter as(argc, argv);
25 POAname_ = as.get_current();
26 as.ignore_arg();
28 ORBname_ = as.get_current();
29 as.ignore_arg();
31 while(as.is_anything_left())
33 as.ignore_arg();
36 try
38 DllORB * p_orb = ACE_Dynamic_Service<DllORB>::instance (ORBname_);
40 mv_orb = p_orb->orb();
42 CORBA::Object_var v_poa = mv_orb->resolve_initial_references("RootPOA");
44 mv_rootPOA = PortableServer::POA::_narrow(v_poa.in ());
46 if(CORBA::is_nil(mv_rootPOA.in()))
48 ACE_DEBUG((
49 LM_DEBUG,
50 ACE_TEXT ("(%P|%t) init - nil root POA\n")
51 ));
52 return -1;
55 // Policies for the new POA
56 CORBA::PolicyList policies(3);
57 policies.length (3);
59 // Threading policy
60 policies[0] = mv_rootPOA->create_thread_policy(PortableServer::ORB_CTRL_MODEL);
62 // Lifespan policy
63 policies[1] = mv_rootPOA->create_lifespan_policy(PortableServer::PERSISTENT);
65 // ID assignment policy
66 policies[2] = mv_rootPOA->create_id_assignment_policy(PortableServer::USER_ID);
68 mv_thisPOA = mv_rootPOA->create_POA(
69 ACE_TEXT_ALWAYS_CHAR(POAname_),
70 PortableServer::POAManager::_nil(),
71 policies);
72 if (CORBA::is_nil(mv_thisPOA.in()))
74 ACE_DEBUG((
75 LM_DEBUG,
76 ACE_TEXT ("(%P|%t) init - POA creation failed\n")
77 ));
78 return -1;
80 else
82 ACE_DEBUG((
83 LM_DEBUG,
84 ACE_TEXT ("(%P|%t) init - POA created\n")
85 ));
88 mv_poaManager = mv_thisPOA->the_POAManager();
90 mv_poaManager->activate();
91 ACE_DEBUG((
92 LM_DEBUG,
93 ACE_TEXT ("(%P|%t) init - activated POA manager\n")
94 ));
96 catch(...)
98 ACE_DEBUG((
99 LM_DEBUG,
100 ACE_TEXT ("(%P|%t) init - exception\n")
102 result = -1;
103 return result;
106 ACE_DEBUG((
107 LM_DEBUG,
108 ACE_TEXT ("(%P|%t) init - POA activated\n")
111 return result;
115 int PersistentPoa::fini ()
117 int result = 0;
121 mv_poaManager->deactivate(1, 1);
122 mv_thisPOA->destroy(1, 1);
123 mv_thisPOA = PortableServer::POA::_nil();
125 catch(...)
127 ACE_DEBUG((
128 LM_DEBUG,
129 ACE_TEXT ("(%P|%t) init - exception\n")
131 result = -1;
132 return result;
134 ACE_DEBUG((
135 LM_DEBUG,
136 ACE_TEXT ("(%P|%t) fini - POA deactivated\n")
139 return result;
142 ACE_FACTORY_DEFINE (bug2936, PersistentPoa)