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

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