Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / POA / Loader / Servant_Activator.cpp
blob09279156ab7ea79cd95914e31a617dab2a28206e
2 //=============================================================================
3 /**
4 * @file Servant_Activator.cpp
6 * Implementation of <ServantActivator>, which is used by a POA
7 * with a RETAIN policy.
9 * @author Kirthika Parameswaran <kirthika@cs.wustl.edu>
11 //=============================================================================
14 #include "Servant_Activator.h"
15 #include "ace/OS_NS_string.h"
17 // Initialization.The dllname is used by the Loactor to load it into
18 // memory. The factory function is the point of entry into the dll and
19 // is used for obtaining the servant. The garbage_collection_function
20 // is used to kill the servant.
22 ServantActivator::ServantActivator (CORBA::ORB_ptr orb,
23 const ACE_TCHAR *dllname,
24 const ACE_TCHAR *factory_function,
25 const ACE_TCHAR *garbage_collection_function)
26 : orb_ (CORBA::ORB::_duplicate (orb))
28 // The dll is opened using the dllname passed.
29 if (this->dll_.open (dllname) == -1)
30 ACE_ERROR ((LM_ERROR,
31 "%p\n",
32 this->dll_.error ()));
34 // Obtain the symbol for the function that will get the servant
35 // object.
37 // Cannot go from void* to function pointer directly. Cast the void*
38 // to long first.
39 void *symbol = this->dll_.symbol (factory_function);
40 intptr_t function = reinterpret_cast<intptr_t> (symbol);
42 servant_supplier_ =
43 reinterpret_cast<SERVANT_FACTORY> (function);
45 // Obtain the symbol for the function which will destroy the
46 // servant.
47 symbol = this->dll_.symbol (garbage_collection_function);
48 function = reinterpret_cast<intptr_t> (symbol);
49 servant_garbage_collector_ =
50 reinterpret_cast<SERVANT_GARBAGE_COLLECTOR> (function);
53 // This method associates an servant with the ObjectID.
55 PortableServer::Servant
56 ServantActivator::incarnate (const PortableServer::ObjectId &oid,
57 PortableServer::POA_ptr poa)
59 // Obtain the servant else exception.
60 PortableServer::Servant servant =
61 (*servant_supplier_) (oid,
62 poa,
63 this->orb_.in ());
64 if (servant != 0)
65 return servant;
66 else
67 throw CORBA::OBJECT_NOT_EXIST ();
70 // This is the method invoked when the object is deactivated or the
71 // entire POA is is deactivated or destroyed.
73 void
74 ServantActivator::etherealize (const PortableServer::ObjectId &oid,
75 PortableServer::POA_ptr poa,
76 PortableServer::Servant servant,
77 CORBA::Boolean,
78 CORBA::Boolean remaining_activations)
80 // If there are no remaining activations i.e ObjectIds associated
81 // with test servant, deactivate it by calling the
82 // garbage_collection_function. Etheralization happens on
83 // POA::destroy() and/or Object::deactivate().
85 if (remaining_activations == 0)
86 (*servant_garbage_collector_) (oid,
87 poa,
88 servant);