Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / POA / Non_Servant_Upcalls / Non_Servant_Upcalls.cpp
blob3e8eb1812819a984f4d6f2fe6f40c720838e3835
2 //=============================================================================
3 /**
4 * @file Non_Servant_Upcalls.cpp
6 * This program tests the users ability to make calls on a POA
7 * during non-servant upcalls. In this example, a servant which
8 * is being destroyed during because of a deactivate_object()
9 * call, tries to deactivate another object in its destructor.
11 * @author Irfan Pyarali
13 //=============================================================================
16 #include "testS.h"
18 class test_i :
19 public virtual POA_test
21 public:
22 test_i (test_i *other);
24 ~test_i ();
26 test_i *other_;
29 test_i::test_i (test_i *other)
30 : other_ (other)
34 test_i::~test_i ()
36 ACE_DEBUG ((LM_DEBUG, "(%t) test_i::~test_i\n"));
38 if (this->other_)
40 try
42 PortableServer::POA_var poa = this->_default_POA ();
44 PortableServer::ObjectId_var id = poa->servant_to_id (this->other_);
46 ACE_DEBUG ((LM_DEBUG, "(%t) Deactivating other servant\n"));
48 poa->deactivate_object (id.in ());
50 catch (const CORBA::Exception& ex)
52 ex._tao_print_exception ("test_i::~test_i");
57 int
58 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
60 try
62 // Initialize the ORB first.
63 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
65 // Obtain the RootPOA.
66 CORBA::Object_var obj =
67 orb->resolve_initial_references ("RootPOA");
69 // Get the POA_var object from Object_var.
70 PortableServer::POA_var root_poa =
71 PortableServer::POA::_narrow (obj.in ());
73 // Get the POAManager of the RootPOA.
74 PortableServer::POAManager_var poa_manager =
75 root_poa->the_POAManager ();
77 poa_manager->activate ();
79 test_i *servant1 = new test_i (0);
80 test_i *servant2 = new test_i (servant1);
82 PortableServer::ObjectId_var id1 =
83 root_poa->activate_object (servant1);
85 // Give ownership to POA.
86 servant1->_remove_ref ();
88 PortableServer::ObjectId_var id2 =
89 root_poa->activate_object (servant2);
91 // Give ownership to POA.
92 servant2->_remove_ref ();
94 root_poa->deactivate_object (id2.in ());
96 root_poa->destroy (true, true);
98 orb->destroy ();
100 catch (const CORBA::Exception& ex)
102 ex._tao_print_exception ("Exception caught");
103 return -1;
106 return 0;