CDR.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    CDR.h
00006  *
00007  *  CDR.h,v 1.75 2006/04/20 12:37:17 jwillemsen Exp
00008  *
00009  *   Common Data Representation (CDR) marshaling streams.
00010  *
00011  *   This implementation assumes that the native numeric
00012  *   representation is two's complement for integers, IEEE
00013  *   single/double for floats.  Also that characters are in ISO
00014  *   Latin/1.
00015  *
00016  *   Note that CDR itself makes no such assumptions, but this
00017  *   implementation makes such assumptions for reasons of
00018  *   efficiency.  Careful enhancements could preserve that
00019  *   efficiency where the assumptions are true, yet still allow the
00020  *   code to work when they aren't true.
00021  *
00022  *   The implementation expects that buffers are aligned according
00023  *   to the strongest CDR alignment restriction.
00024  *
00025  *   NOTE: this does everything "CDR 1.1" does ... that is, it
00026  *   supports the five extended OMG-IDL data types in UNO Appendix
00027  *   A, which provide richer arithmetic types (64 bit integers,
00028  *   "quad precision" FP) and UNICODE-based characters and strings.
00029  *   Those types are not standard parts of OMG-IDL at this time.
00030  *
00031  *   THREADING NOTE: CDR data structures must be protected against
00032  *   concurrent access by their owning thread.
00033  *
00034  *
00035  *  @author  Copyright 1994-1995 by Sun Microsystems Inc.
00036  *  @author  Aniruddha Gokhale
00037  *  @author  Carlos O'Ryan
00038  */
00039 //=============================================================================
00040 
00041 
00042 #ifndef TAO_CDR_H
00043 #define TAO_CDR_H
00044 
00045 #include /**/ "ace/pre.h"
00046 
00047 #include "tao/orbconf.h"
00048 
00049 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00050 # pragma once
00051 #endif /* ACE_LACKS_PRAGMA_ONCE */
00052 
00053 #include "tao/TAO_Export.h"
00054 #include "tao/Basic_Types.h"
00055 
00056 #include "ace/CORBA_macros.h"
00057 #include "ace/CDR_Stream.h"
00058 
00059 
00060 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00061 
00062 class TAO_ORB_Core;
00063 class TAO_GIOP_Fragmentation_Strategy;
00064 class TAO_Stub;
00065 
00066 namespace CORBA
00067 {
00068   class Environment;
00069 }
00070 
00071 /**
00072  * @class TAO_OutputCDR
00073  *
00074  * @brief A CDR stream for writing, i.e. for marshalling.
00075  *
00076  * This class is based on the the CORBA spec for Java (98-02-29),
00077  * java class omg.org.CORBA.portable.OutputStream.
00078  * It diverts in a few ways:
00079  * + Operations taking arrays don't have offsets, because in C++
00080  * it is easier to describe an array starting from x+offset.
00081  * + Operations return an error status, because exceptions are
00082  * not widely available in C++ (yet).
00083  * A particularly useful static member function for this buffer is
00084  * an interpretive encoding routine, usable as a typecode
00085  * interpreter callback.  Ditto for decoding.  These are used to
00086  * support all OMG-IDL datatypes, even those not supported
00087  * directly by put/get primitives.
00088  */
00089 class TAO_Export TAO_OutputCDR : public ACE_OutputCDR
00090 {
00091 public:
00092   /// For reading from a output CDR stream.
00093   friend class TAO_InputCDR;
00094 
00095   // The default values for the allocators and memcpy_tradeoff
00096   // in these constructors are not 0, but are generated by the
00097   // ORB. Refer to the constructor bodies in CDR.cpp for the
00098   // code that supplies these values to the base class constructor.
00099 
00100   /// Default constructor, allocates <size> bytes in the internal
00101   /// buffer, if <size> == 0 it allocates the default size.
00102   TAO_OutputCDR (size_t size = 0,
00103                  int byte_order = ACE_CDR_BYTE_ORDER,
00104                  ACE_Allocator* buffer_allocator = 0,
00105                  ACE_Allocator* data_block_allocator = 0,
00106                  ACE_Allocator* message_block_allocator = 0,
00107                  size_t memcpy_tradeoff = 0,
00108                  ACE_CDR::Octet major_version =
00109                    TAO_DEF_GIOP_MAJOR,
00110                  ACE_CDR::Octet minor_version =
00111                    TAO_DEF_GIOP_MINOR);
00112 
00113   /// Build a CDR stream with an initial buffer, it will *not* remove
00114   /// <data>, since it did not allocated it.
00115   TAO_OutputCDR (char *data,
00116                  size_t size,
00117                  int byte_order = ACE_CDR_BYTE_ORDER,
00118                  ACE_Allocator* buffer_allocator = 0,
00119                  ACE_Allocator* data_block_allocator = 0,
00120                  ACE_Allocator* message_block_allocator = 0,
00121                  size_t memcpy_tradeoff = 0,
00122                  ACE_CDR::Octet major_version =
00123                    TAO_DEF_GIOP_MAJOR,
00124                  ACE_CDR::Octet minor_version =
00125                    TAO_DEF_GIOP_MINOR);
00126 
00127   /// Build a CDR stream with an initial buffer, it will *not* remove
00128   /// @a data since it did not allocated it, and enable fragmentation
00129   /// support.
00130   TAO_OutputCDR (char *data,
00131                  size_t size,
00132                  int byte_order,
00133                  ACE_Allocator* buffer_allocator,
00134                  ACE_Allocator* data_block_allocator,
00135                  ACE_Allocator* message_block_allocator,
00136                  size_t memcpy_tradeoff,
00137                  TAO_GIOP_Fragmentation_Strategy * fs,
00138                  ACE_CDR::Octet major_version,
00139                  ACE_CDR::Octet minor_version);
00140 
00141   /// Build a CDR stream with an initial Message_Block chain, it will *not*
00142   /// remove <data>, since it did not allocate it.
00143   TAO_OutputCDR (ACE_Message_Block *data,
00144                  int byte_order = ACE_CDR_BYTE_ORDER,
00145                  size_t memcpy_tradeoff = 0,
00146                  ACE_CDR::Octet major_version =
00147                    TAO_DEF_GIOP_MAJOR,
00148                  ACE_CDR::Octet minor_version =
00149                    TAO_DEF_GIOP_MINOR);
00150 
00151   /// Destructor.
00152   ~TAO_OutputCDR (void);
00153 
00154   // @todo do we want a special method to write an array of
00155   // strings and wstrings?
00156 
00157   // = TAO specific methods.
00158   static void throw_stub_exception (int error_num ACE_ENV_ARG_DECL);
00159   static void throw_skel_exception (int error_num ACE_ENV_ARG_DECL);
00160 
00161   /**
00162    * @name Outgoing GIOP Fragment Related Methods
00163    *
00164    * These methods are only used when fragmenting outgoing GIOP
00165    * requests and replies.
00166    */
00167   //@{
00168   /// Fragment this output CDR stream if necessary.
00169   /**
00170    * Fragmentation will done through GIOP fragments when the length of
00171    * the CDR stream length will exceed the configured threshold.
00172    */
00173   bool fragment_stream (ACE_CDR::ULong pending_alignment,
00174                         ACE_CDR::ULong pending_length);
00175 
00176   /// Are there more data fragments to come?
00177   bool more_fragments (void) const;
00178 
00179   /// Specify whether there are more data fragments to come.
00180   void more_fragments (bool more);
00181 
00182   /// Set fragmented message attributes.
00183   void message_attributes (CORBA::ULong request_id,
00184                            TAO_Stub * stub,
00185                            int message_semantics,
00186                            ACE_Time_Value * timeout);
00187 
00188   /// Fragmented message request ID.
00189   CORBA::ULong request_id (void) const;
00190 
00191   /// Stub object associated with the request.
00192   TAO_Stub * stub (void) const;
00193 
00194   /// Message semantics (twoway, oneway, reply)
00195   int message_semantics (void) const;
00196 
00197   /// Maximum time to wait for outgoing message to be sent.
00198   ACE_Time_Value * timeout (void) const;
00199   //@}
00200 
00201 private:
00202 
00203   // disallow copying...
00204   TAO_OutputCDR (const TAO_OutputCDR& rhs);
00205   TAO_OutputCDR& operator= (const TAO_OutputCDR& rhs);
00206 
00207 private:
00208 
00209   /**
00210    * @name Outgoing GIOP Fragment Related Attributes
00211    *
00212    * These attributes are only used when fragmenting outgoing GIOP
00213    * requests and replies.
00214    */
00215   //@{
00216   /// Strategy that sends data currently marshaled into this
00217   /// TAO_OutputCDR stream if necessary.
00218   TAO_GIOP_Fragmentation_Strategy * const fragmentation_strategy_;
00219 
00220   /// Are there more data fragments to come?
00221   bool more_fragments_;
00222 
00223   /// Request ID for the request currently being marshaled.
00224   CORBA::ULong request_id_;
00225 
00226   /// Stub object associated with the request.
00227   TAO_Stub * stub_;
00228 
00229   /// Twoway, oneway, reply?
00230   /**
00231    * @see TAO_Transport
00232    */
00233   int message_semantics_;
00234 
00235   /// Request/reply send timeout.
00236   ACE_Time_Value * timeout_;
00237   //@}
00238 
00239 };
00240 
00241 /**
00242  * @class TAO_InputCDR
00243  *
00244  * @brief A CDR stream for reading, i.e. for demarshalling.
00245  *
00246  * This class is based on the the CORBA spec for Java (98-02-29),
00247  * java class omg.org.CORBA.portable.InputStream.
00248  * It diverts in a few ways:
00249  * + Operations to retrieve basic types take parameters by
00250  * reference.
00251  * + Operations taking arrays don't have offsets, because in C++
00252  * it is easier to describe an array starting from x+offset.
00253  * + Operations return an error status, because exceptions are
00254  * not widely available in C++ (yet).
00255  * A particularly useful static member function for this buffer is
00256  * an interpretive encoding routine, usable as a typecode
00257  * interpreter callback.  Ditto for decoding.  These are used to
00258  * support all OMG-IDL datatypes, even those not supported
00259  * directly by put/get primitives.
00260  */
00261 class TAO_Export TAO_InputCDR : public ACE_InputCDR
00262 {
00263 public:
00264   /**
00265    * Create an input stream from an arbitrary buffer, care must be
00266    * exercised wrt alignment, because this contructor will *not* work
00267    * if the buffer is unproperly aligned.
00268    */
00269   TAO_InputCDR (const char* buf,
00270                 size_t bufsiz,
00271                 int byte_order = ACE_CDR_BYTE_ORDER,
00272                 ACE_CDR::Octet major_version =
00273                   TAO_DEF_GIOP_MAJOR,
00274                 ACE_CDR::Octet minor_version =
00275                   TAO_DEF_GIOP_MINOR,
00276                 TAO_ORB_Core* orb_core = 0);
00277 
00278   /// Create an empty input stream. The caller is responsible for
00279   /// putting the right data and providing the right alignment.
00280   TAO_InputCDR (size_t bufsiz,
00281                 int byte_order = ACE_CDR_BYTE_ORDER,
00282                 ACE_CDR::Octet major_version =
00283                   TAO_DEF_GIOP_MAJOR,
00284                 ACE_CDR::Octet minor_version =
00285                   TAO_DEF_GIOP_MINOR,
00286                 TAO_ORB_Core* orb_core = 0);
00287 
00288   /// Create an input stream from an ACE_Message_Block
00289   TAO_InputCDR (const ACE_Message_Block *data,
00290                 int byte_order = ACE_CDR_BYTE_ORDER,
00291                 ACE_CDR::Octet major_version =
00292                   TAO_DEF_GIOP_MAJOR,
00293                 ACE_CDR::Octet minor_version =
00294                   TAO_DEF_GIOP_MINOR,
00295                 TAO_ORB_Core* orb_core = 0);
00296 
00297   /// Create an input stream from an ACE_Message_Block with an optional lock
00298   /// used to protect the data.
00299   TAO_InputCDR (const ACE_Message_Block *data,
00300                 ACE_Lock* lock,
00301                 int byte_order = ACE_CDR_BYTE_ORDER,
00302                 ACE_CDR::Octet major_version = TAO_DEF_GIOP_MAJOR,
00303                 ACE_CDR::Octet minor_version = TAO_DEF_GIOP_MINOR,
00304                 TAO_ORB_Core* orb_core = 0);
00305 
00306 
00307   /// Create an input stream from an ACE_Data_Block
00308   TAO_InputCDR (ACE_Data_Block *data,
00309                 ACE_Message_Block::Message_Flags flag = 0,
00310                 int byte_order = ACE_CDR_BYTE_ORDER,
00311                 ACE_CDR::Octet major_version =
00312                   TAO_DEF_GIOP_MAJOR,
00313                 ACE_CDR::Octet minor_version =
00314                   TAO_DEF_GIOP_MINOR,
00315                 TAO_ORB_Core* orb_core = 0);
00316 
00317   /// Create an input stream from an ACE_Data_Block
00318   TAO_InputCDR (ACE_Data_Block *data,
00319                 ACE_Message_Block::Message_Flags flag,
00320                 size_t read_pointer_position,
00321                 size_t write_pointer_position,
00322                 int byte_order = ACE_CDR_BYTE_ORDER,
00323                 ACE_CDR::Octet major_version =
00324                   TAO_DEF_GIOP_MAJOR,
00325                 ACE_CDR::Octet minor_version =
00326                   TAO_DEF_GIOP_MINOR,
00327                 TAO_ORB_Core* orb_core = 0);
00328 
00329   /**
00330    * Make a copy of the current stream state, but does not copy the
00331    * internal buffer; so the same stream can be read multiple times
00332    * efficiently.
00333    */
00334   TAO_InputCDR (const TAO_InputCDR& rhs);
00335 
00336   /// When interpreting indirected TypeCodes it is useful to make a
00337   /// "copy" of the stream starting in the new position.
00338   TAO_InputCDR (const TAO_InputCDR& rhs,
00339                 size_t size,
00340                 ACE_CDR::Long offset);
00341   /**
00342    * This creates an encapsulated stream, the first byte must be (per
00343    * the spec) the byte order of the encapsulation.  The default
00344    * values for the allocators in this constructor are not 0, but are
00345    * generated by the ORB. Refer to the constructor body in CDR.cpp
00346    * for the code that supplies these values to the base class
00347    * constructor.
00348    */
00349   TAO_InputCDR (const TAO_InputCDR& rhs,
00350                 size_t size);
00351 
00352   /// Create an input CDR from an output CDR.
00353   TAO_InputCDR (const TAO_OutputCDR& rhs,
00354                 ACE_Allocator* buffer_allocator = 0,
00355                 ACE_Allocator* data_block_allocator = 0,
00356                 ACE_Allocator* message_block_allocator = 0,
00357                 TAO_ORB_Core* orb_core = 0);
00358 
00359   /// Initialize the contents of one CDR from another, without data
00360   /// copying and with minimimum locking overhead.
00361   TAO_InputCDR (ACE_InputCDR::Transfer_Contents rhs,
00362                 TAO_ORB_Core* orb_core = 0);
00363 
00364   /// destructor
00365   ~TAO_InputCDR (void);
00366 
00367   // = TAO specific methods.
00368 
00369   /// Accessor
00370   TAO_ORB_Core *orb_core (void) const;
00371 
00372   ACE_Message_Block::Message_Flags
00373     clr_mb_flags( ACE_Message_Block::Message_Flags less_flags );
00374 
00375   // = TAO specific methods.
00376   static void throw_stub_exception (int error_num ACE_ENV_ARG_DECL);
00377   static void throw_skel_exception (int error_num ACE_ENV_ARG_DECL);
00378 
00379 private:
00380   /// The ORB_Core, required to extract object references.
00381   TAO_ORB_Core* orb_core_;
00382 };
00383 
00384 TAO_END_VERSIONED_NAMESPACE_DECL
00385 
00386 #if defined(__ACE_INLINE__)
00387 # include "tao/CDR.i"
00388 #else
00389 
00390 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00391 
00392 // CDR output operators for CORBA types
00393 
00394 TAO_Export CORBA::Boolean operator<< (TAO_OutputCDR &os,
00395                                       CORBA::Short x);
00396 TAO_Export CORBA::Boolean operator<< (TAO_OutputCDR &os,
00397                                       CORBA::UShort x);
00398 TAO_Export CORBA::Boolean operator<< (TAO_OutputCDR &os,
00399                                       CORBA::Long x);
00400 TAO_Export CORBA::Boolean operator<< (TAO_OutputCDR &os,
00401                                       CORBA::ULong x);
00402 TAO_Export CORBA::Boolean operator<< (TAO_OutputCDR &os,
00403                                       CORBA::LongLong x);
00404 TAO_Export CORBA::Boolean operator<< (TAO_OutputCDR &os,
00405                                       CORBA::ULongLong x);
00406 TAO_Export CORBA::Boolean operator<< (TAO_OutputCDR& os,
00407                                       CORBA::LongDouble x);
00408 TAO_Export CORBA::Boolean operator<< (TAO_OutputCDR &os,
00409                                       CORBA::Float x);
00410 TAO_Export CORBA::Boolean operator<< (TAO_OutputCDR &os,
00411                                       CORBA::Double x);
00412 TAO_Export CORBA::Boolean operator<< (TAO_OutputCDR &os,
00413                                       const CORBA::Char* x);
00414 TAO_Export CORBA::Boolean operator<< (TAO_OutputCDR &os,
00415                                       const CORBA::WChar* x);
00416 
00417 // CDR input operators for CORBA types
00418 
00419 TAO_Export CORBA::Boolean operator>> (TAO_InputCDR &is,
00420                                       CORBA::Short &x);
00421 TAO_Export CORBA::Boolean operator>> (TAO_InputCDR &is,
00422                                       CORBA::UShort &x);
00423 TAO_Export CORBA::Boolean operator>> (TAO_InputCDR &is,
00424                                       CORBA::Long &x);
00425 TAO_Export CORBA::Boolean operator>> (TAO_InputCDR &is,
00426                                       CORBA::ULong &x);
00427 TAO_Export CORBA::Boolean operator>> (TAO_InputCDR &is,
00428                                       CORBA::LongLong &x);
00429 TAO_Export CORBA::Boolean operator>> (TAO_InputCDR &is,
00430                                       CORBA::ULongLong &x);
00431 TAO_Export CORBA::Boolean operator>> (TAO_InputCDR &is,
00432                                       CORBA::LongDouble &x);
00433 TAO_Export CORBA::Boolean operator>> (TAO_InputCDR &is,
00434                                       CORBA::Float &x);
00435 TAO_Export CORBA::Boolean operator>> (TAO_InputCDR &is,
00436                                       CORBA::Double &x);
00437 TAO_Export CORBA::Boolean operator>> (TAO_InputCDR &is,
00438                                       CORBA::Char* &x);
00439 TAO_Export CORBA::Boolean operator>> (TAO_InputCDR &is,
00440                                       CORBA::WChar* &x);
00441 
00442 TAO_END_VERSIONED_NAMESPACE_DECL
00443 
00444 #endif /* __ACE_INLINE */
00445 
00446 #include /**/ "ace/post.h"
00447 #endif /* TAO_CDR_H */

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