NVList.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    NVList.h
00006  *
00007  *  $Id: NVList.h 77768 2007-03-22 19:53:25Z johnnyw $
00008  *
00009  *  @author  Copyright 1994-1995 by Sun Microsystems Inc.
00010  *  @author  Aniruddha Gokhale <gokhale@cs.wustl.edu>
00011  */
00012 //=============================================================================
00013 
00014 
00015 #ifndef TAO_NVLIST_H
00016 #define TAO_NVLIST_H
00017 
00018 #include /**/ "ace/pre.h"
00019 
00020 #include "ace/Unbounded_Queue.h"
00021 
00022 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00023 # pragma once
00024 #endif /* ACE_LACKS_PRAGMA_ONCE */
00025 
00026 #include "tao/AnyTypeCode/AnyTypeCode_methods.h"
00027 #include "tao/AnyTypeCode/Any.h"
00028 #include "tao/AnyTypeCode/NVList_Adapter_Impl.h"
00029 
00030 #include "ace/Unbounded_Queue.h"
00031 #include "ace/Thread_Mutex.h"
00032 #include "ace/Atomic_Op.h"
00033 
00034 
00035 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00036 
00037 class TAO_InputCDR;
00038 
00039 namespace CORBA
00040 {
00041   enum
00042   {
00043     // = Flags for NVList add methods
00044     ARG_IN                  = 0x01,
00045     ARG_OUT                 = 0x02,
00046     ARG_INOUT               = 0x04,
00047     IN_COPY_VALUE           = 0x08,
00048     OUT_LIST_MEMORY         = 0x10,
00049     DEPENDENT_LIST          = 0x20,
00050 
00051     // = (Unused) flags for Context methods
00052     CTX_RESTRICT_SCOPE      = 0x40,
00053     CTX_DELETE_DESCENDENTS  = 0x80,
00054 
00055     // = Flags for deferred synchronous methods
00056     INV_NO_RESPONSE         = 0x100,
00057     INV_TERM_ON_ERR         = 0x200,
00058     RESP_NO_WAIT            = 0x400
00059   };
00060 
00061   typedef TAO_Pseudo_Var_T<NamedValue> NamedValue_var;
00062   typedef TAO_Pseudo_Out_T<NamedValue> NamedValue_out;
00063 
00064   typedef ULong Flags;
00065 
00066   /**
00067    * @class NamedValue
00068    *
00069    * @brief CORBA Name/value pair implementation.
00070    *
00071    * These occur only in "NVList" (named value list) data structures.
00072    * The binary form of the data structure is frozen and visible to
00073    * programs using it (e.g. from C).  The C++ class supports some
00074    * programming discipline, e.g. to avoid memory leaks.  They just
00075    * represent parameters to calls.  The name is optional, and the
00076    * value is packaged as an Any.  The flags indicate parameter mode,
00077    * and some ownership rules for "top level" memory.
00078    */
00079   class TAO_AnyTypeCode_Export NamedValue
00080   {
00081     friend class ::TAO_NVList_Adapter_Impl;
00082     friend class NVList;
00083     friend class Request;
00084 
00085   public:
00086     /// optional name
00087     const char * name (void) const;
00088 
00089     /// return the value
00090     Any_ptr value (void) const;
00091 
00092     /// return the parameter mode flag
00093     Flags flags (void) const;
00094 
00095     // The pseudo object static methods..
00096     static NamedValue * _duplicate (NamedValue *);
00097     static NamedValue * _nil (void);
00098 
00099     // = Reference counting.
00100     ULong _incr_refcnt (void);
00101     ULong _decr_refcnt (void);
00102 
00103     // Useful for template programming.
00104     typedef NamedValue_ptr _ptr_type;
00105     typedef NamedValue_var _var_type;
00106     typedef NamedValue_out _out_type;
00107 
00108   protected:
00109 
00110     /// Destructor
00111     /**
00112      * Protected destructor to enforce proper memory management
00113      * through the reference counting mechanism.
00114      */
00115     ~NamedValue (void);
00116 
00117   private:
00118 
00119     /// private constructor. Cannot be directly instantiated other than
00120     /// by its friends.
00121     NamedValue (void);
00122 
00123   private:
00124 
00125     /// Reference counter.
00126     ACE_Atomic_Op<TAO_SYNCH_MUTEX, unsigned long> refcount_;
00127 
00128     /// holds the value
00129     Any any_;
00130 
00131     /// parameter mode flags
00132     Flags flags_;
00133 
00134     /// optional IDL name of the parameter
00135     char * name_;
00136   };
00137 
00138   // ****************************************************************
00139 
00140   typedef TAO_Pseudo_Var_T<NVList> NVList_var;
00141   typedef TAO_Pseudo_Out_T<NVList> NVList_out;
00142 
00143   /**
00144    * @class NVList
00145    *
00146    * @brief CORBA::NVList implementation.
00147 
00148    * This is used in the (client side) DII (Dynamic Invocation
00149    * Interface) to hold parameters, except for the return
00150    * parameter. It's used in the same role in the (server side) DSI
00151    * (Dynamic Skeleton Interface).
00152    *
00153    * Each user (client, server) provides the typecode and memory for
00154    * each parameter using an NVList, then talks to the ORB using a
00155    * Request or ServerRequest pseudo-object.  The ORB copies data
00156    * to/from the IPC messages (e.g. IIOP::Request, IIOP::Response)
00157    * as appropriate.
00158    */
00159   class TAO_AnyTypeCode_Export NVList
00160   {
00161     friend class ::TAO_NVList_Adapter_Impl;
00162     friend class Request;
00163 
00164   public:
00165 
00166     /// return the current number of elements in the list
00167     ULong count (void) const;
00168 
00169     /// add an element and just initialize the flags
00170     NamedValue_ptr add (Flags);
00171 
00172     /// add an element and initialize its name and flags
00173     NamedValue_ptr add_item (const char *, Flags);
00174 
00175     /// initializes a value, name, and flags
00176     NamedValue_ptr add_value (const char *, const Any &, Flags);
00177 
00178     /// just like add_item. In addition, memory management of char *
00179     /// name is taken over by the NVList
00180     NamedValue_ptr add_item_consume (char *, Flags);
00181 
00182     /// just like add_value. In addition, the NVList controls the
00183     /// memory management of the char *name and Any *value parameter
00184     NamedValue_ptr add_value_consume (char *, Any_ptr, Flags);
00185 
00186     /// retrieve the item at the nth location. Raises Bounds
00187     NamedValue_ptr item (ULong n);
00188 
00189     //  CORBA::Status
00190     /// remove element at index n. Raises Bounds
00191     void remove (ULong n);
00192 
00193     // The pseudo object static methods..
00194     static NVList * _duplicate (NVList *);
00195     static NVList * _nil (void);
00196 
00197     // = Reference counting.
00198     ULong _incr_refcnt (void);
00199     ULong _decr_refcnt (void);
00200 
00201     // = TAO Extensions:
00202 
00203     /**
00204      * Set the incoming CDR stream, this is used by TAO to perform lazy
00205      * evaluation of the NVList in an incoming ServerRequest.
00206      * The <flag> is used to check which parameters (IN, OUT and/or
00207      * INOUT) are to be extracted
00208      */
00209     void _tao_incoming_cdr (TAO_InputCDR & cdr,
00210                             int flag,
00211                             bool &lazy_evaluation);
00212 
00213     /// Encode the NVList into the CDR stream. @a flag masks the type of
00214     /// arguments (IN, OUT or INOUT) that are to be marshaled.
00215     void _tao_encode (TAO_OutputCDR & cdr, int flag);
00216 
00217     /// Decode the NVList arguments from the @a cdr stream.
00218     void _tao_decode (TAO_InputCDR & cdr, int flag);
00219 
00220     /**
00221      * Return the required alignment to marshal the NVList without any
00222      * re-alignment.
00223      * It returns ACE_CDR::MAX_ALIGNMENT to indicate errors.
00224      */
00225     ptrdiff_t _tao_target_alignment (void);
00226 
00227     /**
00228      * If this list is used by a DII request, this will tell us if
00229      * our CDR stream contains any marshaled arguments (needed for
00230      * GIOP 1.2).
00231      */
00232     Boolean _lazy_has_arguments (void) const;
00233 
00234     // Useful for template programming.
00235     typedef NVList_ptr _ptr_type;
00236     typedef NVList_var _var_type;
00237     typedef NVList_out _out_type;
00238 
00239   protected:
00240 
00241     /// Destructor
00242     /**
00243      * Protected destructor to enforce proper memory management
00244      * through the reference counting mechanism.
00245      */
00246     ~NVList (void);
00247 
00248   private:
00249     /// Constructor - cannot be instantiated directly other than
00250     /// through the CORBA::ORB::create_list method
00251     NVList (void);
00252 
00253     /// Helper to increase the list size. This is used by all the add_
00254     /// methods of the NVList class
00255     NamedValue_ptr add_element (Flags);
00256 
00257     /// Lazy evaluation routine to fill up the Anys in the NVList from
00258     /// the CDR stream.
00259     void evaluate (void);
00260 
00261   private:
00262     /// Internal list of parameters stored as NamedValues
00263     ACE_Unbounded_Queue<NamedValue_ptr> values_;
00264 
00265     /// Maximum length of list
00266     ULong max_;
00267 
00268     /// Reference counter.
00269     ACE_Atomic_Op<TAO_SYNCH_MUTEX, unsigned long> refcount_;
00270 
00271     /// Protects the incoming pointer.
00272     TAO_SYNCH_MUTEX lock_;
00273 
00274     /**
00275      * When the NVList is used as part of a Server Request we can simply
00276      * store the CDR buffer and perform lazy evaluation to compute the
00277      * Anys.
00278      */
00279     TAO_InputCDR * incoming_;
00280 
00281     /// The flags used to check which parameters are actually extracted
00282     /// from the <incoming_> buffer
00283     int incoming_flag_;
00284   };
00285 }
00286 
00287 TAO_END_VERSIONED_NAMESPACE_DECL
00288 
00289 #if defined (__ACE_INLINE__)
00290 # include "tao/AnyTypeCode/NVList.inl"
00291 #endif /* __ACE_INLINE__ */
00292 
00293 #include /**/ "ace/post.h"
00294 #endif /* TAO_NVLIST_H */

Generated on Sun Jan 27 13:21:06 2008 for TAO_AnyTypeCode by doxygen 1.3.6