2 //=============================================================================
6 * This program is an extension of $TAO_ROOT/example/POA/NewPOA. In
7 * the many POA's created this example adds a BiDirGIOP policy to
10 * @author Balachandran Natarajan <bala@cs.wustl.edu>
12 //=============================================================================
15 #include "tao/PortableServer/PortableServer.h"
17 #include "tao/BiDir_GIOP/BiDirGIOP.h"
19 #include "tao/AnyTypeCode/Any.h"
22 #include "ace/SString.h"
25 print_poa (PortableServer::POA_ptr poa
)
27 CORBA::String_var poa_name
=
30 CORBA::OctetSeq_var poa_id
=
40 for (CORBA::ULong i
= 0;
41 i
!= poa_id
->length ();
52 PortableServer::POAList_var children
=
55 for (CORBA::ULong index
= 0;
56 index
!= children
->length ();
59 print_poa (children
[index
]);
64 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
68 // The first step Initialize the ORB
69 CORBA::ORB_var orb
= CORBA::ORB_init (argc
, argv
);
71 // Obtain the RootPOA.
72 CORBA::Object_var obj
=
73 orb
->resolve_initial_references ("RootPOA");
75 // _narrow() the Object to get the POA object, i.e., the root_poa.
76 PortableServer::POA_var root_poa
=
77 PortableServer::POA::_narrow (obj
.in ());
79 // Policies for the new POAs
80 CORBA::PolicyList
policies (2);
85 root_poa
->create_thread_policy (PortableServer::ORB_CTRL_MODEL
);
89 root_poa
->create_lifespan_policy (PortableServer::TRANSIENT
);
91 // Creation of the firstPOA
92 ACE_CString name
= "firstPOA";
93 PortableServer::POA_var first_poa
=
94 root_poa
->create_POA (name
.c_str (),
95 PortableServer::POAManager::_nil (),
98 // Creation of the new POA, i.e. firstPOA/secondPOA
100 PortableServer::POA_var second_poa
=
101 first_poa
->create_POA (name
.c_str (),
102 PortableServer::POAManager::_nil (),
105 // Creation of the new POAs over, so destroy the Policy_ptr's.
106 for (CORBA::ULong i
= 0;
107 i
< policies
.length ();
110 CORBA::Policy_ptr policy
= policies
[i
];
115 pol
<<= BiDirPolicy::BOTH
;
116 CORBA::PolicyList
bidir_policy (1);
117 bidir_policy
.length (1);
120 orb
->create_policy (BiDirPolicy::BIDIRECTIONAL_POLICY_TYPE
,
124 // Creating thirdPOA.
127 PortableServer::POA_var third_poa
=
128 root_poa
->create_POA (name
.c_str (),
129 PortableServer::POAManager::_nil (),
132 // Creation of childPOA is over. Destroy the Policy objects.
133 for (CORBA::ULong k
= 0;
134 k
< bidir_policy
.length ();
137 bidir_policy
[k
]->destroy ();
140 // Get the names of all the POAs and print them out.
142 CORBA::String_var root_poa_name
=
143 root_poa
->the_name ();
145 CORBA::String_var first_poa_name
=
146 first_poa
->the_name ();
148 CORBA::String_var second_poa_name
=
149 second_poa
->the_name ();
151 CORBA::String_var third_poa_name
=
152 third_poa
->the_name ();
154 ACE_DEBUG ((LM_DEBUG
,
157 first_poa_name
.in (),
158 second_poa_name
.in (),
159 third_poa_name
.in ()));
161 print_poa (root_poa
.in ());
165 catch (const CORBA::Exception
& ex
)
167 ex
._tao_print_exception ("Exception caught in main ");