Update bug_report.md
[ACE_TAO.git] / TAO / tests / POA / On_Demand_Activation / Servant_Locator.cpp
blob824161368a620e802e4e8d74f5dcc89e5f7c03ad
2 //=============================================================================
3 /**
4 * @file Servant_Locator.cpp
6 * Implementation of ServantLocator class , used with a POA
7 * having a NON_RETAIN policy.
9 * @author Irfan Pyarali
11 //=============================================================================
14 #include "Servant_Locator.h"
15 #include "test_i.h"
16 #include "ace/OS_NS_string.h"
18 ServantLocator::ServantLocator (CORBA::ORB_ptr orb)
19 : orb_ (CORBA::ORB::_duplicate (orb))
24 PortableServer::Servant
25 ServantLocator::preinvoke (const PortableServer::ObjectId &oid,
26 PortableServer::POA_ptr poa,
27 const char * /* operation */,
28 PortableServer::ServantLocator::Cookie &cookie)
30 // Convert ObjectID to String.
32 CORBA::String_var s = PortableServer::ObjectId_to_string (oid);
33 // If ObjectID string has a test substring, create and return a
34 // test_i.
36 if (ACE_OS::strstr (s.in (), "test") != 0)
38 PortableServer::Servant servant =
39 new test_i (this->orb_.in (), poa);
41 // Return the servant as the cookie , used as a check when
42 // postinvoke is called on this ServantLocator.
44 cookie = servant;
45 return servant;
47 else
49 throw CORBA::OBJECT_NOT_EXIST ();
53 void
54 ServantLocator::postinvoke (const PortableServer::ObjectId & /* oid */,
55 PortableServer::POA_ptr /* poa */,
56 const char * /* operation */,
57 PortableServer::ServantLocator::Cookie cookie,
58 PortableServer::Servant servant)
60 // Check the passed servant with the cookie.
62 PortableServer::Servant my_servant = (PortableServer::Servant) cookie;
63 ACE_ASSERT (servant == my_servant);
64 delete servant;
66 // To avoid warning about unused variable with ACE_NDEBUG.
67 ACE_UNUSED_ARG (my_servant);