3 // ===================================================================
5 * @file GIOP_Message_Base.h
7 * @author Initially Copyrighted by Sun Microsystems Inc., 1994-1995,
8 * @author modified by Balachandran Natarajan <bala@cs.wustl.edu>
10 // ===================================================================
12 #ifndef TAO_GIOP_MESSAGE_BASE_H
13 #define TAO_GIOP_MESSAGE_BASE_H
15 #include /**/ "ace/pre.h"
17 #include /**/ "tao/TAO_Export.h"
19 #if !defined (ACE_LACKS_PRAGMA_ONCE)
21 #endif /* ACE_LACKS_PRAGMA_ONCE */
23 #include "tao/Exception.h"
24 #include "tao/Pluggable_Messaging_Utils.h"
25 #include "tao/GIOP_Message_Generator_Parser_Impl.h"
26 #include "tao/GIOP_Utils.h"
27 #include "tao/GIOP_Message_State.h"
28 #include "tao/GIOP_Fragmentation_Strategy.h"
30 #include "tao/Incoming_Message_Stack.h"
32 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
34 class TAO_Pluggable_Reply_Params
;
35 class TAO_Queued_Data
;
36 class TAO_ServerRequest
;
39 * @class TAO_GIOP_Message_Base
41 * @brief Definitions of the GIOP specific stuff.
43 * This class will hold the specific details common to all the GIOP
44 * versions. Some of them which are here may be shifted if things
45 * start changing between versions.
48 class TAO_Export TAO_GIOP_Message_Base
52 TAO_GIOP_Message_Base (TAO_ORB_Core
*orb_core
,
53 TAO_Transport
* transport
,
54 size_t input_cdr_size
= ACE_CDR::DEFAULT_BUFSIZE
);
57 ~TAO_GIOP_Message_Base ();
59 /// Initialize the underlying state object based on the @a major and
60 /// @a minor revision numbers
61 void init (CORBA::Octet major
, CORBA::Octet minor
);
63 /// Write the RequestHeader in to the @a cdr stream. The underlying
64 /// implementation of the messaging should do the right thing.
65 int generate_request_header (TAO_Operation_Details
&op
,
66 TAO_Target_Specification
&spec
,
69 /// Write the RequestHeader in to the @a cdr stream.
70 int generate_locate_request_header (
71 TAO_Operation_Details
&op
,
72 TAO_Target_Specification
&spec
,
75 /// Write the reply header
76 int generate_reply_header (
78 TAO_Pluggable_Reply_Params_Base
¶ms
);
80 int generate_fragment_header (TAO_OutputCDR
& cdr
, CORBA::ULong request_id
);
82 /// Format the message. As we have not written the message length in
83 /// the header, we make use of this opportunity to insert and format
84 /// the message. (Called by client, for requests, provides stub pointer
85 /// but not the req pointer; called by server, for replies, provides req
86 /// pointer, not stub pointer.)
87 int format_message (TAO_OutputCDR
&cdr
, TAO_Stub
*stub
, TAO_ServerRequest
*req
);
90 * Parse the details of the next message from the @a incoming
91 * and initializes attributes of @a qd.
92 * @retval 0 If the message header could not be parsed completely,
93 * @retval 1 If the message header could be parsed completely
94 * @retval -1 On error.
96 int parse_next_message (TAO_Queued_Data
&qd
, size_t &mesg_length
);
98 /// Extract the details of the next message from the @a incoming
99 /// through @a qd. Returns 0 if the message header could not be
100 /// parsed completely, returns a 1 if the message header could be
101 /// parsed completely and returns -1 on error.
102 int extract_next_message (ACE_Message_Block
&incoming
, TAO_Queued_Data
*&qd
);
104 /// Check whether the node @a qd needs consolidation from @a incoming.
105 int consolidate_node (TAO_Queued_Data
*qd
, ACE_Message_Block
&incoming
);
107 /// Process the request message that we have received on the
109 int process_request_message (TAO_Transport
*transport
, TAO_Queued_Data
*qd
);
111 /// Parse the reply message that we received and return the reply
112 /// information through @a reply_info
113 int process_reply_message (
114 TAO_Pluggable_Reply_Params
&reply_info
,
115 TAO_Queued_Data
*qd
);
117 /// Generate a reply message with the exception @a ex.
118 int generate_exception_reply (
120 TAO_Pluggable_Reply_Params_Base
¶ms
,
121 const CORBA::Exception
&x
);
124 size_t header_length () const;
126 /// The header length of a fragment
127 size_t fragment_header_length (
128 const TAO_GIOP_Message_Version
& giop_version
) const;
130 TAO_OutputCDR
&out_stream ();
132 /// Consolidate fragmented message with associated fragments, being
133 /// stored within this class. If reliable transport is used (like
134 /// TCP) fragments are partially ordered on stack, last fragment on
135 /// top. Otherwise If un-reliable transport is used (like UDP)
136 /// fragments may be dis-ordered, and must be ordered before
137 /// consolidation. @return 0 on success and @a msg points to
138 /// consolidated message, 1 if there are still fragments outstanding,
139 /// in case of error -1 is being returned. In any case @a qd must be
140 /// released by method implementation.
141 int consolidate_fragmented_message (TAO_Queued_Data
*qd
,
142 TAO_Queued_Data
*&msg
);
144 /// Discard all fragments associated to request-id encoded in
145 /// cancel_request. This operation will never be called
146 /// concurrently by multiple threads nor concurrently to
147 /// consolidate_fragmented_message @return -1 on failure, 0 on
148 /// success, 1 no fragment on stack relating to CancelRequest.
149 int discard_fragmented_message (const TAO_Queued_Data
*cancel_request
);
151 /// Outgoing GIOP message fragmentation strategy.
152 TAO_GIOP_Fragmentation_Strategy
* fragmentation_strategy ();
154 /// Is the messaging object ready for processing BiDirectional
155 /// request/response?
156 bool is_ready_for_bidirectional (TAO_OutputCDR
&msg
) const;
159 #if defined (TAO_HAS_ZIOP) && TAO_HAS_ZIOP ==1
160 /// Decompresses a ZIOP message and turns it into a GIOP message
161 /// When decompressed, db contains a complete new ACE_Data_Block and
162 /// therefore qd its data block is also replaced.
163 bool decompress (ACE_Data_Block
**db
, TAO_Queued_Data
& qd
,
164 size_t& rd_pos
, size_t& wr_pos
);
167 /// Processes the GIOP_REQUEST messages
168 int process_request (TAO_Transport
*transport
,
170 TAO_OutputCDR
&output
,
171 TAO_GIOP_Message_Generator_Parser
*);
173 /// Processes the GIOP_LOCATE_REQUEST messages
174 int process_locate_request (TAO_Transport
*transport
,
176 TAO_OutputCDR
&output
,
177 TAO_GIOP_Message_Generator_Parser
*);
180 TAO_GIOP_Message_Generator_Parser
*get_parser (
181 const TAO_GIOP_Message_Version
&version
) const;
183 /// Print out consolidate messages
184 int dump_consolidated_msg (TAO_OutputCDR
&stream
);
186 /// Print out a debug messages..
187 void dump_msg (const char *label
, const u_char
*ptr
,
190 /// Writes the GIOP header in to @a msg
191 /// @note If the GIOP header happens to change in the future, we can
192 /// push this method in to the generator_parser classes.
193 int write_protocol_header (GIOP::MsgType t
,
194 const TAO_GIOP_Message_Version
& version
,
197 /// Make a GIOP_LOCATEREPLY and hand that over to the transport so
198 /// that it can be sent over the connection.
199 /// @note As on date 1.1 & 1.2 seem to have similar headers. Till an
200 /// unmanageable difference comes let them be implemented here.
201 int make_send_locate_reply (TAO_Transport
*transport
,
202 TAO_GIOP_Locate_Request_Header
&request
,
203 TAO_GIOP_Locate_Status_Msg
&status
,
204 TAO_OutputCDR
&output
,
205 TAO_GIOP_Message_Generator_Parser
*);
207 /// Send error messages
208 int send_error (TAO_Transport
*transport
);
210 /// Close a connection, first sending GIOP::CloseConnection.
211 void send_close_connection (const TAO_GIOP_Message_Version
&version
,
212 TAO_Transport
*transport
);
214 /// We must send a LocateReply through @a transport, this request
215 /// resulted in some kind of exception.
216 int send_reply_exception (TAO_Transport
*transport
,
218 CORBA::ULong request_id
,
219 IOP::ServiceContextList
*svc_info
,
220 CORBA::Exception
*x
);
222 /// Write the locate reply header
223 int generate_locate_reply_header (
225 TAO_Pluggable_Reply_Params_Base
¶ms
);
227 /// Creates a new node for the queue with a message block in the
228 /// node of size @a sz.
229 TAO_Queued_Data
*make_queued_data (size_t sz
);
231 /// Parse GIOP request-id of TAO_Queued_Data @a qd
232 /// @return 0 on success, otherwise -1
233 int parse_request_id (const TAO_Queued_Data
*qd
, CORBA::ULong
&request_id
) const;
235 /// Parse GIOP request-id of TAO_InputCDR @a cdr.
236 /// @return 0 on success, otherwise -1
237 int parse_request_id (const TAO_InputCDR
&cdr
, CORBA::ULong
&request_id
) const;
239 /// Set GIOP message flags in message that has been marshaled into
240 /// the output CDR stream @a msg.
242 * @note It is assumed that the GIOP message header is the first
243 * thing marshaled into the output CDR stream @a msg.
245 void set_giop_flags (TAO_OutputCDR
& msg
) const;
248 /// Cached ORB_Core pointer...
249 TAO_ORB_Core
*orb_core_
;
251 /// All the implementations of GIOP message generator and parsers
252 TAO_GIOP_Message_Generator_Parser_Impl tao_giop_impl_
;
254 /// All Fragments being received are stored on stack in reverse
256 TAO::Incoming_Message_Stack fragment_stack_
;
260 * @name Outgoing GIOP Fragment Related Attributes
262 * These attributes are only used when fragmenting outgoing GIOP
263 * requests and replies.
266 /// Strategy that sends data currently marshaled into this
267 /// TAO_OutputCDR stream if necessary.
268 TAO_GIOP_Fragmentation_Strategy
* fragmentation_strategy_
;
270 /// Buffer where the request is placed.
271 TAO_OutputCDR out_stream_
;
274 TAO_END_VERSIONED_NAMESPACE_DECL
276 #include /**/ "ace/post.h"
278 #endif /* TAO_GIOP_MESSAGE_BASE_H */