Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / POA / NewPOA / NewPOA.cpp
bloba2c25fb53686dd5e027c8c28ab1c37c0dec67551
2 //=============================================================================
3 /**
4 * @file NewPOA.cpp
6 * This program demonstrates creation of new POAs, as children of the root POA or the
7 * existing POA.
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
12 * RootPOA--
13 * \-->third_poa
15 * @author Irfan Pyarali
17 //=============================================================================
20 #include "tao/PortableServer/PortableServer.h"
22 #include "tao/ORB.h"
24 #include "ace/SString.h"
25 #include "ace/Log_Msg.h"
27 void
28 print_poa (PortableServer::POA_ptr poa)
30 CORBA::String_var poa_name =
31 poa->the_name ();
33 CORBA::OctetSeq_var poa_id =
34 poa->id ();
36 ACE_DEBUG ((LM_DEBUG,
37 "POA name = %C\n",
38 poa_name.in ()));
40 ACE_DEBUG ((LM_DEBUG,
41 "POA id = "));
43 for (CORBA::ULong i = 0;
44 i != poa_id->length ();
45 ++i)
47 ACE_DEBUG ((LM_DEBUG,
48 "%o",
49 poa_id[i]));
52 ACE_DEBUG ((LM_DEBUG,
53 "\n"));
55 PortableServer::POAList_var children =
56 poa->the_children ();
58 for (CORBA::ULong index = 0;
59 index != children->length ();
60 ++index)
62 print_poa (children[index]);
66 int
67 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
69 try
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);
84 policies.length (2);
86 // Threading policy
87 policies[0] =
88 root_poa->create_thread_policy (PortableServer::ORB_CTRL_MODEL);
90 // Lifespan policy
91 policies[1] =
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 (),
99 policies);
101 // Creation of the new POA, i.e. firstPOA/secondPOA
102 name = "secondPOA";
103 PortableServer::POA_var second_poa =
104 first_poa->create_POA (name.c_str (),
105 PortableServer::POAManager::_nil (),
106 policies);
108 // Creating thirdPOA.
109 name = "thirdPOA";
111 PortableServer::POA_var third_poa =
112 root_poa->create_POA (name.c_str (),
113 PortableServer::POAManager::_nil (),
114 policies);
116 // Creation of the new POAs over, so destroy the Policy_ptr's.
117 for (CORBA::ULong i = 0;
118 i < policies.length ();
119 ++i)
121 CORBA::Policy_ptr policy = policies[i];
122 policy->destroy ();
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,
140 "%C\n%C\n%C\n%C\n",
141 root_poa_name.in (),
142 first_poa_name.in (),
143 second_poa_name.in (),
144 third_poa_name.in ()));
146 print_poa (root_poa.in ());
148 orb->destroy ();
150 catch (const CORBA::Exception& ex)
152 ex._tao_print_exception ("Exception caught in main ");
153 return -1;
156 return 0;