Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / tests / POA / POA_BiDir / POA_BiDir.cpp
blobee7da30c48e32e140182237caa4eae17d39c438b
2 //=============================================================================
3 /**
4 * @file POA_BiDir.cpp
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
8 * one of the POA's.
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"
20 #include "tao/ORB.h"
22 #include "ace/SString.h"
24 void
25 print_poa (PortableServer::POA_ptr poa)
27 CORBA::String_var poa_name =
28 poa->the_name ();
30 CORBA::OctetSeq_var poa_id =
31 poa->id ();
33 ACE_DEBUG ((LM_DEBUG,
34 "POA name = %C\n",
35 poa_name.in ()));
37 ACE_DEBUG ((LM_DEBUG,
38 "POA id = "));
40 for (CORBA::ULong i = 0;
41 i != poa_id->length ();
42 ++i)
44 ACE_DEBUG ((LM_DEBUG,
45 "%o",
46 poa_id[i]));
49 ACE_DEBUG ((LM_DEBUG,
50 "\n"));
52 PortableServer::POAList_var children =
53 poa->the_children ();
55 for (CORBA::ULong index = 0;
56 index != children->length ();
57 ++index)
59 print_poa (children[index]);
63 int
64 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
66 try
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);
81 policies.length (2);
83 // Threading policy
84 policies[0] =
85 root_poa->create_thread_policy (PortableServer::ORB_CTRL_MODEL);
87 // Lifespan policy
88 policies[1] =
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 (),
96 policies);
98 // Creation of the new POA, i.e. firstPOA/secondPOA
99 name = "secondPOA";
100 PortableServer::POA_var second_poa =
101 first_poa->create_POA (name.c_str (),
102 PortableServer::POAManager::_nil (),
103 policies);
105 // Creation of the new POAs over, so destroy the Policy_ptr's.
106 for (CORBA::ULong i = 0;
107 i < policies.length ();
108 ++i)
110 CORBA::Policy_ptr policy = policies[i];
111 policy->destroy ();
114 CORBA::Any pol;
115 pol <<= BiDirPolicy::BOTH;
116 CORBA::PolicyList bidir_policy (1);
117 bidir_policy.length (1);
119 bidir_policy[0] =
120 orb->create_policy (BiDirPolicy::BIDIRECTIONAL_POLICY_TYPE,
121 pol);
124 // Creating thirdPOA.
125 name = "thirdPOA";
127 PortableServer::POA_var third_poa =
128 root_poa->create_POA (name.c_str (),
129 PortableServer::POAManager::_nil (),
130 bidir_policy);
132 // Creation of childPOA is over. Destroy the Policy objects.
133 for (CORBA::ULong k = 0;
134 k < bidir_policy.length ();
135 ++k)
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,
155 "%C\n%C\n%C\n%C\n",
156 root_poa_name.in (),
157 first_poa_name.in (),
158 second_poa_name.in (),
159 third_poa_name.in ()));
161 print_poa (root_poa.in ());
163 orb->destroy ();
165 catch (const CORBA::Exception& ex)
167 ex._tao_print_exception ("Exception caught in main ");
168 return -1;
171 return 0;