Object.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    Object.h
00006  *
00007  *  $Id: Object.h 79610 2007-09-07 18:17:34Z 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 ImplementationDef;
00065   typedef ImplementationDef *ImplementationDef_ptr;
00066 
00067   class Context;
00068   typedef Context *Context_ptr;
00069 
00070   class Request;
00071   typedef Request *Request_ptr;
00072 
00073   class NVList;
00074   typedef NVList *NVList_ptr;
00075 
00076   class NamedValue;
00077   typedef NamedValue * NamedValue_ptr;
00078 
00079   typedef ULong Flags;
00080 
00081   class ExceptionList;
00082   typedef ExceptionList *ExceptionList_ptr;
00083 
00084   class ContextList;
00085   typedef ContextList *ContextList_ptr;
00086 
00087   class Object;
00088   typedef Object *Object_ptr;
00089   typedef TAO_Pseudo_Var_T<Object> Object_var;
00090   typedef TAO_Pseudo_Out_T<Object> Object_out;
00091 
00092   /**
00093    * @class Object
00094    *
00095    * @brief Implementation of a CORBA object reference.
00096    *
00097    * All CORBA objects, both unconstrained and locality-constrained,
00098    * inherit from this class.  The interface is defined in the CORBA
00099    * specification and the C++ mapping.
00100    */
00101   class TAO_Export Object
00102   {
00103   public:
00104 
00105     /// Destructor.
00106     virtual ~Object (void);
00107 
00108     /**
00109      * @name Spec defined methods
00110      *
00111      * These methods are defined here since they are required by the
00112      * CORBA spec in a form specified by the C++ mapping.
00113      */
00114     //@{
00115     /// Increment the ref count.
00116     static CORBA::Object_ptr _duplicate (CORBA::Object_ptr obj);
00117 
00118     /// Return a NULL object.
00119     static CORBA::Object_ptr _nil (void);
00120 
00121     /// No-op it is just here to simplify some templates.
00122     static CORBA::Object_ptr _narrow (CORBA::Object_ptr obj);
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 
00133     /// The repository ID for the most derived class, this is an
00134     /// implementation method and does no remote invocations!
00135     virtual const char* _interface_repository_id (void) const;
00136 
00137     /**
00138      * Return a (potentially non-unique) hash value for this object.
00139      * This method relies on the representation of the object
00140      * reference's private state.  Since that changes easily (when
00141      * different ORB protocols are in use) there is no default
00142      * implementation.
00143      */
00144     virtual CORBA::ULong _hash (CORBA::ULong maximum);
00145 
00146     /**
00147      * Try to determine if this object is the same as other_obj.  This
00148      * method relies on the representation of the object reference's
00149      * private state.  Since that changes easily (when different ORB
00150      * protocols are in use) there is no default implementation.
00151      */
00152     virtual CORBA::Boolean _is_equivalent (CORBA::Object_ptr other_obj);
00153 
00154 #if (TAO_HAS_MINIMUM_CORBA == 0)
00155 
00156     virtual CORBA::Boolean _non_existent (void);
00157 
00158 #if ! defined (CORBA_E_COMPACT) && ! defined (CORBA_E_MICRO)
00159     /// This method is deprecated in the CORBA 2.2 spec, we just return 0
00160     /// every time.
00161     virtual CORBA::ImplementationDef_ptr _get_implementation (void);
00162 
00163     /// Get info about the object from the Interface Repository.
00164     virtual InterfaceDef_ptr _get_interface (void);
00165 
00166     /// Get info about the object from the Interface Repository.
00167     virtual CORBA::Object_ptr _get_component (void);
00168 #endif
00169 
00170     /// Get the repository id.
00171     virtual char * _repository_id (void);
00172 
00173 #if ! defined (CORBA_E_COMPACT) && ! defined (CORBA_E_MICRO)
00174     // DII operations to create a request.
00175     //
00176     // The mapping for create_request is split into two forms,
00177     // corresponding to the two usage styles described in CORBA
00178     // section 6.2.1.
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::Request_ptr &request,
00185                                   CORBA::Flags req_flags);
00186 
00187     virtual void _create_request (CORBA::Context_ptr ctx,
00188                                   const char *operation,
00189                                   CORBA::NVList_ptr arg_list,
00190                                   CORBA::NamedValue_ptr result,
00191                                   CORBA::ExceptionList_ptr exclist,
00192                                   CORBA::ContextList_ptr ctxtlist,
00193                                   CORBA::Request_ptr &request,
00194                                   CORBA::Flags req_flags);
00195 #endif
00196 
00197     // The default implementation of this method uses the same simple,
00198     // multi-protocol remote invocation interface as is assumed by the
00199     // calls above ... that's how it can have a default
00200     // implementation.
00201 
00202     /// DII operation to create a request.
00203     virtual CORBA::Request_ptr _request (const char *operation);
00204 
00205 #endif /* TAO_HAS_MINIMUM_CORBA */
00206 
00207 #if (TAO_HAS_CORBA_MESSAGING == 1)
00208 
00209     CORBA::Policy_ptr _get_policy (CORBA::PolicyType type);
00210 
00211     CORBA::Policy_ptr _get_cached_policy (TAO_Cached_Policy_Type type);
00212 
00213     CORBA::Object_ptr _set_policy_overrides (
00214       const CORBA::PolicyList & policies,
00215       CORBA::SetOverrideType set_add);
00216 
00217     CORBA::PolicyList * _get_policy_overrides (
00218       const CORBA::PolicyTypeSeq & types);
00219 
00220     CORBA::Boolean _validate_connection (
00221       CORBA::PolicyList_out inconsistent_policies);
00222 
00223 #endif /* TAO_HAS_CORBA_MESSAGING == 1 */
00224 
00225     virtual CORBA::ORB_ptr _get_orb (void);
00226 
00227     /**
00228      * @name Reference Count Managment
00229      *
00230      * These are the standard CORBA object reference count manipulations
00231      * methods.
00232      */
00233     //@{
00234     /// Increment the reference count.
00235     virtual void _add_ref (void);
00236 
00237     /// Decrement the reference count.
00238     virtual void _remove_ref (void);
00239     //@}
00240 
00241     // Useful for template programming.
00242     typedef Object_ptr _ptr_type;
00243     typedef Object_var _var_type;
00244     typedef Object_out _out_type;
00245 
00246     //@} End of CORBA specific methods
00247 
00248 
00249     /**
00250      * @name Methods that are TAO specific.
00251      *
00252      * These methods are defined here as helper functions to be used
00253      * by other parts of TAO. Theoretically they shold all start with
00254      * tao_. But we have deviated from that principle.
00255      */
00256 
00257   protected:
00258     void _tao_actual_add_ref (void);
00259     void _tao_actual_remove_ref (void);
00260 
00261   public:
00262     /// Marshalling operator used by the stub code. A long story why
00263     /// the stub code uses this, let us keep it short here.
00264     static CORBA::Boolean marshal (const Object_ptr x,
00265                                    TAO_OutputCDR &cdr);
00266 
00267     /// Accessor for the cached servant reference held on the stub
00268     /// if this object is collocated
00269     virtual TAO_Abstract_ServantBase *_servant (void) const;
00270 
00271     /// Is this object collocated with the servant?
00272     /// Note this does not return this->is_collocated_ but will instead
00273     /// query the underlying stub for its collocation status
00274     virtual CORBA::Boolean _is_collocated (void) const;
00275 
00276     /// Is this a local object?
00277     virtual CORBA::Boolean _is_local (void) const;
00278 
00279     /// Used in the implementation of CORBA::Any
00280     static void _tao_any_destructor (void*);
00281 
00282     /// Uninlined part of the now-inlined CORBA::is_nil().
00283     static CORBA::Boolean is_nil_i (CORBA::Object_ptr obj);
00284 
00285     /// Helper function for reading contents of an IOR
00286     static void tao_object_initialize (Object *);
00287 
00288     /// Return the object key as an out parameter.  Caller should release
00289     /// return value when finished with it.
00290     virtual TAO::ObjectKey *_key (void);
00291 
00292     /// Constructor
00293     Object (TAO_Stub *p,
00294             CORBA::Boolean collocated = 0,
00295             TAO_Abstract_ServantBase *servant = 0,
00296             TAO_ORB_Core *orb_core = 0);
00297 
00298     Object (IOP::IOR *ior, TAO_ORB_Core *orb_core = 0);
00299 
00300     /// Get the underlying stub object.
00301     virtual TAO_Stub *_stubobj (void) const;
00302     virtual TAO_Stub *_stubobj (void);
00303 
00304     /// Set the proxy broker.
00305     virtual void _proxy_broker (TAO::Object_Proxy_Broker *proxy_broker);
00306 
00307   public:
00308 
00309     /// Allows us to forbid marshaling of local interfaces.
00310     virtual CORBA::Boolean marshal (TAO_OutputCDR &cdr);
00311 
00312 #if defined (GEN_OSTREAM_OPS)
00313 
00314     /// Used by optionally generated ostream operators for interface
00315     /// to output the actual repo id for debugging.
00316     static std::ostream& _tao_stream (std::ostream &strm,
00317                                       const Object_ptr _tao_objref);
00318     virtual std::ostream& _tao_stream_v (std::ostream &strm) const;
00319 
00320 #endif /* GEN_OSTREAM_OPS */
00321 
00322     /// Accessor to the flag..
00323     CORBA::Boolean is_evaluated (void) const;
00324 
00325     /// Mutator for setting the servant in collocated cases.
00326     /**
00327      * This is used by the Object_Adapter to set the servant for
00328      * collocated cases and only when the object is initialized. The
00329      * object initialization takes place when IOR's are lazily
00330      * evaluated.
00331      */
00332     void set_collocated_servant (TAO_Abstract_ServantBase *);
00333 
00334     /// Accessor for the ORB_Core..
00335     TAO_ORB_Core *orb_core (void) const;
00336 
00337     /// Accessors for the underlying IOP::IOR's.
00338     /**
00339      * The steal_ior () call basically relinquishes the ownership of
00340      * the IOR. This is useful for cases when one wants to initialize
00341      * a new CORBA Object
00342      */
00343     IOP::IOR *steal_ior (void);
00344 
00345     const IOP::IOR &ior (void) const;
00346 
00347     //@} End of TAO-specific methods..
00348 
00349     /// Can this object be stringified?
00350     virtual bool can_convert_to_ior (void) const;
00351 
00352     /// A hook to allow users to provide custom object stringification.
00353     /// @note This method is intended to be used by classes that
00354     /// implement Smart Proxies and no others.
00355     virtual char* convert_to_ior (bool use_omg_ior_format,
00356                                   const char* ior_prefix) const;
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     /// Number of outstanding references to this object.
00368     TAO_Configurable_Refcount refcount_;
00369 
00370   private:
00371 
00372     // = Unimplemented methods
00373     Object (const Object &);
00374     Object &operator = (const Object &);
00375 
00376   private:
00377 
00378     /// Specify whether this is a local object or not.
00379     CORBA::Boolean is_local_;
00380 
00381     /// Flag to indicate whether the IOP::IOR has been evaluated fully.
00382     CORBA::Boolean is_evaluated_;
00383 
00384     /// If the IOR hasnt been evaluated fully, then the contents of
00385     /// the IOR that we received  should be in here!
00386     IOP::IOR_var ior_;
00387 
00388     /// Cached pointer of our ORB_Core
00389     /**
00390      * Be aware that this pointer can be zero or not. In fact there are two
00391      * ways to get this pointer filled:
00392      * - If CORBA::Object is constructed through one of the constructors with a
00393      * stub and null ORB_Core, we use the orb_core from the stub to fill
00394      * this pointer
00395      * - If the other constructor, which uses IOP::IOR is used, a stub
00396      * needs to be created first (i.e., the IOR needs to be evaluated first),
00397      * in which case the ORB_Core would be null. The orb_core pointer then
00398      * needs to be accessed from the stub and passed back as part of
00399      * _get_orb().
00400      */
00401     TAO_ORB_Core * orb_core_;
00402 
00403     /**
00404      * Pointer to the protocol-specific "object" containing important
00405      * profiling information regarding this proxy.
00406      * The protocol proxy is (potentially) shared among several
00407      * Objects
00408      */
00409     TAO_Stub * protocol_proxy_;
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 * object_init_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   template<>
00445   struct TAO_Export In_Object_Argument_Cloner_T<CORBA::InterfaceDef_ptr>
00446   {
00447     static void duplicate(CORBA::InterfaceDef_ptr objref);
00448     static void release(CORBA::InterfaceDef_ptr objref);
00449   };
00450 }
00451 
00452 /// This function pointer is set only when the Portable server
00453 /// library is present.
00454 extern
00455   TAO_Export TAO::Object_Proxy_Broker *
00456   (*_TAO_Object_Proxy_Broker_Factory_function_pointer) (void);
00457 
00458 TAO_Export CORBA::Boolean
00459 operator<< (TAO_OutputCDR&, const CORBA::Object*);
00460 
00461 TAO_Export CORBA::Boolean
00462 operator>> (TAO_InputCDR&, CORBA::Object *&);
00463 
00464 #if defined (GEN_OSTREAM_OPS)
00465 
00466 TAO_Export std::ostream&
00467 operator<< (std::ostream&, CORBA::Object_ptr);
00468 
00469 #endif /* GEN_OSTREAM_OPS */
00470 
00471 TAO_END_VERSIONED_NAMESPACE_DECL
00472 
00473 #if defined (__ACE_INLINE__)
00474 # include "tao/Object.inl"
00475 #endif /* __ACE_INLINE__ */
00476 
00477 #include /**/ "ace/post.h"
00478 #endif /* TAO_CORBA_OBJECT_H */

Generated on Sun Jan 27 13:07:34 2008 for TAO by doxygen 1.3.6