Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tao / Object.h
blobbe3a1b18ef32f4c1ac0c63a44f415a343febb69b
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file Object.h
7 * A "Object" is an entity that can be the target of an invocation
8 * using an ORB. All CORBA objects provide this functionality.
9 * See the CORBA 3.x specification for details.
11 * @author Portions Copyright 1994-1995 by Sun Microsystems Inc.
12 * @author Portions Copyright 1997-2002 by Washington University
14 //=============================================================================
16 #ifndef TAO_CORBA_OBJECT_H
17 #define TAO_CORBA_OBJECT_H
19 #include /**/ "ace/pre.h"
21 #include "tao/IOPC.h"
23 #if !defined (ACE_LACKS_PRAGMA_ONCE)
24 # pragma once
25 #endif /* ACE_LACKS_PRAGMA_ONCE */
27 #include "tao/CORBA_methods.h"
28 #include "tao/Policy_ForwardC.h"
29 #include "tao/Pseudo_VarOut_T.h"
30 #include "tao/Object_Argument_T.h"
31 #include "tao/Arg_Traits_T.h"
32 #include "tao/Any_Insert_Policy_T.h"
33 #include <atomic>
35 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
37 class TAO_Stub;
38 class TAO_Abstract_ServantBase;
39 class TAO_ORB_Core;
41 namespace TAO
43 class ObjectKey;
44 class Object_Proxy_Broker;
47 namespace CORBA
49 class InterfaceDef;
50 typedef InterfaceDef *InterfaceDef_ptr;
52 class Context;
53 typedef Context *Context_ptr;
55 class Request;
56 typedef Request *Request_ptr;
58 class NVList;
59 typedef NVList *NVList_ptr;
61 class NamedValue;
62 typedef NamedValue * NamedValue_ptr;
64 typedef ULong Flags;
66 class ExceptionList;
67 typedef ExceptionList *ExceptionList_ptr;
69 class ContextList;
70 typedef ContextList *ContextList_ptr;
72 class Object;
73 typedef Object *Object_ptr;
75 typedef TAO_Pseudo_Var_T<Object> Object_var;
76 typedef TAO_Pseudo_Out_T<Object> Object_out;
78 template<>
79 TAO_Export Boolean
80 is_nil<> (Object_ptr);
82 /**
83 * @class Object
85 * @brief Implementation of a CORBA object reference.
87 * All CORBA objects, both unconstrained and locality-constrained,
88 * inherit from this class. The interface is defined in the CORBA
89 * specification and the C++ mapping.
91 class TAO_Export Object
93 public:
94 /// Destructor.
95 virtual ~Object ();
97 /**
98 * @name Spec defined methods
100 * These methods are defined here since they are required by the
101 * CORBA spec in a form specified by the C++ mapping.
103 //@{
104 /// Increment the ref count.
105 static CORBA::Object_ptr _duplicate (CORBA::Object_ptr obj);
107 /// Return a NULL object.
108 static CORBA::Object_ptr _nil ();
110 /// No-op it is just here to simplify some templates.
111 static CORBA::Object_ptr _narrow (CORBA::Object_ptr obj);
113 // These calls correspond to over-the-wire operations, or at least
114 // do so in many common cases. The normal implementation assumes a
115 // particular simple, efficient, protocol-neutral interface for
116 // making such calls, but may be overridden when it appears
117 // appropriate.
119 /// Determine if we are of the type specified by the "logical_type_id"
120 virtual CORBA::Boolean _is_a (const char *logical_type_id);
122 /// The repository ID for the most derived class, this is an
123 /// implementation method and does no remote invocations!
124 virtual const char* _interface_repository_id () const;
127 * Return a (potentially non-unique) hash value for this object.
128 * This method relies on the representation of the object
129 * reference's private state. Since that changes easily (when
130 * different ORB protocols are in use) there is no default
131 * implementation.
133 virtual CORBA::ULong _hash (CORBA::ULong maximum);
136 * Try to determine if this object is the same as other_obj. This
137 * method relies on the representation of the object reference's
138 * private state. Since that changes easily (when different ORB
139 * protocols are in use) there is no default implementation.
141 virtual CORBA::Boolean _is_equivalent (CORBA::Object_ptr other_obj);
143 #if (TAO_HAS_MINIMUM_CORBA == 0)
145 virtual CORBA::Boolean _non_existent ();
147 #if ! defined (CORBA_E_COMPACT) && ! defined (CORBA_E_MICRO)
148 /// Get info about the object from the Interface Repository.
149 virtual InterfaceDef_ptr _get_interface ();
151 /// Get info about the object from the Interface Repository.
152 virtual CORBA::Object_ptr _get_component ();
153 #endif
155 /// Get the repository id.
156 virtual char * _repository_id ();
158 #if ! defined (CORBA_E_COMPACT) && ! defined (CORBA_E_MICRO)
159 // DII operations to create a request.
161 // The mapping for create_request is split into two forms,
162 // corresponding to the two usage styles described in CORBA
163 // section 6.2.1.
165 virtual void _create_request (CORBA::Context_ptr ctx,
166 const char *operation,
167 CORBA::NVList_ptr arg_list,
168 CORBA::NamedValue_ptr result,
169 CORBA::Request_ptr &request,
170 CORBA::Flags req_flags);
172 virtual void _create_request (CORBA::Context_ptr ctx,
173 const char *operation,
174 CORBA::NVList_ptr arg_list,
175 CORBA::NamedValue_ptr result,
176 CORBA::ExceptionList_ptr exclist,
177 CORBA::ContextList_ptr ctxtlist,
178 CORBA::Request_ptr &request,
179 CORBA::Flags req_flags);
181 // The default implementation of this method uses the same simple,
182 // multi-protocol remote invocation interface as is assumed by the
183 // calls above ... that's how it can have a default
184 // implementation.
186 /// DII operation to create a request.
187 virtual CORBA::Request_ptr _request (const char *operation);
188 #endif
190 #endif /* TAO_HAS_MINIMUM_CORBA */
192 #if (TAO_HAS_CORBA_MESSAGING == 1)
194 CORBA::Policy_ptr _get_policy (CORBA::PolicyType type);
196 CORBA::Policy_ptr _get_cached_policy (TAO_Cached_Policy_Type type);
198 CORBA::Object_ptr _set_policy_overrides (
199 const CORBA::PolicyList & policies,
200 CORBA::SetOverrideType set_add);
202 CORBA::PolicyList * _get_policy_overrides (
203 const CORBA::PolicyTypeSeq & types);
205 CORBA::Boolean _validate_connection (
206 CORBA::PolicyList_out inconsistent_policies);
208 #endif /* TAO_HAS_CORBA_MESSAGING == 1 */
210 virtual CORBA::ORB_ptr _get_orb ();
213 * @name Reference Count Management
215 * These are the standard CORBA object reference count manipulations
216 * methods.
218 //@{
219 /// Increment the reference count.
220 virtual void _add_ref ();
222 /// Decrement the reference count.
223 virtual void _remove_ref ();
225 /// Get the refcount
226 virtual CORBA::ULong _refcount_value () const;
227 //@}
229 // Useful for template programming.
230 typedef Object_ptr _ptr_type;
231 typedef Object_var _var_type;
232 typedef Object_out _out_type;
234 //@} End of CORBA specific methods
236 public:
237 /// Marshalling operator used by the stub code. A long story why
238 /// the stub code uses this, let us keep it short here.
239 static CORBA::Boolean marshal (const Object_ptr x,
240 TAO_OutputCDR &cdr);
242 /// Accessor for the cached servant reference held on the stub
243 /// if this object is collocated
244 virtual TAO_Abstract_ServantBase *_servant () const;
246 /// Is this object collocated with the servant?
247 /// Note this does not return this->is_collocated_ but will instead
248 /// query the underlying stub for its collocation status
249 virtual CORBA::Boolean _is_collocated () const;
251 /// Is this a local object?
252 virtual CORBA::Boolean _is_local () const;
254 /// Used in the implementation of CORBA::Any
255 static void _tao_any_destructor (void*);
257 /// Uninlined part of the now-inlined CORBA::is_nil().
258 static CORBA::Boolean is_nil_i (CORBA::Object_ptr obj);
260 /// Helper function for reading contents of an IOR
261 static void tao_object_initialize (Object *);
263 /// Return the object key as an out parameter. Caller should release
264 /// return value when finished with it.
265 virtual TAO::ObjectKey *_key ();
267 /// Constructor
268 Object (TAO_Stub *p,
269 CORBA::Boolean collocated = false,
270 TAO_Abstract_ServantBase *servant = 0,
271 TAO_ORB_Core *orb_core = 0);
273 Object (IOP::IOR *ior, TAO_ORB_Core *orb_core);
275 /// Get the underlying stub object.
276 virtual TAO_Stub *_stubobj () const;
277 virtual TAO_Stub *_stubobj ();
279 /// Set the proxy broker.
280 virtual void _proxy_broker (TAO::Object_Proxy_Broker *proxy_broker);
282 public:
283 /// Allows us to forbid marshaling of local interfaces.
284 virtual CORBA::Boolean marshal (TAO_OutputCDR &cdr);
286 #if defined (GEN_OSTREAM_OPS)
288 /// Used by optionally generated ostream operators for interface
289 /// to output the actual repo id for debugging.
290 static std::ostream& _tao_stream (std::ostream &strm,
291 const Object_ptr _tao_objref);
292 virtual std::ostream& _tao_stream_v (std::ostream &strm) const;
294 #endif /* GEN_OSTREAM_OPS */
296 /// Accessor to the flag..
297 CORBA::Boolean is_evaluated () const;
299 /// Accessor for the ORB_Core..
300 TAO_ORB_Core *orb_core () const;
302 /// Accessors for the underlying IOP::IOR's.
304 * The steal_ior () call basically relinquishes the ownership of
305 * the IOR. This is useful for cases when one wants to initialize
306 * a new CORBA Object
308 IOP::IOR *steal_ior ();
310 const IOP::IOR &ior () const;
312 //@} End of TAO-specific methods..
314 /// Can this object be stringified?
315 virtual bool can_convert_to_ior () const;
317 /// A hook to allow users to provide custom object stringification.
318 /// @note This method is intended to be used by classes that
319 /// implement Smart Proxies and no others.
320 virtual char* convert_to_ior (bool use_omg_ior_format,
321 const char* ior_prefix) const;
323 /// Wrapper for _remove_ref(), naming convention for templatizing.
324 void _decr_refcount ();
326 protected:
327 /// Initializing a local object.
328 Object (int dummy = 0);
330 /// Convenience accessor for the object proxy broker of the
331 /// underlying stub.
332 TAO::Object_Proxy_Broker *proxy_broker () const;
334 /// Number of outstanding references to this object.
335 # define TAO_OBJECT_USES_STD_ATOMIC_REFCOUNT
336 std::atomic<uint32_t> refcount_;
338 private:
339 Object (const Object &) = delete;
340 Object &operator = (const Object &) = delete;
342 private:
343 /// Specify whether this is a local object or not.
344 CORBA::Boolean is_local_;
346 /// Flag to indicate whether the IOP::IOR has been evaluated fully.
347 CORBA::Boolean is_evaluated_;
349 /// If the IOR hasnt been evaluated fully, then the contents of
350 /// the IOR that we received should be in here!
351 IOP::IOR_var ior_;
353 /// Cached pointer of our ORB_Core
355 * Be aware that this pointer can be zero or not. In fact there are two
356 * ways to get this pointer filled:
357 * - If CORBA::Object is constructed through one of the constructors with a
358 * stub and null ORB_Core, we use the orb_core from the stub to fill
359 * this pointer
360 * - If the other constructor, which uses IOP::IOR is used, a stub
361 * needs to be created first (i.e., the IOR needs to be evaluated first),
362 * in which case the ORB_Core would be null. The orb_core pointer then
363 * needs to be accessed from the stub and passed back as part of
364 * _get_orb().
366 TAO_ORB_Core * orb_core_;
369 * Pointer to the protocol-specific "object" containing important
370 * profiling information regarding this proxy.
371 * The protocol proxy is (potentially) shared among several
372 * Objects
374 TAO_Stub * protocol_proxy_;
376 /// Protect reference count manipulation from race conditions.
378 * This lock is only instantiated for unconstrained objects. The
379 * reason for this is that locality-constrained objects that do
380 * not require reference counting (the default) may be
381 * instantiated in the critical path.
383 TAO_SYNCH_MUTEX object_init_lock_;
385 } // End CORBA namespace.
387 namespace TAO
389 template<>
390 class TAO_Export Arg_Traits<CORBA::Object>
391 : public Object_Arg_Traits_T<CORBA::Object_ptr,
392 CORBA::Object_var,
393 CORBA::Object_out,
394 TAO::Objref_Traits<CORBA::Object>,
395 TAO::Any_Insert_Policy_CORBA_Object>
399 template<>
400 struct TAO_Export Objref_Traits<CORBA::Object>
402 static CORBA::Object_ptr duplicate (CORBA::Object_ptr);
403 static void release (CORBA::Object_ptr);
404 static CORBA::Object_ptr nil ();
405 static CORBA::Boolean marshal (const CORBA::Object_ptr p,
406 TAO_OutputCDR & cdr);
409 template<>
410 struct TAO_Export In_Object_Argument_Cloner_T<CORBA::InterfaceDef_ptr>
412 static void duplicate(CORBA::InterfaceDef_ptr objref);
413 static void release(CORBA::InterfaceDef_ptr objref);
417 /// This function pointer is set only when the Portable server
418 /// library is present.
419 extern
420 TAO_Export TAO::Object_Proxy_Broker *
421 (*_TAO_Object_Proxy_Broker_Factory_function_pointer) ();
423 TAO_Export CORBA::Boolean
424 operator<< (TAO_OutputCDR&, const CORBA::Object*);
426 TAO_Export CORBA::Boolean
427 operator>> (TAO_InputCDR&, CORBA::Object *&);
429 #if defined (GEN_OSTREAM_OPS)
431 TAO_Export std::ostream&
432 operator<< (std::ostream&, CORBA::Object_ptr);
434 #endif /* GEN_OSTREAM_OPS */
436 TAO_END_VERSIONED_NAMESPACE_DECL
438 #if defined (__ACE_INLINE__)
439 # include "tao/Object.inl"
440 #endif /* __ACE_INLINE__ */
442 #include /**/ "ace/post.h"
443 #endif /* TAO_CORBA_OBJECT_H */