2 //=============================================================================
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"
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
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.
49 throw CORBA::OBJECT_NOT_EXIST ();
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
);
66 // To avoid warning about unused variable with ACE_NDEBUG.
67 ACE_UNUSED_ARG (my_servant
);