TAO_ServantBase Class Reference

Base class for skeletons and servants. More...

#include <Servant_Base.h>

Inheritance diagram for TAO_ServantBase:

Inheritance graph
[legend]
Collaboration diagram for TAO_ServantBase:

Collaboration graph
[legend]
List of all members.

Public Member Functions

virtual ~TAO_ServantBase (void)
 Destructor.

virtual PortableServer::POA_ptr _default_POA ()
 Returns the default POA for this servant.

virtual CORBA::Boolean _is_a (const char *logical_type_id)
 Local implementation of the CORBA::Object::_is_a method.

virtual CORBA::Boolean _non_existent ()
 Default _non_existent: always returns false.

virtual CORBA::InterfaceDef_ptr _get_interface ()
 Query the Interface Repository for the interface definition.

virtual CORBA::Object_ptr _get_component ()
 Default _get_component: always returns CORBA::Object::_nil().

virtual char * _repository_id ()
 Get the repository id.

virtual TAO_Stub_create_stub ()
 This is an auxiliary method for _this() and _narrow().

virtual void _dispatch (TAO_ServerRequest &request, void *servant_upcall)=0
virtual int _find (const char *opname, TAO_Skeleton &skelfunc, const size_t length=0)
virtual int _find (const char *opname, TAO_Collocated_Skeleton &skelfunc, TAO::Collocation_Strategy st, const size_t length=0)
virtual const char * _interface_repository_id (void) const=0
 Get this interface's repository id (TAO specific).

Reference Counting Operations
virtual void _add_ref ()
 Increase reference count by one.

virtual void _remove_ref ()
virtual CORBA::ULong _refcount_value () const

Protected Member Functions

 TAO_ServantBase (void)
 Default constructor, only derived classes can be created.

 TAO_ServantBase (const TAO_ServantBase &)
 Copy constructor, protected so no instances can be created.

TAO_ServantBaseoperator= (const TAO_ServantBase &)
 Assignment operator.

virtual void synchronous_upcall_dispatch (TAO_ServerRequest &req, void *servant_upcall, void *derived_this)
virtual void asynchronous_upcall_dispatch (TAO_ServerRequest &req, void *servant_upcall, void *derived_this)

Protected Attributes

ACE_Atomic_Op< TAO_SYNCH_MUTEX,
long > 
ref_count_
 Reference counter.

TAO_Operation_Tableoptable_

Detailed Description

Base class for skeletons and servants.

The POA spec requires that all servants inherit from this class' base class.

An instance of a servant class derived from ServantBase initially has a reference count of one. Invoking _add_ref on the servant instance increases its reference count by one. Invoking _remove_ref on the servant instance decreases its reference count by one; if the resulting reference count equals zero, _remove_ref invokes delete on its this pointer in order to destroy the servant. For ORBs that operate in multi-threaded environments, the implementations of _add_ref and _remove_ref that the ServantBase class provides shall be thread-safe.

Like ServantBase supports copy construction and the default assignment operation. Copy construction always sets the reference count of the new servant instance to one. The default assignment implementation merely returns *this and does not affect the reference count.

Definition at line 60 of file Servant_Base.h.


Constructor & Destructor Documentation

TAO_ServantBase::~TAO_ServantBase void   )  [virtual]
 

Destructor.

Definition at line 72 of file Servant_Base.cpp.

00073 {
00074 }

TAO_BEGIN_VERSIONED_NAMESPACE_DECL TAO_ServantBase::TAO_ServantBase void   )  [protected]
 

Default constructor, only derived classes can be created.

Definition at line 51 of file Servant_Base.cpp.

00052   : TAO_Abstract_ServantBase ()
00053   , ref_count_ (1)
00054   , optable_ (0)
00055 {
00056 }

TAO_ServantBase::TAO_ServantBase const TAO_ServantBase  )  [protected]
 

Copy constructor, protected so no instances can be created.

Definition at line 58 of file Servant_Base.cpp.

00059   : TAO_Abstract_ServantBase ()
00060   , ref_count_ (1)
00061   , optable_ (rhs.optable_)
00062 {
00063 }


Member Function Documentation

void TAO_ServantBase::_add_ref  )  [virtual]
 

Increase reference count by one.

