summaryrefslogtreecommitdiff
path: root/TAO/tao/Transport_Mux_Strategy.h
blob: 6c13a03e73de7b39789e17a6413b4c096bcb27e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
// This may look like C, but it's really -*- C++ -*-
// $Id$

// ============================================================================
//
// = LIBRARY
//     TAO
//
// = FILENAME
//     Transport_Mux_Strategy.h
//
// = DESCRIPTION
//     IIOP Transport Mux Strategies.
//
// = AUTHOR
//     Alexander Babu Arulanthu <alex@cs.wustl.edu>
//
// ============================================================================

#ifndef TAO_TRANSPORT_MUX_STRATEGY_H
#define TAO_TRANSPORT_MUX_STRATEGY_H

#include "tao/GIOP.h"

#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */

#include "ace/Functor.h"
#include "ace/Hash_Map_Manager.h"

class TAO_Reply_Dispatcher;

class TAO_Export TAO_Transport_Mux_Strategy
{
  // = TITLE
  //
  //     Strategy to determine whether the connection should be
  //     multiplexed for multiple requests or it is exclusive for a
  //     single request at a time.
  //
  // = DESCRIPTION
  //
  
public:
  TAO_Transport_Mux_Strategy (void);
  // Base class constructor.

  virtual ~TAO_Transport_Mux_Strategy (void);
  // Base class destructor.

  virtual CORBA::ULong request_id (void)  = 0;
  // Generate and return an unique request id for the current
  // invocation.

  // = Bind and Find methods for the <Request ID, ReplyDispatcher>
  //   pairs.

  virtual int bind_dispatcher (CORBA::ULong request_id,
                               TAO_Reply_Dispatcher *rd) = 0;
  // Bind the dispatcher with the request id.
  
  virtual int dispatch_reply (CORBA::ULong request_id,
                              CORBA::ULong reply_status,
                              const TAO_GIOP_Version& version,
                              TAO_GIOP_ServiceContextList& reply_ctx,
                              TAO_GIOP_Message_State* message_state) = 0;
  // Dispatch the reply for <request_id>, cleanup any resources
  // allocated for that request.

  // = "Factory methods" to obtain the CDR stream, in the Muxed case
  //    the factory simply allocates a new one, in the Exclusive case
  //    the factory returns a pointer to the pre-allocated CDR.

  virtual TAO_GIOP_Message_State *get_message_state (void) = 0;
  // Get a CDR stream.

  virtual void destroy_message_state (TAO_GIOP_Message_State *) = 0;
  // Destroy a CDR stream.

  virtual int idle_after_send (TAO_Transport *) = 0;
  // Request has been just sent, but the reply is not received. Idle
  // the transport now.
  
  virtual int idle_after_reply (TAO_Transport *) = 0;
  // Request is sent and the reply is received. Idle the transport
  // now. 

  virtual int reply_received (const CORBA::ULong request_id) = 0;
  // Check whether the reply has been receieved for the request with
  // <request_id>. Return 0 if no, 1 on yes and -1 if the request_id
  // is invalid or there are some errors.
};

// *********************************************************************

class TAO_Export TAO_Exclusive_TMS : public TAO_Transport_Mux_Strategy
{
  // = TITLE
  //
  //    Connection exclusive for the request.
  //
  // = DESCRIPTION
  //

public:
  TAO_Exclusive_TMS (TAO_ORB_Core *orb_core);
  // Constructor.

  virtual ~TAO_Exclusive_TMS (void);
  // Destructor.

  virtual CORBA::ULong request_id (void);
  // Generate and return an unique request id for the current
  // invocation.

  virtual int bind_dispatcher (CORBA::ULong request_id,
                               TAO_Reply_Dispatcher *rh);
  // Bind the dispatcher with the request id.

  virtual int dispatch_reply (CORBA::ULong request_id,
                              CORBA::ULong reply_status,
                              const TAO_GIOP_Version& version,
                              TAO_GIOP_ServiceContextList& reply_ctx,
                              TAO_GIOP_Message_State* message_state);
  // Dispatch the reply for <request_id>, cleanup any resources
  // allocated for that request.

