GIOP_Message_Lite.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // ===================================================================
00004 /**
00005  *  @file GIOP_Message_Lite.h
00006  *
00007  *  GIOP_Message_Lite.h,v 1.44 2006/04/20 12:37:17 jwillemsen Exp
00008  *
00009  *  @author Balachandran Natarajan <bala@cs.wustl.edu>
00010  *  @author Carlos O'Ryan <coryan@uci.edu>
00011  */
00012 // ===================================================================
00013 
00014 #ifndef TAO_GIOP_MESSAGE_LITE_H
00015 #define TAO_GIOP_MESSAGE_LITE_H
00016 
00017 #include /**/ "ace/pre.h"
00018 
00019 #include "tao/Pluggable_Messaging.h"
00020 
00021 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00022 # pragma once
00023 #endif /* ACE_LACKS_PRAGMA_ONCE */
00024 
00025 #include "tao/Pluggable_Messaging_Utils.h"
00026 #include "tao/GIOP_Utils.h"
00027 #include "tao/SystemException.h"
00028 #include "tao/CDR.h"
00029 
00030 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00031 
00032 class TAO_Operation_Details;
00033 class TAO_Pluggable_Reply_Params;
00034 class TAO_GIOP_Locate_Request_Header;
00035 class TAO_Queued_Data;
00036 class TAO_ServerRequest;
00037 class TAO_GIOP_Message_Version;
00038 
00039 /**
00040  * @class TAO_GIOP_Message_Lite
00041  *
00042  * @brief Definitions of GIOPLite specific stuff
00043  *
00044  * This protocol is a modified version of GIOP. This is more suited
00045  * for homogenous platforms.
00046  */
00047 class TAO_Export TAO_GIOP_Message_Lite : public TAO_Pluggable_Messaging
00048 {
00049 public:
00050 
00051   /// Constructor
00052   TAO_GIOP_Message_Lite (TAO_ORB_Core *orb_core,
00053                          size_t input_cdr_size = ACE_CDR::DEFAULT_BUFSIZE);
00054 
00055   /// Dtor
00056   virtual ~TAO_GIOP_Message_Lite (void);
00057 
00058   /// Initialize the object -- this is a dummy for GIOPlite
00059   virtual void init (CORBA::Octet, CORBA::Octet);
00060 
00061   /// Reset the messaging the object
00062   virtual void reset (void);
00063 
00064   /// Write the RequestHeader in to the @a cdr stream. The underlying
00065   /// implementation of the mesaging should do the right thing.
00066   virtual int generate_request_header (TAO_Operation_Details &op,
00067                                        TAO_Target_Specification &spec,
00068                                        TAO_OutputCDR &cdr);
00069 
00070   /// Write the RequestHeader in to the @a cdr stream.
00071   virtual int generate_locate_request_header (
00072       TAO_Operation_Details &op,
00073       TAO_Target_Specification &spec,
00074       TAO_OutputCDR &cdr);
00075 
00076   /// Write the reply header
00077   virtual int generate_reply_header (
00078       TAO_OutputCDR &cdr,
00079       TAO_Pluggable_Reply_Params_Base &params
00080     );
00081 
00082   virtual int generate_fragment_header (TAO_OutputCDR & cdr,
00083                                         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   virtual int format_message (TAO_OutputCDR &cdr);
00089 
00090 private:
00091   /// Parse the incoming messages..
00092   ///
00093   /// \retval -1 There was some error parsing the GIOP header
00094   /// \retval 0  The GIOP header was parsed correctly
00095   /// \retval 1  There was not enough data in the message block to
00096   ///            parse the header
00097   int parse_incoming_messages (ACE_Message_Block &message_block);
00098 
00099   /// Get the message type. The return value would be one of the
00100   /// following:
00101   /// TAO_PLUGGABLE_MESSAGE_REQUEST,
00102   /// TAO_PLUGGABLE_MESSAGE_REPLY,
00103   /// TAO_PLUGGABLE_MESSAGE_CLOSECONNECTION,
00104   /// TAO_PLUGGABLE_MESSAGE_MESSAGE_ERROR.
00105   /// TAO_PLUGGABLE_MESSAGE_MESSAGE_CANCELREQUEST.
00106   TAO_Pluggable_Message_Type message_type (void) const;
00107 
00108 public:
00109   /// Parse the details of the next message from the @a incoming
00110   /// and initializes attributes of @a qd. Returns 0 if the message
00111   /// header could not be parsed completely, returns a 1 if the message
00112   /// header could be parsed completely and returns -1 on error.
00113   virtual int parse_next_message (ACE_Message_Block &incoming,
00114                                   TAO_Queued_Data &qd,        /* out */
00115                                   size_t &mesg_length);      /* out */
00116 
00117 
00118   /// Extract the details of the next message from the @a incoming
00119   /// through @a qd. Returns 0 if the message header could not be
00120   /// parsed completely, returns a 1 if the message header could be
00121   /// parsed completely and returns -1 on error.
00122   virtual int extract_next_message (ACE_Message_Block &incoming,
00123                                     TAO_Queued_Data *&qd);
00124 
00125   /// Check whether the node @a qd needs consolidation from @a incoming
00126   virtual int consolidate_node (TAO_Queued_Data *qd,
00127                                 ACE_Message_Block &incoming);
00128 
00129   /// Process the request message that we have received on the
00130   /// connection
00131   virtual int process_request_message (TAO_Transport *transport,
00132                                        TAO_Queued_Data *qd);
00133 
00134   /// Parse the reply message that we received and return the reply
00135   /// information through @a reply_info
00136   virtual int process_reply_message (
00137       TAO_Pluggable_Reply_Params &reply_info,
00138       TAO_Queued_Data *qd);
00139 
00140   /// Generate a reply message with the exception @a ex.
00141   virtual int generate_exception_reply (
00142       TAO_OutputCDR &cdr,
00143       TAO_Pluggable_Reply_Params_Base &params,
00144       CORBA::Exception &x
00145     );
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 @r 0 on success, 1 if no matching
00163   /// fragment chain exists, -1 on error
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 private:
00170 
00171   /// Writes the GIOP header in to @a msg
00172   /// @note If the GIOP header happens to change in the future, we can
00173   /// push this method in to the generator_parser classes.
00174   int write_protocol_header (TAO_GIOP_Message_Type t,
00175                              TAO_OutputCDR &msg);
00176 
00177   /// Processes the GIOP_REQUEST messages
00178   int process_request (TAO_Transport *transport,
00179                        TAO_InputCDR &input,
00180                        TAO_OutputCDR &output);
00181 
00182   /// Processes the GIOP_LOCATE_REQUEST messages
00183   int process_locate_request (TAO_Transport *transport,
00184                               TAO_InputCDR &input,
00185                               TAO_OutputCDR &output);
00186 
00187   /// Make a GIOP_LOCATEREPLY and hand that over to the transport so
00188   /// that it can be sent over the connection.
00189   /// @note As on date 1.1 & 1.2 seem to have similar headers. Till an
00190   /// unmanageable difference comes let them be implemented here.
00191   int make_send_locate_reply (TAO_Transport *transport,
00192                               TAO_OutputCDR &output,
00193                               TAO_GIOP_Locate_Request_Header &request,
00194                               TAO_GIOP_Locate_Status_Msg &status);
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                               void *ctx);
00203 
00204   /// We must send a LocateReply through @a transport, this request
00205   /// resulted in some kind of exception.
00206   int send_reply_exception (TAO_Transport *transport,
00207                             TAO_ORB_Core* orb_core,
00208                             CORBA::ULong request_id,
00209                             IOP::ServiceContextList *svc_info,
00210                             CORBA::Exception *x);
00211 
00212   /// Print out a debug messages..
00213   void dump_msg (const char *label,
00214                  const u_char *ptr,
00215                  size_t len);
00216 
00217   TAO_Queued_Data *make_queued_data (size_t sz);
00218 
00219   /// Write the locate reply header
00220   virtual int generate_locate_reply_header (
00221       TAO_OutputCDR & /*cdr*/,
00222       TAO_Pluggable_Reply_Params_Base & /*params*/);
00223 
00224   /// Is the messaging object ready for processing BiDirectional
00225   /// request/response?
00226   virtual int is_ready_for_bidirectional (TAO_OutputCDR &msg);
00227 
00228   /// Header length
00229   virtual size_t header_length (void) const;
00230 
00231   /// Fragment header length
00232   virtual size_t fragment_header_length (CORBA::Octet major,
00233                                          CORBA::Octet minor) const;
00234 
00235   virtual TAO_OutputCDR &out_stream (void);
00236 
00237 private:
00238 
00239   /// Write the request header in to <msg>
00240   int write_request_header (
00241       const TAO_Operation_Details &opdetails,
00242       TAO_Target_Specification &spec,
00243       TAO_OutputCDR &msg);
00244 
00245   /// Write the LocateRequest header
00246   int write_locate_request_header (
00247       CORBA::ULong request_id,
00248       TAO_Target_Specification &spec,
00249       TAO_OutputCDR &msg);
00250 
00251   /// Write the reply header in to <output>
00252   int write_reply_header (
00253       TAO_OutputCDR &output,
00254       TAO_Pluggable_Reply_Params_Base &reply
00255       ACE_ENV_ARG_DECL_WITH_DEFAULTS)
00256     ACE_THROW_SPEC ((CORBA::SystemException));
00257 
00258   /// Writes the locate _reply message in to the <output>
00259   int write_locate_reply_mesg (
00260       TAO_OutputCDR &output,
00261       CORBA::ULong request_id,
00262       TAO_GIOP_Locate_Status_Msg &status);
00263 
00264   /// Parse the Request Header from the incoming stream. This will do a
00265   /// version specific parsing of the incoming Request header
00266   int parse_request_header (TAO_ServerRequest &);
00267 
00268   /// Parse the Loacte Request Header from the incoming stream. This will do a
00269   /// version specific parsing of the incoming Request header
00270   int parse_locate_header (
00271       TAO_GIOP_Locate_Request_Header &);
00272 
00273   /// Parse the reply message
00274   int parse_reply (TAO_InputCDR &input,
00275                    TAO_Pluggable_Reply_Params &params);
00276 
00277   /// Parse the locate reply message from the server
00278   int parse_locate_reply (TAO_InputCDR &input,
00279                           TAO_Pluggable_Reply_Params &params);
00280 
00281   /// Initialize the relevant portions of a TAO_Queued_Data
00282   void init_queued_data (TAO_Queued_Data* qd) const;
00283 
00284 private:
00285 
00286   /// Our copy of the ORB core...
00287   TAO_ORB_Core *orb_core_;
00288 
00289   /// The message type that we are going to process..
00290   CORBA::Octet message_type_;
00291 
00292   /// The pay load size
00293   CORBA::ULong message_size_;
00294 
00295   /// The byte order..
00296   /// @note GIOP lite cannot work between heterogenous platforms..
00297   CORBA::Octet byte_order_;
00298 
00299   TAO_OutputCDR cdr_;
00300 };
00301 
00302 TAO_END_VERSIONED_NAMESPACE_DECL
00303 
00304 #include /**/ "ace/post.h"
00305 #endif /*TAO_GIOP_MESSAGE_LITE_H*/

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