summaryrefslogtreecommitdiff
path: root/apps/JAWS/PROTOTYPE/JAWS/IO_Handler.h
blob: 6b22e88609ad2587429a8ab01d19ff878a9db24f (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
/* -*- c++ -*- */
// Hey, Emacs!  This is a C++ file!
// $Id$

// ============================================================================
//
// = LIBRARY
//   jaws
//
// = FILENAME
//    IO.h
//
// = AUTHOR
//    James Hu
//
// ============================================================================

#if !defined (JAWS_IO_HANDLER_H)
#define JAWS_IO_HANDLER_H

#include "ace/Asynch_IO.h"
#include "ace/Singleton.h"

// #include "JAWS/IO.h"
class JAWS_IO;
class JAWS_Synch_IO;
class JAWS_Asynch_IO;
class JAWS_IO_Handler;
class JAWS_Synch_IO_Handler;
class JAWS_Asynch_IO_Handler;
class JAWS_IO_Handler_Factory;
class JAWS_Synch_IO_Handler_Factory;
class JAWS_Asynch_IO_Handler_Factory;
class JAWS_Data_Block;

template <class TYPE> class JAWS_Pipeline_Abstract_Handler;
typedef JAWS_Pipeline_Abstract_Handler<JAWS_Data_Block>
        JAWS_Pipeline_Handler;

class JAWS_IO_Handler
  // = TITLE
  //
  //     This class defines the abstract interface for an I/O handler
  //     class in the context of Web-likes servers
  //
  // = DESCRIPTION
{
public:
  virtual void accept_complete (ACE_HANDLE handle) = 0;
  // This method is called by the IO class when new passive connection has
  // been established.

  virtual void accept_error (void) = 0;
  // This method is called by the IO class when new passive connection has
  // been established.

#if 0
  virtual void connect_complete (ACE_Message_Block &) = 0;
  // This method is called by the IO class when new active connection has
  // been established.

  virtual void connect_error (ACE_Message_Block &) = 0;
  // This method is called by the IO class when new active connection has
  // been established.
#endif

  virtual void read_complete (ACE_Message_Block &data) = 0;
  // This method is called by the IO class when new client data shows
  // up.

  virtual void read_error (void) = 0;
  // This method is called by the IO class when there was an error in
  // reading new data from the client.

  virtual void transmit_file_complete (void) = 0;
  // This method is called by the IO class when the requested file has
  // been successfully transmitted to the client.

  virtual void transmit_file_error (int result) = 0;
  // This method is called by the IO class when there was an error in
  // transmitting the requested file to the client.

  virtual void receive_file_complete (void) = 0;
  // This method is called by the IO class when the requested file has
  // been successfully received from the client.

  virtual void receive_file_error (int result) = 0;
  // This method is called by the IO class when there was an error in
  // receiving the requested file from the client.

  virtual void write_error (void) = 0;
  // This method is called by the IO class when there was an error in
  // writing data to the client.

  virtual void confirmation_message_complete (void) = 0;
  // This method is called by the IO class when the confirmation
  // message has been delivered to the client.

  virtual void error_message_complete (void) = 0;
  // This method is called by the IO class when the error message has
  // been delivered to the client.

  virtual JAWS_IO_Handler_Factory *factory (void) = 0;
  // Returns the factory for this IO handler

  virtual ACE_HANDLE handle (void) = 0;
  // Returns the socket handle for this handler

  virtual int status (void) = 0;

  enum { IDLE = 0,
         ACCEPT_OK, ACCEPT_ERROR,
         READ_OK, READ_ERROR,
         WRITE_OK, WRITE_ERROR,
         TRANSMIT_OK, TRANSMIT_ERROR,
         RECEIVE_OK, RECEIVE_ERROR };
};

class JAWS_IO_Handler_Factory
#if defined (ACE_WIN32)
 : public ACE_Service_Handler
#endif
{
public:
  virtual ~JAWS_IO_Handler_Factory (void);
  // Destructor

  virtual JAWS_IO_Handler *create_io_handler (void) = 0;
  // This creates a new HTTP_Handler

  virtual void destroy_io_handler (JAWS_IO_Handler *handler) = 0;
  // The HTTP handler will call this method from HTTP_Handler::done to
  // tell the factory to reap up the handler as it is now done with
  // the protocol
};

class JAWS_Synch_IO_Handler : protected JAWS_IO_Handler
{
friend class JAWS_Synch_IO;
friend class JAWS_Synch_IO_Handler_Factory;

public:
  JAWS_Synch_IO_Handler (JAWS_IO_Handler_Factory *factory);
  virtual ~JAWS_Synch_IO_Handler (void);

protected:
  // Inherited from JAWS_IO_Handler

  virtual void accept_complete (ACE_HANDLE handle);
  virtual void accept_error (void);
  virtual void read_complete (ACE_Message_Block &data);
  virtual void read_error (void);
  virtual void transmit_file_complete (void);
  virtual void transmit_file_error (int result);
  virtual void receive_file_complete (void);
  virtual void receive_file_error (int result);
  virtual void write_error (void);
  virtual void confirmation_message_complete (void);
  virtual void error_message_complete (void);

  virtual JAWS_IO_Handler_Factory *factory (void);
  virtual ACE_HANDLE handle (void);

  virtual void done (void);
  virtual int status (void);

private:
  int status_;
  // The state of the handler.

  ACE_Message_Block *mb_;
  // This maintains the state of the request.

  ACE_HANDLE handle_;
  // The socket handle returned from accept.

  JAWS_Pipeline_Handler *task_;
  // This is a reference to the next stage of the pipeline when the IO
  // request completes.

  JAWS_IO_Handler_Factory *factory_;
};

class JAWS_Synch_IO_Handler_Factory : public JAWS_IO_Handler_Factory
{
public:
  JAWS_IO_Handler *create_io_handler (void);
  // This creates a new HTTP_Handler

  void destroy_io_handler (JAWS_IO_Handler *handler);
  // The HTTP handler will call this method from HTTP_Handler::done to
  // tell the factory to reap up the handler as it is now done with
  // the protocol
};

typedef ACE_Singleton<JAWS_Synch_IO_Handler_Factory, ACE_SYNCH_MUTEX>
        JAWS_Synch_IO_Handler_Factory_Singleton;

// This only works on Win32
#if defined (ACE_WIN32)

class JAWS_Asynch_IO_Handler : protected JAWS_IO_Handler
{
public:
  JAWS_Asynch_IO_Handler (void);
  virtual ~JAWS_Asynch_IO_Handler (void);

protected:
  // Inherited from JAWS_IO_Handler

  virtual void accept_complete (void);
  virtual void accept_error (void);
  virtual void read_complete (ACE_Message_Block &data);
  virtual void read_error (void);
  virtual void transmit_file_complete (void);
  virtual void transmit_file_error (int result);
  virtual void receive_file_complete (void);
  virtual void receive_file_error (int result);
  virtual void write_error (void);
  virtual void confirmation_message_complete (void);
  virtual void error_message_complete (void);
  virtual JAWS_Handler_Factory *factory (void);

private:
  ACE_Message_Block *state_;
  // This maintains the state of the request.

  JAWS_IO *io_;
  // The reference to our IO interface (synch vs. asynch)

  JAWS_Pipeline *pipeline_;
  // This is a reference to the next stage of the pipeline when the IO
  // request completes.

  JAWS_IO_Handler_Factory *factory_;
};

class JAWS_Asynch_IO_Handler_Factory : public JAWS_IO_Handler_Factory
{
public:
  JAWS_IO_Handler *create_io_handler (void);
  // This creates a new HTTP_Handler

  void destroy_io_handler (JAWS_IO_Handler *handler);
  // The HTTP handler will call this method from HTTP_Handler::done to
  // tell the factory to reap up the handler as it is now done with
  // the protocol
};

#endif /* ACE_WIN32 */
#endif /* JAWS_IO_HANDLER_H */