Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / Bug_1869_Regression / server.cpp
blob9a9e55eb805ea8c4e4eb6d2d8404c01f3746447d
1 #include "AMIS.h"
2 #include "tao/IORTable/IORTable.h"
4 class AdderServant :
5 public POA_AMI_test::adder {
6 public:
7 AdderServant () = default;
9 virtual ~AdderServant () = default;
11 virtual
12 CORBA::Long add (CORBA::Long a, CORBA::Long b)
14 return a + b;
18 int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) {
19 try {
20 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
22 // Get reference to Root POA
23 CORBA::Object_var obj
24 = orb->resolve_initial_references ("RootPOA");
26 PortableServer::POA_var rootPOA = PortableServer::POA::_narrow (obj.in ());
28 // Activate POA manager
29 PortableServer::POAManager_var mgr
30 = rootPOA->the_POAManager ();
32 mgr->activate();
34 // Create Persistent Lifespan Policy and User Id Policy
35 PortableServer::LifespanPolicy_var lifespan =
36 rootPOA->create_lifespan_policy(PortableServer::PERSISTENT);
37 PortableServer::IdAssignmentPolicy_var idassignment =
38 rootPOA->create_id_assignment_policy(PortableServer::USER_ID);
40 // Stuff them into a policy list
41 CORBA::PolicyList policies(2);
42 policies.length(2);
43 policies[0] = PortableServer::IdAssignmentPolicy::_duplicate(idassignment.in());
44 policies[1] = PortableServer::LifespanPolicy::_duplicate(lifespan.in());
46 // Create the Child POA
47 PortableServer::POA_var persistentPOA =
48 rootPOA->create_POA("persistentPOA", mgr.in(), policies);
50 // Policies are no longer needed
51 idassignment->destroy();
52 lifespan->destroy();
54 AdderServant servant;
56 // Create an id
57 PortableServer::ObjectId_var oid =
58 PortableServer::string_to_ObjectId("Adder");
60 // Activate the object (with id)
61 persistentPOA->activate_object_with_id(oid.in(), & servant);
63 CORBA::Object_var ref = persistentPOA->id_to_reference(oid.in());
64 CORBA::String_var iors = orb->object_to_string(ref.in());
66 CORBA::Object_var tobj = orb->resolve_initial_references("IORTable");
67 IORTable::Table_var table = IORTable::Table::_narrow(tobj.in());
68 table->bind("Adder", iors.in ());
70 orb->run();
71 } catch (...) {
72 ACE_ERROR ((LM_ERROR, "ERROR: Caught exception in server"));
73 return 1;
75 return 0;