Implements TAO_Abstract_ServantBase.

Definition at line 341 of file Servant_Base.cpp.

Referenced by TAO_ServantBase_var::operator=(), and TAO_ServantBase_var::TAO_ServantBase_var().

00342 {
00343   ++this->ref_count_;
00344 }

TAO_Stub * TAO_ServantBase::_create_stub  )  [virtual]
 

This is an auxiliary method for _this() and _narrow().

Implements TAO_Abstract_ServantBase.

Reimplemented in TAO_Local_ServantBase.

Definition at line 154 of file Servant_Base.cpp.

References _default_POA(), TAO_Stub::_incr_refcnt(), _interface_repository_id(), ACE_CHECK_RETURN, ACE_ENV_ARG_PARAMETER, ACE_ENV_SINGLE_ARG_PARAMETER, TAO_TSS_Resources::instance(), TAO::Portable_Server::POA_Current_Impl::object_key(), TAO_ORB_Core::orb(), TAO_Stub::orb_core(), TAO::Portable_Server::POA_Current_Impl::orb_core(), TAO::Portable_Server::POA_Current_Impl::poa(), TAO_TSS_Resources::poa_current_impl_, PortableServer::POA_var, TAO::Portable_Server::POA_Current_Impl::priority(), TAO::Portable_Server::POA_Current_Impl::servant(), and TAO_Stub::servant_orb().

Referenced by POA_CORBA::Policy::_this().

00155 {
00156   TAO_Stub *stub = 0;
00157 
00158   TAO::Portable_Server::POA_Current_Impl *poa_current_impl =
00159     static_cast<TAO::Portable_Server::POA_Current_Impl *>
00160                     (TAO_TSS_Resources::instance ()->poa_current_impl_);
00161 
00162   CORBA::ORB_ptr servant_orb = 0;
00163 
00164   if (poa_current_impl != 0
00165       && this == poa_current_impl->servant ())
00166     {
00167       servant_orb = poa_current_impl->orb_core ().orb () ;
00168 
00169       stub =
00170         poa_current_impl->poa ()->key_to_stub (
00171             poa_current_impl->object_key (),
00172             this->_interface_repository_id (),
00173             poa_current_impl->priority ()
00174             ACE_ENV_ARG_PARAMETER
00175           );
00176       ACE_CHECK_RETURN (0);
00177     }
00178   else
00179     {
00180       PortableServer::POA_var poa =
00181         this->_default_POA (ACE_ENV_SINGLE_ARG_PARAMETER);
00182       ACE_CHECK_RETURN (0);
00183 
00184       CORBA::Object_var object =
00185         poa->servant_to_reference (this ACE_ENV_ARG_PARAMETER);
00186       ACE_CHECK_RETURN (0);
00187 
00188       // Get the stub object
00189       stub = object->_stubobj ();
00190 
00191       // Increment the reference count since <object> will zap its
00192       // stub object on deletion.
00193       stub->_incr_refcnt ();
00194 
00195       servant_orb = stub->orb_core ()->orb ();
00196     }
00197 
00198   stub->servant_orb (servant_orb);
00199   return stub;
00200 }

PortableServer::POA_ptr TAO_ServantBase::_default_POA  )  [virtual]
 

Returns the default POA for this servant.

Definition at line 77 of file Servant_Base.cpp.

References ACE_CHECK_RETURN, ACE_ENV_ARG_PARAMETER, ACE_ENV_SINGLE_ARG_PARAMETER, TAO_ORB_Core::root_poa(), and TAO_ORB_Core_instance().

Referenced by _create_stub().

00078 {
00079   CORBA::Object_var object =
00080     TAO_ORB_Core_instance ()->root_poa (ACE_ENV_SINGLE_ARG_PARAMETER);
00081   ACE_CHECK_RETURN (PortableServer::POA::_nil ());
00082 
00083   return PortableServer::POA::_narrow (object.in ()
00084                                        ACE_ENV_ARG_PARAMETER);
00085 }

virtual void TAO_ServantBase::_dispatch TAO_ServerRequest request,
void *  servant_upcall
[pure virtual]
 

Dispatches a request to the object: find the operation, cast the type to the most derived type, demarshall all the parameters from the request and finally invokes the operation, storing the results and out parameters (if any) or the exceptions thrown into request.

