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
[])
72 // The first step Initialize the ORB
73 CORBA::ORB_var orb
= CORBA::ORB_init (argc
, argv
);
75 // Obtain the RootPOA.
76 CORBA::Object_var obj
=
77 orb
->resolve_initial_references ("RootPOA");
79 // _narrow() the Object to get the POA object, i.e., the root_poa.
80 PortableServer::POA_var root_poa
=
81 PortableServer::POA::_narrow (obj
.in ());
83 // Policies for the new POAs
84 CORBA::PolicyList
policies (2);
89 root_poa
->create_thread_policy (PortableServer::ORB_CTRL_MODEL
);
93 root_poa
->create_lifespan_policy (PortableServer::TRANSIENT
);
95 // Creation of the firstPOA
96 ACE_CString name
= "firstPOA";
97 PortableServer::POA_var first_poa
=
98 root_poa
->create_POA (name
.c_str (),
99 PortableServer::POAManager::_nil (),
102 // Creation of the new POA, i.e. firstPOA/secondPOA
104 PortableServer::POA_var second_poa
=
105 first_poa
->create_POA (name
.c_str (),
106 PortableServer::POAManager::_nil (),
109 // Creating thirdPOA.
112 PortableServer::POA_var third_poa
=
113 root_poa
->create_POA (name
.c_str (),
114 PortableServer::POAManager::_nil (),
117 // Creation of the new POAs over, so destroy the Policy_ptr's.
118 for (CORBA::ULong i
= 0;
119 i
< policies
.length ();
122 CORBA::Policy_ptr policy
= policies
[i
];
126 // Get the names of all the POAs and print them out.
128 CORBA::String_var root_poa_name
=
129 root_poa
->the_name ();
131 CORBA::String_var first_poa_name
=
132 first_poa
->the_name ();
134 CORBA::String_var second_poa_name
=
135 second_poa
->the_name ();
137 CORBA::String_var third_poa_name
=
138 third_poa
->the_name ();
140 ACE_DEBUG ((LM_DEBUG
,
143 first_poa_name
.in (),
144 second_poa_name
.in (),
145 third_poa_name
.in ()));
147 print_poa (root_poa
.in ());
151 catch (const CORBA::Exception
& ex
)
153 ex
._tao_print_exception ("Exception caught in main ");