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

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

#if !defined (JAWS_IO_H)
#define JAWS_IO_H

class ACE_Message_Block;
class JAWS_IO_Handler;

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

class JAWS_IO
  // = TITLE
  //     
  //     This class defines the abstract interface for an I/O class in
  //     the context of Web-likes servers
  //
  // = DESCRIPTION
  //     
  //     An I/O class should have the following interface. Derived
  //     classes will define the exactly how the I/O will take place
  //     (Asynchronous, Synchronous, Reactive)
{
public:
  JAWS_IO (void);
  virtual ~JAWS_IO (void);
  void handler (JAWS_IO_Handler *handler);
  void handle (ACE_HANDLE h);
  ACE_HANDLE handle (void);

  // James, please add documentation here.

  virtual void read (ACE_Message_Block& mb, int size) = 0;
  // read from the handle size bytes into the message block.

  virtual void transmit_file (const char *filename,
			      const char *header,
			      int header_size,
			      const char *trailer,
			      int trailer_size) = 0;
  // send header, filename, trailer to the handle.

  virtual void receive_file (const char *filename,
			     void *initial_data,
			     int initial_data_length,
			     int entire_length) = 0;
  // read data from the handle and store in filename.

  virtual void send_confirmation_message (const char *buffer, int length) = 0; 
  // send a confirmation message to the handle.

  virtual void send_error_message (const char *buffer, int length) = 0; 
  // send an error message to the handle.
  
protected:
  ACE_HANDLE handle_;
  JAWS_IO_Handler *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 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.

};

class JAWS_Synch_IO : public JAWS_IO
  // = TITLE
  //     
  //     This class defines the interface for a Synchronous I/O class.
  //
  // = DESCRIPTION
{
public:
  JAWS_Synch_IO (void);

  ~JAWS_Synch_IO (void);

  void read (ACE_Message_Block& mb, int size);  

  void transmit_file (const char *filename,
		      const char *header,
		      int header_size,
		      const char *trailer,
		      int trailer_size);

  void receive_file (const char *filename,
		     void *initial_data,
		     int initial_data_length,
		     int entire_length);

  void send_confirmation_message (const char *buffer, 
				  int length); 

  void send_error_message (const char *buffer,
			   int length); 
  
protected:
  virtual void send_message (const char *buffer,
			     int length); 
};

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

class JAWS_Asynch_IO : public JAWS_IO, public ACE_Handler
  // = TITLE
  //     
  //     This class defines the interface for a Asynchronous I/O class.
  //
  // = DESCRIPTION
{
public:
  JAWS_Asynch_IO (void);

  ~JAWS_Asynch_IO (void);

  void read (ACE_Message_Block& mb, int size);

  void transmit_file (const char *filename,
		      const char *header,
		      int header_size,
		      const char *trailer,
		      int trailer_size);

  void receive_file (const char *filename,
		     void *initial_data,
		     int initial_data_length,
		     int entire_length);

  void send_confirmation_message (const char *buffer,
				  int length);

  void send_error_message (const char *buffer,
			   int length); 

protected:
  enum Message_Types
  {
    CONFORMATION,
    ERROR_MESSAGE
  };

  virtual void send_message (const char *buffer,
			     int length,
			     int act); 

  virtual void handle_read_stream (const ACE_Asynch_Read_Stream::Result &result);
  // This method will be called when an asynchronous read completes on
  // a stream.

  virtual void handle_write_stream (const ACE_Asynch_Write_Stream::Result &result);
  // This method will be called when an asynchronous write completes
  // on a stream.

  virtual void handle_transmit_file (const ACE_Asynch_Transmit_File::Result &result);
  // This method will be called when an asynchronous transmit file
  // completes.
};

#endif /* ACE_WIN32 */
#endif /* JAWS_IO_H */