Object.h

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

Generated on Thu Nov 9 11:54:16 2006 for TAO by doxygen 1.3.6