Servant_Base.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    Servant_Base.h
00006  *
00007  *  $Id: Servant_Base.h 79124 2007-07-31 12:39:37Z johnnyw $
00008  *
00009  *  @author  Irfan Pyarali <irfan@cs.wustl.edu>
00010  */
00011 //=============================================================================
00012 
00013 #ifndef TAO_SERVANT_BASE_H
00014 #define TAO_SERVANT_BASE_H
00015 
00016 #include /**/ "ace/pre.h"
00017 
00018 #include "tao/PortableServer/portableserver_export.h"
00019 
00020 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00021 # pragma once
00022 #endif /* ACE_LACKS_PRAGMA_ONCE */
00023 
00024 #include "tao/PortableServer/PS_ForwardC.h"
00025 #include "tao/PortableServer/Servant_var.h"
00026 #include "tao/Abstract_Servant_Base.h"
00027 #include "ace/Atomic_Op.h"
00028 
00029 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00030 
00031 class TAO_Operation_Table;
00032 
00033 /**
00034  * @class TAO_ServantBase
00035  *
00036  * @brief Base class for skeletons and servants.
00037  *
00038  * The POA spec requires that all servants inherit from this class'
00039  * base class.
00040  *
00041  * An instance of a servant class derived from
00042  * ServantBase initially has a reference count of
00043  * one. Invoking _add_ref on the servant instance increases its
00044  * reference count by one. Invoking _remove_ref on the servant
00045  * instance decreases its reference count by one; if the
00046  * resulting reference count equals zero, _remove_ref invokes
00047  * delete on its this pointer in order to destroy the
00048  * servant. For ORBs that operate in multi-threaded
00049  * environments, the implementations of _add_ref and _remove_ref
00050  * that the ServantBase class provides shall be
00051  * thread-safe.
00052  *
00053  * Like ServantBase supports copy
00054  * construction and the default assignment operation. Copy
00055  * construction always sets the reference count of the new
00056  * servant instance to one. The default assignment
00057  * implementation merely returns *this and does not affect the
00058  * reference count.
00059  *
00060  */
00061 class TAO_PortableServer_Export TAO_ServantBase
00062   : public virtual TAO_Abstract_ServantBase
00063 {
00064 public:
00065 
00066   /// Destructor.
00067   virtual ~TAO_ServantBase (void);
00068 
00069   /// Returns the default POA for this servant.
00070   virtual PortableServer::POA_ptr _default_POA (void);
00071 
00072   /// Local implementation of the CORBA::Object::_is_a method.
00073   virtual CORBA::Boolean _is_a (const char *logical_type_id);
00074 
00075   /// Default _non_existent: always returns false.
00076   virtual CORBA::Boolean _non_existent (void);
00077 
00078   /// Query the Interface Repository for the interface definition.
00079   virtual CORBA::InterfaceDef_ptr _get_interface (void);
00080 
00081   /// Default _get_component: always returns CORBA::Object::_nil().
00082   virtual CORBA::Object_ptr _get_component (void);
00083 
00084   /// Get the repository id.
00085   virtual char * _repository_id (void);
00086 
00087   /// This is an auxiliary method for _this() and _narrow().
00088   virtual TAO_Stub *_create_stub (void);
00089 
00090   /**
00091    * Dispatches a request to the object: find the operation, cast the
00092    * type to the most derived type, demarshall all the parameters from
00093    * the request and finally invokes the operation, storing the
00094    * results and out parameters (if any) or the exceptions thrown into
00095    * @a request.
00096    */
00097   virtual void _dispatch (TAO_ServerRequest &request, void *servant_upcall) = 0;
00098 
00099   /// Please see documentation in tao/Abstract_Servant_Base.h for
00100   /// details.
00101   virtual int _find (const char *opname,
00102                      TAO_Skeleton &skelfunc,
00103                      const size_t length = 0);
00104 
00105   virtual int _find (const char *opname,
00106                      TAO_Collocated_Skeleton &skelfunc,
00107                      TAO::Collocation_Strategy st,
00108                      const size_t length = 0);
00109 
00110   /// Get this interface's repository id (TAO specific).
00111   virtual const char *_interface_repository_id (void) const = 0;
00112 
00113   //@{
00114   /**
00115    * @name Reference Counting Operations
00116    */
00117   /// Increase reference count by one.
00118   virtual void _add_ref (void);
00119 
00120   /**
00121    * Decreases reference count by one; if the resulting reference
00122    * count equals zero, _remove_ref invokes delete on its this pointer
00123    * in order to destroy the servant.
00124    */
00125   virtual void _remove_ref (void);
00126 
00127   /**
00128    * Returns the current reference count value.
00129    */
00130   virtual CORBA::ULong _refcount_value (void) const;
00131   //@}
00132 
00133 protected:
00134 
00135   /// Default constructor, only derived classes can be created.
00136   TAO_ServantBase (void);
00137 
00138   /// Copy constructor, protected so no instances can be created.
00139   TAO_ServantBase (const TAO_ServantBase &);
00140 
00141   /// Assignment operator.
00142   TAO_ServantBase &operator= (const TAO_ServantBase &);
00143 
00144   virtual void synchronous_upcall_dispatch (TAO_ServerRequest & req,
00145                                             void * servant_upcall,
00146                                             void * derived_this);
00147 
00148   virtual void asynchronous_upcall_dispatch (TAO_ServerRequest & req,
00149                                              void * servant_upcall,
00150                                              void * derived_this);
00151 
00152 protected:
00153   /// Reference counter.
00154   ACE_Atomic_Op<TAO_SYNCH_MUTEX, long> ref_count_;
00155 
00156   /// The operation table for this servant.  It is initialized by the
00157   /// most derived class.
00158   TAO_Operation_Table * optable_;
00159 };
00160 
00161 class TAO_PortableServer_Export TAO_Servant_Hash
00162 {
00163 public:
00164   /// Returns hash value.
00165   u_long operator () (PortableServer::Servant servant) const;
00166 };
00167 
00168 namespace PortableServer
00169 {
00170   typedef Servant_var<TAO_ServantBase> ServantBase_var;
00171 }
00172 
00173 TAO_END_VERSIONED_NAMESPACE_DECL
00174 
00175 #if defined (__ACE_INLINE__)
00176 # include "tao/PortableServer/Servant_Base.inl"
00177 #endif /* __ACE_INLINE__ */
00178 
00179 #include /**/ "ace/post.h"
00180 
00181 #endif /* TAO_SERVANT_BASE_H */

Generated on Tue Feb 2 17:40:54 2010 for TAO_PortableServer by  doxygen 1.4.7