Implements TAO_Abstract_ServantBase.

Implemented in TAO_Local_ServantBase, and POA_CORBA::Policy.

int TAO_ServantBase::_find const char *  opname,
TAO_Collocated_Skeleton skelfunc,
TAO::Collocation_Strategy  st,
const size_t  length = 0
[virtual]
 

Implements TAO_Abstract_ServantBase.

Definition at line 144 of file Servant_Base.cpp.

References ACE_FUNCTION_TIMEPROBE, TAO_Operation_Table::find(), optable_, and TAO_Collocated_Skeleton.

00148 {
00149   ACE_FUNCTION_TIMEPROBE (TAO_SERVANT_BASE_FIND_START);
00150   return this->optable_->find (opname, skelfunc, st, length);
00151 }

int TAO_ServantBase::_find const char *  opname,
TAO_Skeleton skelfunc,
const size_t  length = 0
[virtual]
 

Please see documentation in tao/Abstract_Servant_Base.h for details.

Implements TAO_Abstract_ServantBase.

Definition at line 135 of file Servant_Base.cpp.

References ACE_FUNCTION_TIMEPROBE, TAO_Operation_Table::find(), optable_, and TAO_Skeleton.

Referenced by asynchronous_upcall_dispatch(), and synchronous_upcall_dispatch().

00138 {
00139   ACE_FUNCTION_TIMEPROBE (TAO_SERVANT_BASE_FIND_START);
00140   return this->optable_->find (opname, skelfunc, length);
00141 }

CORBA::Object_ptr TAO_ServantBase::_get_component  )  [virtual]
 

Default _get_component: always returns CORBA::Object::_nil().

Implements TAO_Abstract_ServantBase.

Definition at line 123 of file Servant_Base.cpp.

References CORBA::Object::_nil().

00124 {
00125   return CORBA::Object::_nil ();
00126 }

CORBA::InterfaceDef_ptr TAO_ServantBase::_get_interface  )  [virtual]
 

Query the Interface Repository for the interface definition.

Implements TAO_Abstract_ServantBase.

Definition at line 102 of file Servant_Base.cpp.

References ACE_ENV_ARG_PARAMETER, ACE_THROW_RETURN, TAO_IFR_Client_Adapter::get_interface(), ACE_Dynamic_Service< TYPE >::instance(), and TAO_ORB_Core_instance().

Referenced by POA_CORBA::Policy::_interface_skel().

00103 {
00104   TAO_IFR_Client_Adapter *adapter =
00105     ACE_Dynamic_Service<TAO_IFR_Client_Adapter>::instance (
00106         TAO_ORB_Core::ifr_client_adapter_name ()
00107       );
00108 
00109   if (adapter == 0)
00110     {
00111       ACE_THROW_RETURN (CORBA::INTF_REPOS (),
00112                         0);
00113     }
00114 
00115   // This doesn't take multiple ORBs into account, but it's being
00116   // used only to resolve the IFR, so we should be ok.
00117   return adapter->get_interface (TAO_ORB_Core_instance ()->orb (),
00118                                  this->_interface_repository_id ()
00119                                  ACE_ENV_ARG_PARAMETER);
00120 }

virtual const char* TAO_ServantBase::_interface_repository_id void   )  const [pure virtual]
 

Get this interface's repository id (TAO specific).

Implements TAO_Abstract_ServantBase.

Implemented in POA_CORBA::Policy.

Referenced by _create_stub().

CORBA::Boolean TAO_ServantBase::_is_a const char *  logical_type_id  )  [virtual]
 

Local implementation of the CORBA::Object::_is_a method.

Implements TAO_Abstract_ServantBase.

Reimplemented in POA_CORBA::Policy.

Definition at line 88 of file Servant_Base.cpp.

References ACE_OS::strcmp().

00090 {
00091   static char const id[] = "IDL:omg.org/CORBA/Object:1.0";
00092   return ACE_OS::strcmp (logical_type_id, id) == 0;
00093 }

CORBA::Boolean TAO_ServantBase::_non_existent  )  [virtual]
 

Default _non_existent: always returns false.

Implements TAO_Abstract_ServantBase.

