Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tao / PortableServer / Servant_Base.h
blob9b15c1c26bbbfb5b9770f2709ce5c2bede2d2928
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file Servant_Base.h
7 * @author Irfan Pyarali <irfan@cs.wustl.edu>
8 */
9 //=============================================================================
11 #ifndef TAO_SERVANT_BASE_H
12 #define TAO_SERVANT_BASE_H
14 #include /**/ "ace/pre.h"
16 #include "tao/PortableServer/portableserver_export.h"
18 #if !defined (ACE_LACKS_PRAGMA_ONCE)
19 # pragma once
20 #endif /* ACE_LACKS_PRAGMA_ONCE */
22 #include "tao/PortableServer/PS_ForwardC.h"
23 #include "tao/PortableServer/Servant_var.h"
24 #include "tao/Abstract_Servant_Base.h"
25 #include <atomic>
27 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
29 class TAO_Operation_Table;
31 /**
32 * @class TAO_ServantBase
34 * @brief Base class for skeletons and servants.
36 * The POA spec requires that all servants inherit from this class'
37 * base class.
39 * An instance of a servant class derived from
40 * ServantBase initially has a reference count of
41 * one. Invoking _add_ref on the servant instance increases its
42 * reference count by one. Invoking _remove_ref on the servant
43 * instance decreases its reference count by one; if the
44 * resulting reference count equals zero, _remove_ref invokes
45 * delete on its this pointer in order to destroy the
46 * servant. For ORBs that operate in multi-threaded
47 * environments, the implementations of _add_ref and _remove_ref
48 * that the ServantBase class provides shall be
49 * thread-safe.
51 * Like ServantBase supports copy
52 * construction and the default assignment operation. Copy
53 * construction always sets the reference count of the new
54 * servant instance to one. The default assignment
55 * implementation merely returns *this and does not affect the
56 * reference count.
58 class TAO_PortableServer_Export TAO_ServantBase
59 : public virtual TAO_Abstract_ServantBase
61 public:
62 /// Useful for template programming.
63 typedef CORBA::Object _stub_type;
64 typedef CORBA::Object_ptr _stub_ptr_type;
65 typedef CORBA::Object_var _stub_var_type;
67 /// Destructor.
68 virtual ~TAO_ServantBase ();
70 static void _is_a_skel (TAO_ServerRequest & req,
71 TAO::Portable_Server::Servant_Upcall* servant_upcall,
72 TAO_ServantBase *servant);
74 static void _is_a_thru_poa_skel (TAO_ServerRequest & server_request,
75 TAO::Portable_Server::Servant_Upcall* servant_upcall,
76 TAO_ServantBase *servant);
78 #if (TAO_HAS_MINIMUM_CORBA == 0)
79 static void _non_existent_skel (TAO_ServerRequest & req,
80 TAO::Portable_Server::Servant_Upcall* servant_upcall,
81 TAO_ServantBase *servant);
82 static void _non_existent_thru_poa_skel (TAO_ServerRequest & server_request,
83 TAO::Portable_Server::Servant_Upcall* servant_upcall,
84 TAO_ServantBase *servant);
86 # if !defined (CORBA_E_COMPACT) && !defined (CORBA_E_MICRO)
87 static void _interface_skel (TAO_ServerRequest & req,
88 TAO::Portable_Server::Servant_Upcall* servant_upcall,
89 TAO_ServantBase *servant);
91 static void _component_skel (TAO_ServerRequest & req,
92 TAO::Portable_Server::Servant_Upcall* servant_upcall,
93 TAO_ServantBase *servant);
94 static void _component_thru_poa_skel (TAO_ServerRequest & server_request,
95 TAO::Portable_Server::Servant_Upcall* servant_upcall,
96 TAO_ServantBase *servant);
97 # endif /* !defined (CORBA_E_COMPACT) && !defined (CORBA_E_MICRO) */
98 static void _repository_id_skel (TAO_ServerRequest & req,
99 TAO::Portable_Server::Servant_Upcall* servant_upcall,
100 TAO_ServantBase *servant);
101 static void _repository_id_thru_poa_skel (TAO_ServerRequest & server_request,
102 TAO::Portable_Server::Servant_Upcall* servant_upcall,
103 TAO_ServantBase *servant);
104 #endif /* TAO_HAS_MINIMUM_CORBA */
106 /// Returns the default POA for this servant.
107 virtual PortableServer::POA_ptr _default_POA ();
109 /// Local implementation of the CORBA::Object::_is_a method.
110 virtual CORBA::Boolean _is_a (const char *logical_type_id);
112 #if (TAO_HAS_MINIMUM_CORBA == 0)
113 /// Default _non_existent: always returns false.
114 virtual CORBA::Boolean _non_existent ();
116 /// Query the Interface Repository for the interface definition.
117 virtual CORBA::InterfaceDef_ptr _get_interface ();
119 #if !defined (CORBA_E_COMPACT) && !defined (CORBA_E_MICRO)
120 /// Default _get_component: always returns CORBA::Object::_nil().
121 virtual CORBA::Object_ptr _get_component ();
122 #endif
124 /// Get the repository id.
125 virtual char * _repository_id ();
126 #endif /* TAO_HAS_MINIMUM_CORBA */
128 /// This is an auxiliary method for _this() and _narrow().
129 virtual TAO_Stub *_create_stub ();
132 * Dispatches a request to the object: find the operation, cast the
133 * type to the most derived type, demarshall all the parameters from
134 * the request and finally invokes the operation, storing the
135 * results and out parameters (if any) or the exceptions thrown into
136 * @a request.
138 virtual void _dispatch (
139 TAO_ServerRequest &request,
140 TAO::Portable_Server::Servant_Upcall* servant_upcall) = 0;
142 /// Please see documentation in tao/Abstract_Servant_Base.h for
143 /// details.
144 virtual int _find (const char *opname,
145 TAO_Skeleton &skelfunc,
146 const size_t length = 0);
148 virtual int _find (const char *opname,
149 TAO_Collocated_Skeleton &skelfunc,
150 TAO::Collocation_Strategy st,
151 const size_t length = 0);
153 /// Get this interface's repository id (TAO specific).
154 virtual const char *_interface_repository_id () const = 0;
156 //@{
158 * @name Reference Counting Operations
160 /// Increase reference count by one.
161 virtual void _add_ref ();
164 * Decreases reference count by one; if the resulting reference
165 * count equals zero, _remove_ref invokes delete on its this pointer
166 * in order to destroy the servant.
168 virtual void _remove_ref ();
171 * Returns the current reference count value.
173 virtual CORBA::ULong _refcount_value () const;
174 //@}
176 virtual void _collocated_dispatch (::CORBA::Object_ptr obj,
177 ::CORBA::Object_out forward_obj,
178 bool &is_forwarded,
179 TAO::Argument ** args,
180 int num_args,
181 const char * op,
182 size_t op_len,
183 TAO::Collocation_Strategy strategy);
185 protected:
186 /// Default constructor, only derived classes can be created.
187 explicit TAO_ServantBase (TAO_Operation_Table* optable = 0);
189 /// Copy constructor, protected so no instances can be created.
190 TAO_ServantBase (const TAO_ServantBase &);
192 /// Assignment operator.
193 TAO_ServantBase &operator= (const TAO_ServantBase &);
195 void synchronous_upcall_dispatch (
196 TAO_ServerRequest & req,
197 TAO::Portable_Server::Servant_Upcall* servant_upcall,
198 TAO_ServantBase *derived_this);
200 void asynchronous_upcall_dispatch (
201 TAO_ServerRequest & req,
202 TAO::Portable_Server::Servant_Upcall* servant_upcall,
203 TAO_ServantBase *derived_this);
205 protected:
206 /// Reference counter.
207 std::atomic<uint32_t> ref_count_;
209 /// The operation table for this servant. It is initialized by the
210 /// most derived class.
211 TAO_Operation_Table * optable_;
214 class TAO_PortableServer_Export TAO_Servant_Hash
216 public:
217 /// Returns hash value.
218 u_long operator () (PortableServer::Servant servant) const;
221 namespace PortableServer
223 typedef Servant_var<TAO_ServantBase> ServantBase_var;
226 TAO_END_VERSIONED_NAMESPACE_DECL
228 #if defined (__ACE_INLINE__)
229 # include "tao/PortableServer/Servant_Base.inl"
230 #endif /* __ACE_INLINE__ */
232 #include /**/ "ace/post.h"
234 #endif /* TAO_SERVANT_BASE_H */