Merge pull request #2222 from jwillemsen/jwi-dllexportwarning
[ACE_TAO.git] / TAO / tests / POA / On_Demand_Loading / Servant_Locator.cpp
blobaad9ca32bfd465c80ddde0e70d46a4ef3ad35c8c
2 //=============================================================================
3 /**
4 * @file Servant_Locator.cpp
6 * Implementation of ServantLocator_i class, used with a POA
7 * having a NON_RETAIN policy.
9 * @author Kirthika Parameswaran <kirthika@cs.wustl.edu>
11 //=============================================================================
14 #include "Servant_Locator.h"
16 // Initialization.
18 ServantLocator_i::ServantLocator_i (CORBA::ORB_ptr orb)
19 : servant_manager_ (orb)
23 // This method associates an servant with the ObjectID.
25 PortableServer::Servant
26 ServantLocator_i::preinvoke (const PortableServer::ObjectId &oid,
27 PortableServer::POA_ptr poa,
28 const char * /* operation */,
29 PortableServer::ServantLocator::Cookie &cookie)
31 // Convert ObjectID to String.
33 CORBA::String_var s =
34 PortableServer::ObjectId_to_string (oid);
36 // If ObjectID string has a test substring create and return a
37 // test_i.
39 PortableServer::Servant servant =
40 this->servant_manager_.obtain_servant (ACE_TEXT_CHAR_TO_TCHAR(s.in ()),
41 poa);
42 if (servant != 0)
44 // Return the servant as the cookie , used as a check when
45 // postinvoke is called on this ServantLocator_i.
47 cookie = servant;
48 return servant;
50 else
51 throw CORBA::OBJECT_NOT_EXIST ();
54 // Since the servant gets invoked per operation, the servant has to be
55 // destroyed per operation too. This is accomplished in the
56 // postinvoke method.
58 void
59 ServantLocator_i::postinvoke (const PortableServer::ObjectId &oid,
60 PortableServer::POA_ptr /* poa */,
61 const char * /* operation */,
62 PortableServer::ServantLocator::Cookie cookie,
63 PortableServer::Servant servant)
65 // Check the passed servant with the cookie.
67 PortableServer::Servant my_servant =
68 reinterpret_cast<PortableServer::Servant> (cookie);
70 ACE_ASSERT (servant == my_servant);
72 this->servant_manager_.destroy_servant (servant,
73 oid);
74 // To avoid warning about unused variable with ACE_NDEBUG.
75 ACE_UNUSED_ARG (my_servant);
78 // This method returns an ObjectId when given an dll name and the
79 // factory function to be invoked in the dll. The format of the
80 // ObjectId is libname:factory_function.
82 PortableServer::ObjectId_var
83 ServantLocator_i::create_dll_object_id (const char *dllname,
84 const char *factory_function)
86 return this->servant_manager_.create_dll_object_id (dllname,
87 factory_function);