Definition at line 96 of file Servant_Base.cpp.

00097 {
00098   return false;
00099 }

CORBA::ULong TAO_ServantBase::_refcount_value  )  const [virtual]
 

Returns the current reference count value.

Implements TAO_Abstract_ServantBase.

Definition at line 356 of file Servant_Base.cpp.

References ACE_Atomic_Op< TAO_SYNCH_MUTEX, long >::value().

00357 {
00358   return static_cast<CORBA::ULong> (this->ref_count_.value ());
00359 }

void TAO_ServantBase::_remove_ref  )  [virtual]
 

Decreases reference count by one; if the resulting reference count equals zero, _remove_ref invokes delete on its this pointer in order to destroy the servant.

Implements TAO_Abstract_ServantBase.

Definition at line 347 of file Servant_Base.cpp.

Referenced by TAO_ServantBase_var::operator=(), TAO_ServantBase_var::out(), and TAO_ServantBase_var::~TAO_ServantBase_var().

00348 {
00349   long const new_count = --this->ref_count_;
00350 
00351   if (new_count == 0)
00352     delete this;
00353 }

char * TAO_ServantBase::_repository_id  )  [virtual]
 

Get the repository id.

Implements TAO_Abstract_ServantBase.

Definition at line 129 of file Servant_Base.cpp.

References CORBA::string_dup().

00130 {
00131   return CORBA::string_dup (this->_interface_repository_id ());
00132 }

void TAO_ServantBase::asynchronous_upcall_dispatch TAO_ServerRequest req,
void *  servant_upcall,
void *  derived_this
[protected, virtual]
 

Definition at line 282 of file Servant_Base.cpp.

References _find(), ACE_ANY_EXCEPTION, ACE_CATCHANY, ACE_CHECK, ACE_ENDTRY, ACE_ENV_ARG_PARAMETER, ACE_THROW, ACE_TRY, ACE_TRY_CHECK, TAO_ServerRequest::operation(), TAO_ServerRequest::operation_length(), TAO_ServerRequest::send_no_exception_reply(), TAO_ServerRequest::sync_with_server(), TAO_ServerRequest::tao_send_reply_exception(), and TAO_Skeleton.

00286 {
00287   TAO_Skeleton skel;
00288   const char *opname = req.operation ();
00289 
00290   // It seems that I might have missed s/g here.  What if
00291   // it is a one way that is SYNC_WITH_SERVER.
00292   // Add the following line to handle this reply send as well.
00293 
00294   // Handle the one ways that are SYNC_WITH_SERVER
00295   if (req.sync_with_server ())
00296     {
00297       req.send_no_exception_reply ();
00298     }
00299 
00300   // Fetch the skeleton for this operation
00301   if (this->_find (opname,
00302                    skel,
00303                    static_cast <unsigned int> (req.operation_length())) == -1)
00304     {
00305       ACE_THROW (CORBA::BAD_OPERATION ());
00306     }
00307 
00308   ACE_TRY
00309     {
00310       // Invoke the skeleton, it will demarshal the arguments, invoke
00311       // the right operation on the skeleton class, and marshal any
00312       // results.  De/marshaling will only occur in the uncollocated
00313       // case.
00314       skel (req,
00315             servant_upcall,
00316             derived_this
00317             ACE_ENV_ARG_PARAMETER);
00318       ACE_TRY_CHECK;
00319 
00320       // It is our job to send the already marshaled reply, but only
00321       // send if it is expected and it has not already been sent
00322 
00323       // Return immediately. Do not send a reply; this is an
00324       // asynchronous upcall. (unless, of course there is a system
00325       // exception.
00326 
00327     }
00328   ACE_CATCHANY
00329     {
00330       // If an exception was raised we should marshal it and send
00331       // the appropriate reply to the client
00332       req.tao_send_reply_exception (ACE_ANY_EXCEPTION);
00333     }
00334   ACE_ENDTRY;
00335   ACE_CHECK;
00336 
00337   return;
00338 }

TAO_ServantBase & TAO_ServantBase::operator= const TAO_ServantBase  )  [protected]
 

Assignment operator.

Definition at line 66 of file Servant_Base.cpp.

References optable_.

00067 {
00068   this->optable_ = rhs.optable_;
00069   return *this;
00070 }

