summaryrefslogtreecommitdiff
path: root/TAO/tao/Wait_Strategy.h
blob: 73b4bdcafb7ff99dc765e87e7499b51303a1eb5a (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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
// This may look like C, but it's really -*- C++ -*-
// $Id$

// ============================================================================
//
// = LIBRARY
//     TAO
//
// = FILENAME
//     Wait_Strategy.h
//
// = DESCRIPTION
//     Classes to strategize waiting for reply.
//
// = AUTHOR
//     Alexander Babu Arulanthu <alex@cs.wustl.edu>
//
// ============================================================================

#ifndef TAO_WAIT_STRATEGY_H
#define TAO_WAIT_STRATEGY_H

#include "tao/corbafwd.h"

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

class TAO_ORB_Core;
class TAO_Transport;
class TAO_Transport_Mux_Strategy;

class TAO_Export TAO_Wait_Strategy
{
  // = TITLE
  //
  //    Strategy for waiting for the reply.
  //
  // = DESCRIPTION
  //

public:
  TAO_Wait_Strategy (TAO_Transport *transport);
  // Constructor.

  virtual ~TAO_Wait_Strategy (void);
  // Destructor.

  virtual int sending_request (TAO_ORB_Core *orb_core,
                               int two_way);
  // The user is going to send a request, prepare any internal
  // variables because the reply may arrive *before* the user calls
  // wait.

  virtual int wait (ACE_Time_Value *max_wait_time,
                    int &reply_received) = 0;
  // Base class virtual method. Wait till the <reply_received> flag is
  // true or the time expires.

  virtual int handle_input (void) = 0;
  // Handle the input.

  virtual int register_handler (void) = 0;
  // Register the handler with the Reactor if it makes sense for the
  // strategy.

  virtual ACE_SYNCH_CONDITION *leader_follower_condition_variable (void);
  // Return the TSS leader follower condition variable used in the
  // Wait Strategy. Muxed Leader Follower implementation returns a
  // valid condition variable, others return 0.

protected:
  TAO_Transport *transport_;
  // Transport object.
};

// @@ Alex: we should consider moving these classes to separate files,
//    that can minimize the footprint of systems that use only one of
//    the strategies....(coryan).

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

class TAO_Export TAO_Wait_On_Reactor : public TAO_Wait_Strategy
{
  // = TITLE
  //
  //    Wait on the Reactor. Happens in s Single Threaded client
  //    environment.
  //
  // = DESCRIPTION
  //

public:
  TAO_Wait_On_Reactor (TAO_Transport *transport);
  // Constructor.

  virtual ~TAO_Wait_On_Reactor (void);
  // Destructor.

  // = Documented in TAO_Wait_Strategy.

  virtual int wait (ACE_Time_Value *max_wait_time,
                    int &reply_received);
  virtual int handle_input (void);
  virtual int register_handler (void);

private:
  // int reply_received_;
  // This flag indicates if a *complete* reply has been received. Used
  // to exit the event loop.
};

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

class TAO_Export TAO_Wait_On_Leader_Follower : public TAO_Wait_Strategy
{
  // = TITLE
  //
  //    Wait according to the Leader-Follower model. Leader does the
  //    event loop of the Reactor and the Followers wait on the
  //    condition variable.
  //
  // = DESCRIPTION
  //

public:
  TAO_Wait_On_Leader_Follower (TAO_Transport *transport);
  // Constructor.

  virtual ~TAO_Wait_On_Leader_Follower (void);
  // Destructor.
  
  // = Documented in TAO_Wait_Strategy.

  // virtual int sending_request (TAO_ORB_Core *orb_core,
  //                              int two_way);
  
  // virtual int wait (ACE_Time_Value *max_wait_time,
  //                   int &reply_received);

  // virtual int handle_input (void);
  
  virtual int register_handler (void);
};

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

class TAO_Export TAO_Exclusive_Wait_On_Leader_Follower : public TAO_Wait_On_Leader_Follower
{
  // = TITLE
  //
  //    Wait according to the Leader-Follower model. Leader does the
  //    event loop of the Reactor and the Followers wait on the
  //    condition variable.
  //
  // = DESCRIPTION
  //    
  //     This is strategy is to work with the Exclusive Transport Mux
  //     Strategy. This was the original implementation of Leader
  //     Follower before Muxed Transport was introduced. Here the
  //     state variables such as Condition Variable etc are kept in
  //     the <Wait Strategy> which is a per Transport object.

public:
  TAO_Exclusive_Wait_On_Leader_Follower (TAO_Transport *transport);
  // Constructor.

  virtual ~TAO_Exclusive_Wait_On_Leader_Follower (void);
  // Destructor.
  
  // = Documented in TAO_Wait_Strategy.

  virtual int sending_request (TAO_ORB_Core *orb_core,
                               int two_way);
  virtual int wait (ACE_Time_Value *max_wait_time,
                    int &reply_received);
  virtual int handle_input (void);
  // virtual int register_handler (void);

protected:
  ACE_SYNCH_CONDITION* cond_response_available (void);
  // Return the cond_response_available, initializing it if
  // necessary.

  void wake_up (void);
  // Helper method to wake us up when we are a follower...

protected:
  ACE_thread_t calling_thread_;
  // the thread ID of the thread we were running in.

  ACE_SYNCH_CONDITION* cond_response_available_;
  // wait on reponse if the leader-follower model is active.

  int expecting_response_;
  // State flag which, if non-zero, indicates that we were expecting
  // respose. Otherwise, any input received is unexpected.

  int reply_received_;
  // This flag indicates if a *complete* reply was received. Until
  // that happens we block on the leader/follower condition variable
  // or the reactor event loop.
};

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

class TAO_Export TAO_Muxed_Wait_On_Leader_Follower : public TAO_Wait_On_Leader_Follower
{
  // = TITLE
  //
  //    Wait according to the Leader-Follower model. Leader does the
  //    event loop of the Reactor and the Followers wait on the
  //    condition variable.
  //
  // = DESCRIPTION
  //
  //    This impelementation is to work with the Muxed Transport
  //    Mechanism. Here the state variables such as <Condition
  //    Variable> etc cannot be kept in the Wait Strategy, since the
  //    Wait Strategy is per Transport object and here the Transport
  //    is Muxed and hence there are multiple threads running in the
  //    same Transport context. 

public:
  TAO_Muxed_Wait_On_Leader_Follower (TAO_Transport *transport);
  // Constructor.

  virtual ~TAO_Muxed_Wait_On_Leader_Follower (void);
  // Destructor.
  
  // = Documented in TAO_Wait_Strategy.
  
  virtual int sending_request (TAO_ORB_Core *orb_core,
                               int two_way);

  virtual int wait (ACE_Time_Value *max_wait_time,
                    int &reply_received);

  virtual int handle_input (void);

  // virtual int register_handler (void);

  virtual ACE_SYNCH_CONDITION *leader_follower_condition_variable (void);
  // TSS Leader follower condition variable.
};

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

class TAO_Export TAO_Wait_On_Read :  public TAO_Wait_Strategy
{
  // = TITLE
  //
  // = DESCRIPTION
  //   Simply block on read() to wait for the reply.
  //

public:
  TAO_Wait_On_Read (TAO_Transport *transport);
  // Constructor.

  virtual ~TAO_Wait_On_Read (void);
  // Destructor.

  // = Documented in TAO_Wait_Strategy.

  virtual int wait (ACE_Time_Value *max_wait_time,
                    int &reply_received);
  virtual int handle_input (void);
  virtual int register_handler (void);
};

#endif /* TAO_WAIT_STRATEGY_H */