Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / POA / Bug_2511_Regression / server.cpp
blob40efbd8d9b249988f6acc93f2ea23538f3a43ecf
2 //=============================================================================
3 /**
4 * @file server.cpp
6 * This program tests that multiple calls to the Servant Locator
7 * can take place simultaneously.
9 * @author Irfan Pyarali
11 //=============================================================================
14 #include "testS.h"
15 #include "tao/PortableServer/ServantLocatorC.h"
16 #include "tao/CDR.h"
18 int postCount = 0;
19 int errorCount = 0;
21 class test_i :
22 public virtual POA_test
24 public:
25 test_i (PortableServer::POA_ptr poa);
27 void normal ();
29 void exceptional ();
31 void notexisting ();
33 PortableServer::POA_var poa_;
36 test_i::test_i (PortableServer::POA_ptr poa)
37 : poa_ (PortableServer::POA::_duplicate (poa))
41 void
42 test_i::normal ()
44 ACE_DEBUG ((LM_DEBUG, "executing normal\n"));
47 void
48 test_i::exceptional ()
50 ACE_DEBUG ((LM_DEBUG, "executing exceptional\n"));
53 void
54 test_i::notexisting ()
56 ACE_DEBUG ((LM_DEBUG, "executing notexisting\n"));
59 class Servant_Locator :
60 public PortableServer::ServantLocator
62 public:
63 Servant_Locator (PortableServer::POA_ptr poa);
65 ::PortableServer::Servant preinvoke (const PortableServer::ObjectId &,
66 PortableServer::POA_ptr,
67 const char *,
68 PortableServer::ServantLocator::Cookie &);
70 void postinvoke (const PortableServer::ObjectId &,
71 PortableServer::POA_ptr,
72 const char *,
73 PortableServer::ServantLocator::Cookie,
74 PortableServer::Servant);
76 test_i servant_;
79 Servant_Locator::Servant_Locator (PortableServer::POA_ptr poa)
80 : servant_ (poa)
84 ::PortableServer::Servant
85 Servant_Locator::preinvoke (const PortableServer::ObjectId &oid,
86 PortableServer::POA_ptr,
87 const char *op,
88 PortableServer::ServantLocator::Cookie &)
90 CORBA::String_var name =
91 PortableServer::ObjectId_to_string (oid);
93 ACE_DEBUG ((LM_DEBUG,
94 "Servant_Locator::preinvoke for %C.%C ",
95 name.in (), op ));
97 if (ACE_OS::strcmp (op, "normal") == 0)
99 ACE_DEBUG ((LM_DEBUG, "returning servant\n"));
100 return &this->servant_;
102 else if (ACE_OS::strcmp (op, "exceptional") == 0)
104 ACE_DEBUG ((LM_DEBUG, "throwing exception\n"));
105 throw CORBA::INTERNAL();
107 else
109 ACE_DEBUG ((LM_DEBUG, "returning NULL\n"));
110 return 0;
114 void
115 Servant_Locator::postinvoke (const PortableServer::ObjectId &oid,
116 PortableServer::POA_ptr,
117 const char *op,
118 PortableServer::ServantLocator::Cookie,
119 PortableServer::Servant)
121 ++postCount;
122 CORBA::String_var name =
123 PortableServer::ObjectId_to_string (oid);
125 if (!op)
127 op = "NULL";
128 ++errorCount;
131 ACE_DEBUG ((LM_DEBUG,
132 "Servant_Locator::postinvoke for %C.%C\n",
133 name.in (), op ));
137 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
141 CORBA::ORB_var orb =
142 CORBA::ORB_init (argc, argv);
144 CORBA::Object_var obj =
145 orb->resolve_initial_references ("RootPOA");
147 PortableServer::POA_var root_poa =
148 PortableServer::POA::_narrow (obj.in ());
150 PortableServer::POAManager_var poa_manager =
151 root_poa->the_POAManager ();
153 poa_manager->activate ();
155 CORBA::PolicyList policies;
156 CORBA::ULong current_length = 0;
158 policies.length (current_length + 1);
159 policies[current_length++] =
160 root_poa->create_request_processing_policy (PortableServer::USE_SERVANT_MANAGER);
162 policies.length (current_length + 1);
163 policies[current_length++] =
164 root_poa->create_servant_retention_policy (PortableServer::NON_RETAIN);
166 policies.length (current_length + 1);
167 policies[current_length++] =
168 root_poa->create_id_assignment_policy (PortableServer::USER_ID);
170 PortableServer::POA_var child_poa =
171 root_poa->create_POA ("child",
172 poa_manager.in (),
173 policies);
175 Servant_Locator servant_locator (child_poa.in ());
176 child_poa->set_servant_manager (&servant_locator);
178 PortableServer::ObjectId_var objectID =
179 PortableServer::string_to_ObjectId ("object");
181 CORBA::Object_var objectREF =
182 child_poa->create_reference_with_id (objectID.in (),
183 "IDL:test:1.0");
185 test_var testObject =
186 test::_narrow (objectREF.in ());
188 testObject->normal();
190 bool caught = false;
193 testObject->exceptional();
195 catch (const CORBA::Exception&)
197 ACE_DEBUG ((LM_DEBUG, "exceptional() yielded exception\n"));
198 caught = true;
200 if (!caught) ++errorCount;
202 caught = false;
205 testObject->notexisting();
207 catch (const CORBA::Exception&)
209 ACE_DEBUG ((LM_DEBUG, "notexisting() yielded exception\n"));
210 caught = true;
212 if (!caught) ++errorCount;
214 orb->destroy ();
216 catch (const CORBA::Exception& ex)
218 ex._tao_print_exception ("Exception caught");
219 ++errorCount;
222 if (!errorCount)
224 ACE_DEBUG ((LM_DEBUG,"test successful\n"));
226 else
228 ACE_DEBUG ((LM_DEBUG,"unsuccessfull: %d errors\n", errorCount ));
231 return errorCount;