Merge pull request #2222 from jwillemsen/jwi-dllexportwarning
[ACE_TAO.git] / TAO / tests / POA / Etherealization / Etherealization.cpp
blobf1a9f39901edb21864c5febb400a7fd3872c8295
2 //=============================================================================
3 /**
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 //=============================================================================
14 #include "testS.h"
15 #include "ace/OS_NS_string.h"
16 #include "tao/PortableServer/ServantActivatorC.h"
18 class test_i : public POA_test
20 public:
21 void method ()
25 ~test_i ()
27 ACE_DEBUG ((LM_DEBUG, "~test_i called\n"));
31 class test_i_with_reference_counting :
32 public virtual POA_test
34 public:
35 void method ()
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
47 public:
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);
65 ACE_DEBUG ((LM_DEBUG,
66 "\nIncarnate called with id = \"%C\"\n",
67 object_name.in ()));
69 if (ACE_OS::strcmp (object_name.in (),
70 "without reference counting") == 0)
71 return new test_i;
72 else
73 return new test_i_with_reference_counting;
77 void
78 Servant_Activator::etherealize (const PortableServer::ObjectId &id,
79 PortableServer::POA_ptr ,
80 PortableServer::Servant servant,
81 CORBA::Boolean,
82 CORBA::Boolean)
84 CORBA::String_var object_name =
85 PortableServer::ObjectId_to_string (id);
87 ACE_DEBUG ((LM_DEBUG,
88 "Etherealize called with id = \"%C\"\n",
89 object_name.in ()));
91 if (ACE_OS::strcmp (object_name.in (),
92 "without reference counting") == 0)
93 delete servant;
94 else
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);
121 policies.length (3);
123 // ID Assignment Policy
124 policies[0] =
125 root_poa->create_id_assignment_policy (PortableServer::USER_ID);
127 // Lifespan Policy
128 policies[1] =
129 root_poa->create_lifespan_policy (PortableServer::PERSISTENT);
131 // Request Processing Policy
132 policies[2] =
133 root_poa->create_request_processing_policy (PortableServer::USE_SERVANT_MANAGER);
135 PortableServer::POA_var child_poa =
136 root_poa->create_POA ("child",
137 poa_manager.in (),
138 policies);
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");
154 object =
155 child_poa->create_reference_with_id (id.in (),
156 "IDL:test:1.0");
158 test_var test =
159 test::_narrow (object.in ());
161 test->method ();
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");
172 object =
173 child_poa->create_reference_with_id (id.in (),
174 "IDL:test:1.0");
176 test_var test =
177 test::_narrow (object.in ());
179 test->method ();
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");
190 object =
191 child_poa->create_reference_with_id (id.in (),
192 "IDL:test:1.0");
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");
203 object =
204 child_poa->create_reference_with_id (id.in (),
205 "IDL:test:1.0");
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"));
216 orb->destroy ();
218 catch (const CORBA::Exception& ex)
220 ex._tao_print_exception ("Exception caught");
221 return -1;
224 return 0;