2 //=============================================================================
6 * This program demonstrates creation of new POAs, as children of the root POA or the
8 * There are three new POA created in this example.
9 * The hierarchy of POAs looks like this.
11 * /-->first_poa-->first_poa/second_poa
15 * @author Irfan Pyarali
17 //=============================================================================
20 #include "tao/PortableServer/PortableServer.h"
24 #include "ace/SString.h"
25 #include "ace/Log_Msg.h"
28 print_poa (PortableServer::POA_ptr poa
)
30 CORBA::String_var poa_name
=
33 CORBA::OctetSeq_var poa_id
=
43 for (CORBA::ULong i
= 0;
44 i
!= poa_id
->length ();
55 PortableServer::POAList_var children
=
58 for (CORBA::ULong index
= 0;
59 index
!= children
->length ();
62 print_poa (children
[index
]);
67 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
71 // The first step Initialize the ORB
72 CORBA::ORB_var orb
= CORBA::ORB_init (argc
, argv
);
74 // Obtain the RootPOA.
75 CORBA::Object_var obj
=
76 orb
->resolve_initial_references ("RootPOA");
78 // _narrow() the Object to get the POA object, i.e., the root_poa.
79 PortableServer::POA_var root_poa
=
80 PortableServer::POA::_narrow (obj
.in ());
82 // Policies for the new POAs
83 CORBA::PolicyList
policies (2);
88 root_poa
->create_thread_policy (PortableServer::ORB_CTRL_MODEL
);
92 root_poa
->create_lifespan_policy (PortableServer::TRANSIENT
);
94 // Creation of the firstPOA
95 ACE_CString name
= "firstPOA";
96 PortableServer::POA_var first_poa
=
97 root_poa
->create_POA (name
.c_str (),
98 PortableServer::POAManager::_nil (),
101 // Creation of the new POA, i.e. firstPOA/secondPOA
103 PortableServer::POA_var second_poa
=
104 first_poa
->create_POA (name
.c_str (),
105 PortableServer::POAManager::_nil (),
108 // Creating thirdPOA.
111 PortableServer::POA_var third_poa
=
112 root_poa
->create_POA (name
.c_str (),
113 PortableServer::POAManager::_nil (),
116 // Creation of the new POAs over, so destroy the Policy_ptr's.
117 for (CORBA::ULong i
= 0;
118 i
< policies
.length ();
121 CORBA::Policy_ptr policy
= policies
[i
];
125 // Get the names of all the POAs and print them out.
127 CORBA::String_var root_poa_name
=
128 root_poa
->the_name ();
130 CORBA::String_var first_poa_name
=
131 first_poa
->the_name ();
133 CORBA::String_var second_poa_name
=
134 second_poa
->the_name ();
136 CORBA::String_var third_poa_name
=
137 third_poa
->the_name ();
139 ACE_DEBUG ((LM_DEBUG
,
142 first_poa_name
.in (),
143 second_poa_name
.in (),
144 third_poa_name
.in ()));
146 print_poa (root_poa
.in ());
150 catch (const CORBA::Exception
& ex
)
152 ex
._tao_print_exception ("Exception caught in main ");