Object.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    Object.h
00006  *
00007  *  $Id: Object.h 81430 2008-04-24 19:04:02Z johnnyw $
00008  *
00009  *   A "Object" is an entity that can be the target of an invocation
00010  *   using an ORB.  All CORBA objects provide this functionality.
00011  *   See the CORBA 3.x specification for details.
00012  *
00013  *  @author  Portions Copyright 1994-1995 by Sun Microsystems Inc.
00014  *  @author  Portions Copyright 1997-2002 by Washington University
00015  */
00016 //=============================================================================
00017 
00018 #ifndef TAO_CORBA_OBJECT_H
00019 #define TAO_CORBA_OBJECT_H
00020 
00021 #include /**/ "ace/pre.h"
00022 
00023 #include "tao/IOP_IORC.h"
00024 
00025 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00026 # pragma once
00027 #endif /* ACE_LACKS_PRAGMA_ONCE */
00028 
00029 #include "tao/CORBA_methods.h"
00030 #include "tao/Policy_ForwardC.h"
00031 #include "tao/Pseudo_VarOut_T.h"
00032 #include "tao/Object_Argument_T.h"
00033 #include "tao/Arg_Traits_T.h"
00034 #include "tao/Any_Insert_Policy_T.h"
00035 #include "tao/Configurable_Refcount.h"
00036 
00037 #if defined (HPUX) && defined (IOR)
00038    /* HP-UX 11.11 defines IOR in /usr/include/pa/inline.h
00039       and we don't want that definition.  See IOP_IORC.h. */
00040 # undef IOR
00041 #endif /* HPUX && IOR */
00042 
00043 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00044 class ACE_Lock;
00045 ACE_END_VERSIONED_NAMESPACE_DECL
00046 
00047 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00048 
00049 class TAO_Stub;
00050 class TAO_Abstract_ServantBase;
00051 class TAO_ORB_Core;
00052 
00053 namespace TAO
00054 {
00055   class ObjectKey;
00056   class Object_Proxy_Broker;
00057 }
00058 
00059 namespace CORBA
00060 {
00061   class InterfaceDef;
00062   typedef InterfaceDef *InterfaceDef_ptr;
00063 
00064   class Context;
00065   typedef Context *Context_ptr;
00066 
00067   class Request;
00068   typedef Request *Request_ptr;
00069 
00070   class NVList;
00071   typedef NVList *NVList_ptr;
00072 
00073   class NamedValue;
00074   typedef NamedValue * NamedValue_ptr;
00075 
00076   typedef ULong Flags;
00077 
00078   class ExceptionList;
00079   typedef ExceptionList *ExceptionList_ptr;
00080 
00081   class ContextList;
00082   typedef ContextList *ContextList_ptr;
00083 
00084   class Object;
00085   typedef Object *Object_ptr;
00086   typedef TAO_Pseudo_Var_T<Object> Object_var;
00087   typedef TAO_Pseudo_Out_T<Object> Object_out;
00088 
00089   /**
00090    * @class Object
00091    *
00092    * @brief Implementation of a CORBA object reference.
00093    *
00094    * All CORBA objects, both unconstrained and locality-constrained,
00095    * inherit from this class.  The interface is defined in the CORBA
00096    * specification and the C++ mapping.
00097    */
00098   class TAO_Export Object
00099   {
00100   public:
00101 
00102     /// Destructor.
00103     virtual ~Object (void);
00104 
00105     /**
00106      * @name Spec defined methods
00107      *
00108      * These methods are defined here since they are required by the
00109      * CORBA spec in a form specified by the C++ mapping.
00110      */
00111     //@{
00112     /// Increment the ref count.
00113     static CORBA::Object_ptr _duplicate (CORBA::Object_ptr obj);
00114 
00115     /// Return a NULL object.
00116     static CORBA::Object_ptr _nil (void);
00117 
00118     /// No-op it is just here to simplify some templates.
00119     static CORBA::Object_ptr _narrow (CORBA::Object_ptr obj);
00120 
00121     // These calls correspond to over-the-wire operations, or at least
00122     // do so in many common cases.  The normal implementation assumes a
00123     // particular simple, efficient, protocol-neutral interface for
00124     // making such calls, but may be overridden when it appears
00125     // appropriate.
00126 
00127     /// Determine if we are of the type specified by the "logical_type_id"
00128     virtual CORBA::Boolean _is_a (const char *logical_type_id);
00129 
00130     /// The repository ID for the most derived class, this is an
00131     /// implementation method and does no remote invocations!
00132     virtual const char* _interface_repository_id (void) const;
00133 
00134     /**
00135      * Return a (potentially non-unique) hash value for this object.
00136      * This method relies on the representation of the object
00137      * reference's private state.  Since that changes easily (when
00138      * different ORB protocols are in use) there is no default
00139      * implementation.
00140      */
00141     virtual CORBA::ULong _hash (CORBA::ULong maximum);
00142 
00143     /**
00144      * Try to determine if this object is the same as other_obj.  This
00145      * method relies on the representation of the object reference's
00146      * private state.  Since that changes easily (when different ORB
00147      * protocols are in use) there is no default implementation.
00148      */
00149     virtual CORBA::Boolean _is_equivalent (CORBA::Object_ptr other_obj);
00150 
00151 #if (TAO_HAS_MINIMUM_CORBA == 0)
00152 
00153     virtual CORBA::Boolean _non_existent (void);
00154 
00155 #if ! defined (CORBA_E_COMPACT) && ! defined (CORBA_E_MICRO)
00156     /// Get info about the object from the Interface Repository.
00157     virtual InterfaceDef_ptr _get_interface (void);
00158 
00159     /// Get info about the object from the Interface Repository.
00160     virtual CORBA::Object_ptr _get_component (void);
00161 #endif
00162 
00163     /// Get the repository id.
00164     virtual char * _repository_id (void);
00165 
00166 #if ! defined (CORBA_E_COMPACT) && ! defined (CORBA_E_MICRO)
00167     // DII operations to create a request.
00168     //
00169     // The mapping for create_request is split into two forms,
00170     // corresponding to the two usage styles described in CORBA
00171     // section 6.2.1.
00172 
00173     virtual void _create_request (CORBA::Context_ptr ctx,
00174                                   const char *operation,
00175                                   CORBA::NVList_ptr arg_list,
00176                                   CORBA::NamedValue_ptr result,
00177                                   CORBA::Request_ptr &request,
00178                                   CORBA::Flags req_flags);
00179 
00180     virtual void _create_request (CORBA::Context_ptr ctx,
00181                                   const char *operation,
00182                                   CORBA::NVList_ptr arg_list,
00183                                   CORBA::NamedValue_ptr result,
00184                                   CORBA::ExceptionList_ptr exclist,
00185                                   CORBA::ContextList_ptr ctxtlist,
00186                                   CORBA::Request_ptr &request,
00187                                   CORBA::Flags req_flags);
00188 
00189     // The default implementation of this method uses the same simple,
00190     // multi-protocol remote invocation interface as is assumed by the
00191     // calls above ... that's how it can have a default
00192     // implementation.
00193 
00194     /// DII operation to create a request.
00195     virtual CORBA::Request_ptr _request (const char *operation);
00196 #endif
00197 
00198 #endif /* TAO_HAS_MINIMUM_CORBA */
00199 
00200 #if (TAO_HAS_CORBA_MESSAGING == 1)
00201 
00202     CORBA::Policy_ptr _get_policy (CORBA::PolicyType type);
00203 
00204     CORBA::Policy_ptr _get_cached_policy (TAO_Cached_Policy_Type type);
00205 
00206     CORBA::Object_ptr _set_policy_overrides (
00207       const CORBA::PolicyList & policies,
00208       CORBA::SetOverrideType set_add);
00209 
00210     CORBA::PolicyList * _get_policy_overrides (
00211       const CORBA::PolicyTypeSeq & types);
00212 
00213     CORBA::Boolean _validate_connection (
00214       CORBA::PolicyList_out inconsistent_policies);
00215 
00216 #endif /* TAO_HAS_CORBA_MESSAGING == 1 */
00217 
00218     virtual CORBA::ORB_ptr _get_orb (void);
00219 
00220     /**
00221      * @name Reference Count Managment
00222      *
00223      * These are the standard CORBA object reference count manipulations
00224      * methods.
00225      */
00226     //@{
00227     /// Increment the reference count.
00228     virtual void _add_ref (void);
00229 
00230     /// Decrement the reference count.
00231     virtual void _remove_ref (void);
00232 
00233     /// Get the refcount
00234     virtual CORBA::ULong _refcount_value(void) const;
00235     //@}
00236 
00237     // Useful for template programming.
00238     typedef Object_ptr _ptr_type;
00239     typedef Object_var _var_type;
00240     typedef Object_out _out_type;
00241 
00242     //@} End of CORBA specific methods
00243 
00244   public:
00245     /// Marshalling operator used by the stub code. A long story why
00246     /// the stub code uses this, let us keep it short here.
00247     static CORBA::Boolean marshal (const Object_ptr x,
00248                                    TAO_OutputCDR &cdr);
00249 
00250     /// Accessor for the cached servant reference held on the stub
00251     /// if this object is collocated
00252     virtual TAO_Abstract_ServantBase *_servant (void) const;
00253 
00254     /// Is this object collocated with the servant?
00255     /// Note this does not return this->is_collocated_ but will instead
00256     /// query the underlying stub for its collocation status
00257     virtual CORBA::Boolean _is_collocated (void) const;
00258 
00259     /// Is this a local object?
00260     virtual CORBA::Boolean _is_local (void) const;
00261 
00262     /// Used in the implementation of CORBA::Any
00263     static void _tao_any_destructor (void*);
00264 
00265     /// Uninlined part of the now-inlined CORBA::is_nil().
00266     static CORBA::Boolean is_nil_i (CORBA::Object_ptr obj);
00267 
00268     /// Helper function for reading contents of an IOR
00269     static void tao_object_initialize (Object *);
00270 
00271     /// Return the object key as an out parameter.  Caller should release
00272     /// return value when finished with it.
00273     virtual TAO::ObjectKey *_key (void);
00274 
00275     /// Constructor
00276     Object (TAO_Stub *p,
00277             CORBA::Boolean collocated = 0,
00278             TAO_Abstract_ServantBase *servant = 0,
00279             TAO_ORB_Core *orb_core = 0);
00280 
00281     Object (IOP::IOR *ior, TAO_ORB_Core *orb_core = 0);
00282 
00283     /// Get the underlying stub object.
00284     virtual TAO_Stub *_stubobj (void) const;
00285     virtual TAO_Stub *_stubobj (void);
00286 
00287     /// Set the proxy broker.
00288     virtual void _proxy_broker (TAO::Object_Proxy_Broker *proxy_broker);
00289 
00290   public:
00291 
00292     /// Allows us to forbid marshaling of local interfaces.
00293     virtual CORBA::Boolean marshal (TAO_OutputCDR &cdr);
00294 
00295 #if defined (GEN_OSTREAM_OPS)
00296 
00297     /// Used by optionally generated ostream operators for interface
00298     /// to output the actual repo id for debugging.
00299     static std::ostream& _tao_stream (std::ostream &strm,
00300                                       const Object_ptr _tao_objref);
00301     virtual std::ostream& _tao_stream_v (std::ostream &strm) const;
00302 
00303 #endif /* GEN_OSTREAM_OPS */
00304 
00305     /// Accessor to the flag..
00306     CORBA::Boolean is_evaluated (void) const;
00307 
00308     /// Mutator for setting the servant in collocated cases.
00309     /**
00310      * This is used by the Object_Adapter to set the servant for
00311      * collocated cases and only when the object is initialized. The
00312      * object initialization takes place when IOR's are lazily
00313      * evaluated.
00314      */
00315     void set_collocated_servant (TAO_Abstract_ServantBase *);
00316 
00317     /// Accessor for the ORB_Core..
00318     TAO_ORB_Core *orb_core (void) const;
00319 
00320     /// Accessors for the underlying IOP::IOR's.
00321     /**
00322      * The steal_ior () call basically relinquishes the ownership of
00323      * the IOR. This is useful for cases when one wants to initialize
00324      * a new CORBA Object
00325      */
00326     IOP::IOR *steal_ior (void);
00327 
00328     const IOP::IOR &ior (void) const;
00329 
00330     //@} End of TAO-specific methods..
00331 
00332     /// Can this object be stringified?
00333     virtual bool can_convert_to_ior (void) const;
00334 
00335     /// A hook to allow users to provide custom object stringification.
00336     /// @note This method is intended to be used by classes that
00337     /// implement Smart Proxies and no others.
00338     virtual char* convert_to_ior (bool use_omg_ior_format,
00339                                   const char* ior_prefix) const;
00340 
00341   protected:
00342 
00343     /// Initializing a local object.
00344     Object (int dummy = 0);
00345 
00346     /// Convenience accessor for the object proxy broker of the
00347     /// underlying stub.
00348     TAO::Object_Proxy_Broker *proxy_broker () const;
00349 
00350     /// Number of outstanding references to this object.
00351     TAO_Configurable_Refcount refcount_;
00352 
00353   private:
00354 
00355     // = Unimplemented methods
00356     Object (const Object &);
00357     Object &operator = (const Object &);
00358 
00359   private:
00360     /// Specify whether this is a local object or not.
00361     CORBA::Boolean is_local_;
00362 
00363     /// Flag to indicate whether the IOP::IOR has been evaluated fully.
00364     CORBA::Boolean is_evaluated_;
00365 
00366     /// If the IOR hasnt been evaluated fully, then the contents of
00367     /// the IOR that we received  should be in here!
00368     IOP::IOR_var ior_;
00369 
00370     /// Cached pointer of our ORB_Core
00371     /**
00372      * Be aware that this pointer can be zero or not. In fact there are two
00373      * ways to get this pointer filled:
00374      * - If CORBA::Object is constructed through one of the constructors with a
00375      * stub and null ORB_Core, we use the orb_core from the stub to fill
00376      * this pointer
00377      * - If the other constructor, which uses IOP::IOR is used, a stub
00378      * needs to be created first (i.e., the IOR needs to be evaluated first),
00379      * in which case the ORB_Core would be null. The orb_core pointer then
00380      * needs to be accessed from the stub and passed back as part of
00381      * _get_orb().
00382      */
00383     TAO_ORB_Core * orb_core_;
00384 
00385     /**
00386      * Pointer to the protocol-specific "object" containing important
00387      * profiling information regarding this proxy.
00388      * The protocol proxy is (potentially) shared among several
00389      * Objects
00390      */
00391     TAO_Stub * protocol_proxy_;
00392 
00393     /// Protect reference count manipulation from race conditions.
00394     /**
00395      * This lock is only instantiated for unconstrained objects.  The
00396      * reason for this is that locality-constrained objects that do
00397      * not require reference counting (the default) may be
00398      * instantiated in the critical path.
00399      */
00400     ACE_Lock * object_init_lock_;
00401   };
00402 }   // End CORBA namespace.
00403 
00404 namespace TAO
00405 {
00406   template<>
00407   class TAO_Export Arg_Traits<CORBA::Object>
00408     : public Object_Arg_Traits_T<CORBA::Object_ptr,
00409                                  CORBA::Object_var,
00410                                  CORBA::Object_out,
00411                                  TAO::Objref_Traits<CORBA::Object>,
00412                                  TAO::Any_Insert_Policy_CORBA_Object <CORBA::Object_ptr> >
00413   {
00414   };
00415 
00416   template<>
00417   struct TAO_Export Objref_Traits<CORBA::Object>
00418   {
00419     static CORBA::Object_ptr duplicate (CORBA::Object_ptr);
00420     static void release (CORBA::Object_ptr);
00421     static CORBA::Object_ptr nil (void);
00422     static CORBA::Boolean marshal (const CORBA::Object_ptr p,
00423                                    TAO_OutputCDR & cdr);
00424   };
00425 
00426   template<>
00427   struct TAO_Export In_Object_Argument_Cloner_T<CORBA::InterfaceDef_ptr>
00428   {
00429     static void duplicate(CORBA::InterfaceDef_ptr objref);
00430     static void release(CORBA::InterfaceDef_ptr objref);
00431   };
00432 }
00433 
00434 /// This function pointer is set only when the Portable server
00435 /// library is present.
00436 extern
00437   TAO_Export TAO::Object_Proxy_Broker *
00438   (*_TAO_Object_Proxy_Broker_Factory_function_pointer) (void);
00439 
00440 TAO_Export CORBA::Boolean
00441 operator<< (TAO_OutputCDR&, const CORBA::Object*);
00442 
00443 TAO_Export CORBA::Boolean
00444 operator>> (TAO_InputCDR&, CORBA::Object *&);
00445 
00446 #if defined (GEN_OSTREAM_OPS)
00447 
00448 TAO_Export std::ostream&
00449 operator<< (std::ostream&, CORBA::Object_ptr);
00450 
00451 #endif /* GEN_OSTREAM_OPS */
00452 
00453 TAO_END_VERSIONED_NAMESPACE_DECL
00454 
00455 #if defined (__ACE_INLINE__)
00456 # include "tao/Object.inl"
00457 #endif /* __ACE_INLINE__ */
00458 
00459 #include /**/ "ace/post.h"
00460 #endif /* TAO_CORBA_OBJECT_H */

Generated on Tue Feb 2 17:37:52 2010 for TAO by  doxygen 1.4.7