GIOP_Message_Base.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // ===================================================================
00004 /**
00005  *  @file GIOP_Message_Base.h
00006  *
00007  *  $Id: GIOP_Message_Base.h 80140 2007-11-30 00:40:17Z jtc $
00008  *
00009  *  @author Initially Copyrighted by Sun Microsystems Inc., 1994-1995,
00010  *  @author modified by Balachandran Natarajan <bala@cs.wustl.edu>
00011  */
00012 // ===================================================================
00013 
00014 #ifndef TAO_GIOP_MESSAGE_BASE_H
00015 #define TAO_GIOP_MESSAGE_BASE_H
00016 
00017 #include /**/ "ace/pre.h"
00018 
00019 #include /**/ "tao/TAO_Export.h"
00020 
00021 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00022 # pragma once
00023 #endif /* ACE_LACKS_PRAGMA_ONCE */
00024 
00025 #include "tao/Exception.h"
00026 #include "tao/Pluggable_Messaging_Utils.h"
00027 #include "tao/GIOP_Message_Generator_Parser_Impl.h"
00028 #include "tao/GIOP_Utils.h"
00029 #include "tao/GIOP_Message_State.h"
00030 #include "tao/GIOP_Fragmentation_Strategy.h"
00031 #include "tao/CDR.h"
00032 #include "tao/Incoming_Message_Stack.h"
00033 
00034 #include "ace/Auto_Ptr.h"
00035 
00036 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00037 
00038 class TAO_Pluggable_Reply_Params;
00039 class TAO_Queued_Data;
00040 
00041 /**
00042  * @class TAO_GIOP_Message_Base
00043  *
00044  * @brief Definitions of the GIOP specific stuff.
00045  *
00046  * This class will hold the specific details common to all the GIOP
00047  * versions. Some of them which are here may be shifted if things
00048  * start changing between versions.
00049  */
00050 
00051 class TAO_Export TAO_GIOP_Message_Base
00052 {
00053 public:
00054   /// Constructor
00055   TAO_GIOP_Message_Base (TAO_ORB_Core *orb_core,
00056                          TAO_Transport * transport,
00057                          size_t input_cdr_size = ACE_CDR::DEFAULT_BUFSIZE);
00058 
00059   /// Dtor
00060   ~TAO_GIOP_Message_Base (void);
00061 
00062   /// Initialize the underlying state object based on the @a major and
00063   /// @a minor revision numbers
00064   void init (CORBA::Octet major, CORBA::Octet minor);
00065 
00066   /// Write the RequestHeader in to the @a cdr stream. The underlying
00067   /// implementation of the mesaging should do the right thing.
00068   int generate_request_header (TAO_Operation_Details &op,
00069                                TAO_Target_Specification &spec,
00070                                TAO_OutputCDR &cdr);
00071 
00072   /// Write the RequestHeader in to the @a cdr stream.
00073   int generate_locate_request_header (
00074       TAO_Operation_Details &op,
00075       TAO_Target_Specification &spec,
00076       TAO_OutputCDR &cdr);
00077 
00078   /// Write the reply header
00079   int generate_reply_header (
00080       TAO_OutputCDR &cdr,
00081       TAO_Pluggable_Reply_Params_Base &params);
00082 
00083   int generate_fragment_header (TAO_OutputCDR & cdr, CORBA::ULong request_id);
00084 
00085   /// Format the message. As we have not written the message length in
00086   /// the header, we make use of this oppurtunity to insert and format
00087   /// the message.
00088   int format_message (TAO_OutputCDR &cdr);
00089 
00090   /**
00091    * Parse the details of the next message from the @a incoming
00092    * and initializes attributes of @a qd.
00093    * @retval 0 If the message header could not be parsed completely,
00094    * @retval 1 If the message header could be parsed completely
00095    * @retval -1 On error.
00096    */
00097   int parse_next_message (TAO_Queued_Data &qd, size_t &mesg_length);
00098 
00099   /// Extract the details of the next message from the @a incoming
00100   /// through @a qd. Returns 0 if the message header could not be
00101   /// parsed completely, returns a 1 if the message header could be
00102   /// parsed completely and returns -1 on error.
00103   int extract_next_message (ACE_Message_Block &incoming, TAO_Queued_Data *&qd);
00104 
00105   /// Check whether the node @a qd needs consolidation from @a incoming.
00106   int consolidate_node (TAO_Queued_Data *qd, ACE_Message_Block &incoming);
00107 
00108   /// Process the request message that we have received on the
00109   /// connection
00110   int process_request_message (TAO_Transport *transport, TAO_Queued_Data *qd);
00111 
00112   /// Parse the reply message that we received and return the reply
00113   /// information through @a reply_info
00114   int process_reply_message (
00115       TAO_Pluggable_Reply_Params &reply_info,
00116       TAO_Queued_Data *qd);
00117 
00118   /// Generate a reply message with the exception @a ex.
00119   int generate_exception_reply (
00120       TAO_OutputCDR &cdr,
00121       TAO_Pluggable_Reply_Params_Base &params,
00122       const CORBA::Exception &x);
00123 
00124   /// Header length
00125   size_t header_length (void) const;
00126 
00127   /// The header length of a fragment
00128   size_t fragment_header_length (
00129     const TAO_GIOP_Message_Version& giop_version) const;
00130 
00131   TAO_OutputCDR &out_stream (void);
00132 
00133   /// Consolidate fragmented message with associated fragments, being
00134   /// stored withi this class.  If reliable transport is used (like
00135   /// TCP) fragments are partialy ordered on stack, last fragment on
00136   /// top. Otherwise If un-reliable transport is used (like UDP)
00137   /// fragments may be dis-ordered, and must be ordered before
00138   /// consolidation.  @return 0 on success and @a msg points to
00139   /// consolidated message, 1 if there are still fragmens outstanding,
00140   /// in case of error -1 is being returned. In any case @a qd must be
00141   /// released by method implementation.
00142   int consolidate_fragmented_message (TAO_Queued_Data *qd,
00143                                       TAO_Queued_Data *&msg);
00144 
00145   /// Discard all fragments associated to request-id encoded in
00146   /// cancel_request.  This operation will never be called
00147   /// concurrently by multiplpe threads nor concurrently to
00148   /// consolidate_fragmented_message @return -1 on failure, 0 on
00149   /// success, 1 no fragment on stack relating to CancelRequest.
00150   int discard_fragmented_message (const TAO_Queued_Data *cancel_request);
00151 
00152   /// Outgoing GIOP message fragmentation strategy.
00153   TAO_GIOP_Fragmentation_Strategy * fragmentation_strategy (void);
00154 
00155   /// Is the messaging object ready for processing BiDirectional
00156   /// request/response?
00157   bool is_ready_for_bidirectional (TAO_OutputCDR &msg) const;
00158 
00159 private:
00160   /// Processes the GIOP_REQUEST messages
00161   int process_request (TAO_Transport *transport,
00162                        TAO_InputCDR &input,
00163                        TAO_OutputCDR &output,
00164                        TAO_GIOP_Message_Generator_Parser *);
00165 
00166   /// Processes the GIOP_LOCATE_REQUEST messages
00167   int process_locate_request (TAO_Transport *transport,
00168                               TAO_InputCDR &input,
00169                               TAO_OutputCDR &output,
00170                               TAO_GIOP_Message_Generator_Parser *);
00171 
00172   /// Get the parser
00173   TAO_GIOP_Message_Generator_Parser *get_parser (
00174     const TAO_GIOP_Message_Version &version) const;
00175 
00176   /// Print out a debug messages..
00177   void dump_msg (const char *label, const u_char *ptr, size_t len);
00178 
00179   /// Writes the GIOP header in to @a msg
00180   /// @note If the GIOP header happens to change in the future, we can
00181   /// push this method in to the generator_parser classes.
00182   int write_protocol_header (GIOP::MsgType t,
00183                              const TAO_GIOP_Message_Version& version,
00184                              TAO_OutputCDR &msg);
00185 
00186   /// Make a GIOP_LOCATEREPLY and hand that over to the transport so
00187   /// that it can be sent over the connection.
00188   /// @note As on date 1.1 & 1.2 seem to have similar headers. Till an
00189   /// unmanageable difference comes let them be implemented here.
00190   int make_send_locate_reply (TAO_Transport *transport,
00191                               TAO_GIOP_Locate_Request_Header &request,
00192                               TAO_GIOP_Locate_Status_Msg &status,
00193                               TAO_OutputCDR &output,
00194                               TAO_GIOP_Message_Generator_Parser *);
00195 
00196   /// Send error messages
00197   int send_error (TAO_Transport *transport);
00198 
00199   /// Close a connection, first sending GIOP::CloseConnection.
00200   void send_close_connection (const TAO_GIOP_Message_Version &version,
00201                               TAO_Transport *transport);
00202 
00203   /// We must send a LocateReply through @a transport, this request
00204   /// resulted in some kind of exception.
00205   int send_reply_exception (TAO_Transport *transport,
00206                             TAO_OutputCDR &cdr,
00207                             CORBA::ULong request_id,
00208                             IOP::ServiceContextList *svc_info,
00209                             CORBA::Exception *x);
00210 
00211   /// Write the locate reply header
00212   int generate_locate_reply_header (
00213       TAO_OutputCDR &cdr,
00214       TAO_Pluggable_Reply_Params_Base &params);
00215 
00216   /// Creates a new node for the queue with a message block in the
00217   /// node of size @a sz.
00218   TAO_Queued_Data *make_queued_data (size_t sz);
00219 
00220   /// Parse GIOP request-id of TAO_Queued_Data @a qd
00221   /// @return 0 on success, otherwise -1
00222   int parse_request_id (const TAO_Queued_Data *qd, CORBA::ULong &request_id) const;
00223 
00224   /// Parse GIOP request-id of TAO_InputCDR @a cdr.
00225   /// @return 0 on success, otherwise -1
00226   int parse_request_id (const TAO_InputCDR &cdr, CORBA::ULong &request_id) const;
00227 
00228   /// Set GIOP message flags in message that has been marshaled into
00229   /// the output CDR stream @a msg.
00230   /**
00231    * @note It is assumed that the GIOP message header is the first
00232    *       thing marshaled into the output CDR stream @a msg.
00233    */
00234   void set_giop_flags (TAO_OutputCDR & msg) const;
00235 
00236 private:
00237   /// Cached ORB_Core pointer...
00238   TAO_ORB_Core *orb_core_;
00239 
00240   /// All the implementations of GIOP message generator and parsers
00241   TAO_GIOP_Message_Generator_Parser_Impl tao_giop_impl_;
00242 
00243   /// All Fragments being received are stored on stack in reverse
00244   /// order, last top
00245   TAO::Incoming_Message_Stack fragment_stack_;
00246 
00247 protected:
00248   /**
00249    * @name Outgoing GIOP Fragment Related Attributes
00250    *
00251    * These attributes are only used when fragmenting outgoing GIOP
00252    * requests and replies.
00253    */
00254   //@{
00255   /// Strategy that sends data currently marshaled into this
00256   /// TAO_OutputCDR stream if necessary.
00257   auto_ptr<TAO_GIOP_Fragmentation_Strategy> fragmentation_strategy_;
00258 
00259   /// Buffer where the request is placed.
00260   TAO_OutputCDR out_stream_;
00261 };
00262 
00263 TAO_END_VERSIONED_NAMESPACE_DECL
00264 
00265 #include /**/ "ace/post.h"
00266 
00267 #endif  /* TAO_GIOP_MESSAGE_BASE_H */

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