void TAO_ServantBase::synchronous_upcall_dispatch TAO_ServerRequest req,
void *  servant_upcall,
void *  derived_this
[protected, virtual]
 

Implements TAO_Abstract_ServantBase.

Definition at line 202 of file Servant_Base.cpp.

References _find(), ACE_ANY_EXCEPTION, ACE_CATCHANY, ACE_CHECK, ACE_ENDTRY, ACE_ENV_ARG_PARAMETER, ACE_RE_THROW, ACE_THROW, ACE_TRY, ACE_TRY_CHECK, TAO_ServerRequest::collocated(), TAO_ServerRequest::deferred_reply(), TAO_ServerRequest::operation(), TAO_ServerRequest::operation_length(), TAO_ServerRequest::response_expected(), TAO_ServerRequest::send_no_exception_reply(), TAO_ServerRequest::sync_with_server(), TAO_ServerRequest::tao_send_reply(), TAO_ServerRequest::tao_send_reply_exception(), and TAO_Skeleton.

Referenced by POA_CORBA::Policy::_dispatch().

00206 {
00207   TAO_Skeleton skel;
00208   char const * const opname = req.operation ();
00209 
00210   // It seems that I might have missed s/g here.  What if
00211   // it is a one way that is SYNC_WITH_SERVER.
00212   // Add the following line to handle this reply send as well.
00213 
00214   // Handle the one ways that are SYNC_WITH_SERVER and not collocated
00215   if (req.sync_with_server () && !req.collocated ())
00216     {
00217       req.send_no_exception_reply ();
00218     }
00219 
00220   // Fetch the skeleton for this operation
00221   if (this->_find (opname,
00222                    skel,
00223                    static_cast <unsigned int> (req.operation_length())) == -1)
00224     {
00225       ACE_THROW (CORBA::BAD_OPERATION ());
00226     }
00227 
00228   CORBA::Boolean const send_reply =
00229     !req.sync_with_server ()
00230     && req.response_expected ()
00231     && !req.deferred_reply ();
00232 
00233   ACE_TRY
00234     {
00235       // Invoke the skeleton, it will demarshal the arguments, invoke
00236       // the right operation on the skeleton class, and marshal any
00237       // results.  De/marshaling will only occur in the uncollocated
00238       // case.
00239       skel (req,
00240             servant_upcall,
00241             derived_this
00242             ACE_ENV_ARG_PARAMETER);
00243       ACE_TRY_CHECK;
00244 
00245       /*
00246        * Dispatch resolution specialization add hook.
00247        * Over-ridden with code to handle optimized dispatch.
00248        */
00249       //@@ TAO_DISPATCH_RESOLUTION_OPT_ADD_HOOK
00250 
00251       // It is our job to send the already marshaled reply, but only
00252       // send if it is expected and it has not already been sent
00253 
00254       // We send the reply only if it is NOT a SYNC_WITH_SERVER, a
00255       // response is expected and if the reply is not deferred.
00256       if (send_reply)
00257         {
00258           req.tao_send_reply ();
00259         }
00260     }
00261   ACE_CATCHANY
00262     {
00263       // If an exception was raised we should marshal it and send
00264       // the appropriate reply to the client
00265       if (send_reply)
00266         {
00267           if (req.collocated ())
00268             {
00269               // Report the exception to the collocated client.
00270               ACE_RE_THROW;
00271             }
00272           else
00273             req.tao_send_reply_exception (ACE_ANY_EXCEPTION);
00274         }
00275     }
00276   ACE_ENDTRY;
00277   ACE_CHECK;
00278 
00279   return;
00280 }


Member Data Documentation

TAO_Operation_Table* TAO_ServantBase::optable_ [protected]
 

The operation table for this servant. It is initialized by the most derived class.

Definition at line 172 of file Servant_Base.h.

Referenced by _find(), and operator=().

ACE_Atomic_Op<TAO_SYNCH_MUTEX, long> TAO_ServantBase::ref_count_ [protected]
 

Reference counter.

Definition at line 168 of file Servant_Base.h.


The documentation for this class was generated from the following files:
Generated on Thu Nov 9 12:46:11 2006 for TAO_PortableServer by doxygen 1.3.6