  virtual TAO_GIOP_Message_State *get_message_state (void);
  // Return the pre-allocated message state.

  virtual void destroy_message_state (TAO_GIOP_Message_State *);
  // No op in this strategy.

  virtual int idle_after_send (TAO_Transport *transport);
  // Request has been just sent, but the reply is not received. Idle
  // the transport now.
  
  virtual int idle_after_reply (TAO_Transport *transport);
  // Request is sent and the reply is received. Idle the transport
  // now. 
  
  virtual int reply_received (const CORBA::ULong request_id);
  // Check whether the reply has been receieved for the request with
  // <request_id>. Return 0 if no, 1 on yes and -1 if the request_id
  // is invalid or there are errors.

protected:
  CORBA::ULong request_id_generator_;
  // Used to generate a different request_id on each call to
  // request_id().

  CORBA::ULong request_id_;
  // Request id for the current request.

  TAO_Reply_Dispatcher *rd_;
  // Reply Dispatcher corresponding to the request.

  TAO_GIOP_Message_State message_state_;
  // Message state to read the incoming message. 
};

// *********************************************************************

class TAO_Export TAO_Muxed_TMS : public  TAO_Transport_Mux_Strategy
{
  // = TITLE
  //
  //    Connection is multiplexed for many requests.
  //
  // = DESCRIPTION
  //

public:
  TAO_Muxed_TMS (TAO_ORB_Core *orb_core);
  // Constructor.

  virtual ~TAO_Muxed_TMS (void);
  // Destructor.

  virtual CORBA::ULong request_id (void);
  // Generate and return an unique request id for the current
  // invocation.
  
  virtual int bind_dispatcher (CORBA::ULong request_id,
                               TAO_Reply_Dispatcher *rh);
  // Bind the dispatcher with the request id.

  virtual int dispatch_reply (CORBA::ULong request_id,
                              CORBA::ULong reply_status,
                              const TAO_GIOP_Version& version,
                              TAO_GIOP_ServiceContextList& reply_ctx,
                              TAO_GIOP_Message_State* message_state);
  // Dispatch the reply for <request_id>, cleanup any resources
  // allocated for that request.

  virtual TAO_GIOP_Message_State *get_message_state (void);
  // Return the message state.

  virtual void destroy_message_state (TAO_GIOP_Message_State *);
  // No op in this strategy.

  virtual int idle_after_send (TAO_Transport *transport);
  // Request has been just sent, but the reply is not received. Idle
  // the transport now.
  
  virtual int idle_after_reply (TAO_Transport *transport);
  // Request is sent and the reply is received. Idle the transport
  // now. 

  virtual int reply_received (const CORBA::ULong request_id);
  // Check whether the reply has been receieved for the request with
  // <request_id>. Return 0 if no, 1 on yes and -1 if the request_id
  // is invalid or there are errors.

protected:
  CORBA::ULong request_id_generator_;
  // Used to generate a different request_id on each call to
  // request_id().

  ACE_SYNCH_MUTEX request_id_lock_;
  // Lock to protect the state of the request id generator. 

  typedef ACE_Hash_Map_Manager_Ex <CORBA::ULong,
                                   TAO_Reply_Dispatcher *,
                                   ACE_Hash <CORBA::ULong>,
                                   ACE_Equal_To <CORBA::ULong>,
                                   ACE_SYNCH_MUTEX> REQUEST_DISPATCHER_TABLE;

  REQUEST_DISPATCHER_TABLE dispatcher_table_;
  // Table of <Request ID, Reply Dispatcher> pairs.

  TAO_ORB_Core *orb_core_;
  // Keep track of the orb core pointer. We need to this to create the
  // Reply Dispatchers.

  TAO_GIOP_Message_State *message_state_;
  // Message state where the current input message is being read. This
  // is created at start of each incoming message. When that message
  // is read, the message is processed and for the next message a new
  // message state is created.
};

// *********************************************************************

#endif /* TRANSPORT_MUX_STRATEGY_H */