GIOP_Message_Base.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // ===================================================================
00004 /**
00005  *  @file GIOP_Message_Base.h
00006  *
00007  *  GIOP_Message_Base.h,v 1.39 2006/05/30 13:41:29 jwillemsen Exp
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/Pluggable_Messaging.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 : public TAO_Pluggable_Messaging
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   virtual ~TAO_GIOP_Message_Base (void);
00061 
00062   /// Initialize the underlying state object based on the @a major and
00063   /// @a minor revision numbers
00064   virtual void init (CORBA::Octet major,
00065                      CORBA::Octet minor);
00066 
00067   /// Reset the messaging the object
00068   virtual void reset (void);
00069 
00070   /// Write the RequestHeader in to the @a cdr stream. The underlying
00071   /// implementation of the mesaging should do the right thing.
00072   virtual int generate_request_header (TAO_Operation_Details &op,
00073                                        TAO_Target_Specification &spec,
00074                                        TAO_OutputCDR &cdr);
00075 
00076   /// Write the RequestHeader in to the @a cdr stream.
00077   virtual int generate_locate_request_header (
00078       TAO_Operation_Details &op,
00079       TAO_Target_Specification &spec,
00080       TAO_OutputCDR &cdr
00081     );
00082 
00083   /// Write the reply header
00084   virtual int generate_reply_header (
00085       TAO_OutputCDR &cdr,
00086       TAO_Pluggable_Reply_Params_Base &params
00087     );
00088 
00089   virtual int generate_fragment_header (TAO_OutputCDR & cdr,
00090                                         CORBA::ULong request_id);
00091 
00092   /// Format the message. As we have not written the message length in
00093   /// the header, we make use of this oppurtunity to insert and format
00094   /// the message.
00095   virtual int format_message (TAO_OutputCDR &cdr);
00096 
00097   /**
00098    * Parse the details of the next message from the @a incoming
00099    * and initializes attributes of @a qd.
00100    * @retval 0 If the message header could not be parsed completely,
00101    * @retval 1 If the message header could be parsed completely
00102    * @retval -1 On error.
00103    */
00104   virtual int parse_next_message (ACE_Message_Block &incoming,
00105                                   TAO_Queued_Data &qd,       /* out */
00106                                   size_t &mesg_length);      /* out */
00107 
00108   /// Extract the details of the next message from the @a incoming
00109   /// through @a qd. Returns 0 if the message header could not be
00110   /// parsed completely, returns a 1 if the message header could be
00111   /// parsed completely and returns -1 on error.
00112   virtual int extract_next_message (ACE_Message_Block &incoming,
00113                                     TAO_Queued_Data *&qd);
00114 
00115   /// Check whether the node @a qd needs consolidation from @a incoming.
00116   virtual int consolidate_node (TAO_Queued_Data *qd,
00117                                 ACE_Message_Block &incoming);
00118 
00119   /// Process the request message that we have received on the
00120   /// connection
00121   virtual int process_request_message (TAO_Transport *transport,
00122                                        TAO_Queued_Data *qd);
00123 
00124 
00125   /// Parse the reply message that we received and return the reply
00126   /// information through @a reply_info
00127   virtual int process_reply_message (
00128       TAO_Pluggable_Reply_Params &reply_info,
00129       TAO_Queued_Data *qd);
00130 
00131   /// Generate a reply message with the exception @a ex.
00132   virtual int generate_exception_reply (
00133       TAO_OutputCDR &cdr,
00134       TAO_Pluggable_Reply_Params_Base &params,
00135       CORBA::Exception &x
00136     );
00137 
00138   /// Header length
00139   virtual size_t header_length (void) const;
00140 
00141   /// The header length of a fragment
00142   virtual size_t fragment_header_length (CORBA::Octet major,
00143                                          CORBA::Octet minor) const;
00144 
00145   virtual TAO_OutputCDR &out_stream (void);
00146 
00147   /// Consolidate fragmented message with associated fragments, being
00148   /// stored withi this class.  If reliable transport is used (like
00149   /// TCP) fragments are partialy ordered on stack, last fragment on
00150   /// top. Otherwise If un-reliable transport is used (like UDP)
00151   /// fragments may be dis-ordered, and must be ordered before
00152   /// consolidation.  @return 0 on success and @a msg points to
00153   /// consolidated message, 1 if there are still fragmens outstanding,
00154   /// in case of error -1 is being returned. In any case @a qd must be
00155   /// released by method implementation.
00156   virtual int consolidate_fragmented_message (TAO_Queued_Data *qd,
00157                                               TAO_Queued_Data *&msg);
00158 
00159   /// Discard all fragments associated to request-id encoded in
00160   /// cancel_request.  This operation will never be called
00161   /// concurrently by multiplpe threads nor concurrently to
00162   /// consolidate_fragmented_message @return -1 on failure, 0 on
00163   /// success, 1 no fragment on stack relating to CancelRequest.
00164   virtual int discard_fragmented_message (const TAO_Queued_Data *cancel_request);
00165 
00166   /// Outgoing GIOP message fragmentation strategy.
00167   virtual TAO_GIOP_Fragmentation_Strategy * fragmentation_strategy (void);
00168 
00169 protected:
00170 
00171   /// Processes the GIOP_REQUEST messages
00172   virtual int process_request (TAO_Transport *transport,
00173                                TAO_InputCDR &input,
00174                                TAO_OutputCDR &output,
00175                                TAO_GIOP_Message_Generator_Parser *);
00176 
00177   /// Processes the GIOP_LOCATE_REQUEST messages
00178   virtual int process_locate_request (TAO_Transport *transport,
00179                                       TAO_InputCDR &input,
00180                                       TAO_OutputCDR &output,
00181                                       TAO_GIOP_Message_Generator_Parser *);
00182 
00183   /// Set the state
00184   void set_state (CORBA::Octet major,
00185                   CORBA::Octet minor,
00186                   TAO_GIOP_Message_Generator_Parser *&) const;
00187 
00188   /// Print out a debug messages..
00189   void dump_msg (const char *label,
00190                  const u_char *ptr,
00191                  size_t len);
00192 
00193   /// Get the message type. The return value would be one of the
00194   /// following:
00195   /// TAO_PLUGGABLE_MESSAGE_REQUEST,
00196   /// TAO_PLUGGABLE_MESSAGE_REPLY,
00197   /// TAO_PLUGGABLE_MESSAGE_CLOSECONNECTION,
00198   /// TAO_PLUGGABLE_MESSAGE_MESSAGE_ERROR.
00199   TAO_Pluggable_Message_Type message_type (
00200                                const TAO_GIOP_Message_State &state) const;
00201 
00202   /// Writes the GIOP header in to @a msg
00203   /// @note If the GIOP header happens to change in the future, we can
00204   /// push this method in to the generator_parser classes.
00205   int write_protocol_header (TAO_GIOP_Message_Type t,
00206                              TAO_OutputCDR &msg);
00207 
00208   /// Make a GIOP_LOCATEREPLY and hand that over to the transport so
00209   /// that it can be sent over the connection.
00210   /// @note As on date 1.1 & 1.2 seem to have similar headers. Till an
00211   /// unmanageable difference comes let them be implemented here.
00212   int make_send_locate_reply (TAO_Transport *transport,
00213                               TAO_GIOP_Locate_Request_Header &request,
00214                               TAO_GIOP_Locate_Status_Msg &status,
00215                               TAO_OutputCDR &output,
00216                               TAO_GIOP_Message_Generator_Parser *);
00217 
00218   /// Send error messages
00219   int  send_error (TAO_Transport *transport);
00220 
00221   /// Close a connection, first sending GIOP::CloseConnection.
00222   void send_close_connection (const TAO_GIOP_Message_Version &version,
00223                               TAO_Transport *transport,
00224                               void *ctx);
00225 
00226   /// We must send a LocateReply through @a transport, this request
00227   /// resulted in some kind of exception.
00228   int send_reply_exception (TAO_Transport *transport,
00229                             TAO_OutputCDR &cdr,
00230                             CORBA::ULong request_id,
00231                             IOP::ServiceContextList *svc_info,
00232                             CORBA::Exception *x);
00233 
00234 
00235   /// Write the locate reply header
00236   virtual int generate_locate_reply_header (
00237       TAO_OutputCDR & /*cdr*/,
00238       TAO_Pluggable_Reply_Params_Base & /*params*/);
00239 
00240   /// Is the messaging object ready for processing BiDirectional
00241   /// request/response?
00242   virtual int is_ready_for_bidirectional (TAO_OutputCDR &msg);
00243 
00244   /// Creates a new node for the queue with a message block in the
00245   /// node of size @a sz.
00246   TAO_Queued_Data *make_queued_data (size_t sz);
00247 
00248   /// Initialize the TAO_Queued_Data from the relevant portions of
00249   /// a GIOP_Message_State.
00250   void init_queued_data (TAO_Queued_Data* qd,
00251                          const TAO_GIOP_Message_State& state) const;
00252 
00253 private:
00254   int parse_incoming_messages (ACE_Message_Block &incoming);
00255 
00256   /// Parse GIOP request-id of TAO_Queued_Data @a qd
00257   /// @return 0 on success, otherwise -1
00258   int parse_request_id (const TAO_Queued_Data *qd, CORBA::ULong &request_id) const;
00259 
00260   /// Parse GIOP request-id of TAO_InputCDR @a cdr.
00261   /// @return 0 on success, otherwise -1
00262   int parse_request_id (const TAO_InputCDR &cdr, CORBA::ULong &request_id) const;
00263 
00264   /// Set GIOP message flags in message that has been marshaled into
00265   /// the output CDR stream @a msg.
00266   /**
00267    * @note It is assumed that the GIOP message header is the first
00268    *       thing marshaled into the output CDR stream @a msg.
00269    */
00270   void set_giop_flags (TAO_OutputCDR & msg) const;
00271 
00272 private:
00273   /// Cached ORB_Core pointer...
00274   TAO_ORB_Core *orb_core_;
00275 
00276   /// The message handler object that does reading and parsing of the
00277   /// incoming messages
00278   TAO_GIOP_Message_State message_state_;
00279 
00280   /// All the implementations of GIOP message generator and parsers
00281   TAO_GIOP_Message_Generator_Parser_Impl tao_giop_impl_;
00282 
00283   /// All Fragments being received are stored on stack in reverse
00284   /// order, last top
00285   TAO::Incoming_Message_Stack fragment_stack_;
00286 
00287 protected:
00288   /**
00289    * @name Outgoing GIOP Fragment Related Attributes
00290    *
00291    * These attributes are only used when fragmenting outgoing GIOP
00292    * requests and replies.
00293    */
00294   //@{
00295   /// Strategy that sends data currently marshaled into this
00296   /// TAO_OutputCDR stream if necessary.
00297   auto_ptr<TAO_GIOP_Fragmentation_Strategy> fragmentation_strategy_;
00298 
00299   /// Buffer where the request is placed.
00300   TAO_OutputCDR out_stream_;
00301 
00302   /*
00303    * Hook in the GIOP_Message class to add data member. This hook is
00304    * used in speeding up the dispatch within TAO.
00305    */
00306 //@@ GIOP_MESSAGE_BASE_DATA_MEMBER_ADD_HOOK
00307 
00308 };
00309 
00310 /*
00311  * Hook to specialize the Messaging implementation in TAO with either
00312  * GIOP or GIOP_Lite protocol.
00313  */
00314 //@@ MESSAGING_SPL_EXTERN_ADD_HOOK
00315 
00316 TAO_END_VERSIONED_NAMESPACE_DECL
00317 
00318 #include /**/ "ace/post.h"
00319 
00320 #endif  /* TAO_GIOP_MESSAGE_BASE_H */

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