2 //=============================================================================
4 * @file Etherealization.cpp
6 * This program tests for deactivation and etherealization of
7 * reference counted and non reference counted servants.
9 * @author Irfan Pyarali
11 //=============================================================================
15 #include "ace/OS_NS_string.h"
16 #include "tao/PortableServer/ServantActivatorC.h"
18 class test_i
: public POA_test
27 ACE_DEBUG ((LM_DEBUG
, "~test_i called\n"));
31 class test_i_with_reference_counting
:
32 public virtual POA_test
39 ~test_i_with_reference_counting ()
41 ACE_DEBUG ((LM_DEBUG
, "~test_i_with_reference_counting called\n"));
45 class Servant_Activator
: public PortableServer::ServantActivator
48 PortableServer::Servant
incarnate (const PortableServer::ObjectId
&oid
,
49 PortableServer::POA_ptr poa
);
51 void etherealize (const PortableServer::ObjectId
&oid
,
52 PortableServer::POA_ptr adapter
,
53 PortableServer::Servant servant
,
54 CORBA::Boolean cleanup_in_progress
,
55 CORBA::Boolean remaining_activations
);
58 PortableServer::Servant
59 Servant_Activator::incarnate (const PortableServer::ObjectId
&id
,
60 PortableServer::POA_ptr
)
62 CORBA::String_var object_name
=
63 PortableServer::ObjectId_to_string (id
);
66 "\nIncarnate called with id = \"%C\"\n",
69 if (ACE_OS::strcmp (object_name
.in (),
70 "without reference counting") == 0)
73 return new test_i_with_reference_counting
;
78 Servant_Activator::etherealize (const PortableServer::ObjectId
&id
,
79 PortableServer::POA_ptr
,
80 PortableServer::Servant servant
,
84 CORBA::String_var object_name
=
85 PortableServer::ObjectId_to_string (id
);
88 "Etherealize called with id = \"%C\"\n",
91 if (ACE_OS::strcmp (object_name
.in (),
92 "without reference counting") == 0)
96 servant
->_remove_ref ();
101 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
105 // Initialize the ORB first.
106 CORBA::ORB_var orb
= CORBA::ORB_init (argc
, argv
);
108 // Obtain the RootPOA.
109 CORBA::Object_var object
=
110 orb
->resolve_initial_references ("RootPOA");
112 // Get the POA_var object from Object_var.
113 PortableServer::POA_var root_poa
=
114 PortableServer::POA::_narrow (object
.in ());
116 // Get the POAManager of the RootPOA.
117 PortableServer::POAManager_var poa_manager
=
118 root_poa
->the_POAManager ();
120 CORBA::PolicyList
policies (3);
123 // ID Assignment Policy
125 root_poa
->create_id_assignment_policy (PortableServer::USER_ID
);
129 root_poa
->create_lifespan_policy (PortableServer::PERSISTENT
);
131 // Request Processing Policy
133 root_poa
->create_request_processing_policy (PortableServer::USE_SERVANT_MANAGER
);
135 PortableServer::POA_var child_poa
=
136 root_poa
->create_POA ("child",
140 poa_manager
->activate ();
142 // Create servant activator.
143 Servant_Activator servant_manager
;
145 // Set servant_activator as the servant_manager of child POA.
146 child_poa
->set_servant_manager (&servant_manager
);
149 // Create a reference with user created ID in child POA which
150 // uses the Servant_Activator.
151 PortableServer::ObjectId_var id
=
152 PortableServer::string_to_ObjectId ("without reference counting");
155 child_poa
->create_reference_with_id (id
.in (),
159 test::_narrow (object
.in ());
163 child_poa
->deactivate_object (id
.in ());
167 // Create a reference with user created ID in child POA which
168 // uses the Servant_Activator.
169 PortableServer::ObjectId_var id
=
170 PortableServer::string_to_ObjectId ("with reference counting");
173 child_poa
->create_reference_with_id (id
.in (),
177 test::_narrow (object
.in ());
181 child_poa
->deactivate_object (id
.in ());
185 // Create a reference with user created ID in child POA which
186 // uses the Servant_Activator.
187 PortableServer::ObjectId_var id
=
188 PortableServer::string_to_ObjectId ("no call made");
191 child_poa
->create_reference_with_id (id
.in (),
194 child_poa
->deactivate_object (id
.in ());
198 // Create a reference with user created ID in child POA which
199 // uses the Servant_Activator but just don't call the reference at all
200 PortableServer::ObjectId_var id
=
201 PortableServer::string_to_ObjectId ("no call");
204 child_poa
->create_reference_with_id (id
.in (),
207 PortableServer::ObjectId_var oid
=
208 child_poa
->reference_to_id (object
.in ());
210 child_poa
->deactivate_object (oid
.in ());
213 ACE_DEBUG ((LM_DEBUG
,
214 "\nEnd of main()\n\n"));
218 catch (const CORBA::Exception
& ex
)
220 ex
._tao_print_exception ("Exception caught");