Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / ACE / apps / JAWS / server / JAWS_IO.h
blob1619dcdc2c799db0ad1654d1b12d292699750afb
1 /* -*- c++ -*- */
3 //=============================================================================
4 /**
5 * @file JAWS_IO.h
7 * @author James Hu
8 */
9 //=============================================================================
12 #ifndef JAWS_IO_H
13 #define JAWS_IO_H
15 #include "ace/ACE.h"
17 #if !defined (ACE_LACKS_PRAGMA_ONCE)
18 # pragma once
19 #endif /* ACE_LACKS_PRAGMA_ONCE */
21 #include "ace/Asynch_IO.h"
23 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
24 class ACE_Message_Block;
25 ACE_END_VERSIONED_NAMESPACE_DECL
27 class JAWS_IO_Handler;
30 /**
31 * @class JAWS_IO
33 * @brief This class defines the abstract interface for an I/O class in
34 * the context of Web-likes servers
36 * An I/O class should have the following interface. Derived
37 * classes will define the exactly how the I/O will take place
38 * (Asynchronous, Synchronous, Reactive)
40 class JAWS_IO
42 public:
43 JAWS_IO ();
44 virtual ~JAWS_IO ();
45 void handler (JAWS_IO_Handler *handler);
47 virtual void handle (ACE_HANDLE h) = 0;
48 virtual ACE_HANDLE handle () const = 0;
50 // James, please add documentation here.
52 /// read from the handle size bytes into the message block.
53 virtual void read (ACE_Message_Block& mb, int size) = 0;
55 /// send header, filename, trailer to the handle.
56 virtual void transmit_file (const char *filename,
57 const char *header,
58 int header_size,
59 const char *trailer,
60 int trailer_size) = 0;
62 /// read data from the handle and store in filename.
63 virtual void receive_file (const char *filename,
64 void *initial_data,
65 int initial_data_length,
66 int entire_length) = 0;
68 /// send a confirmation message to the handle.
69 virtual void send_confirmation_message (const char *buffer, int length) = 0;
71 /// send an error message to the handle.
72 virtual void send_error_message (const char *buffer, int length) = 0;
74 protected:
75 JAWS_IO_Handler *handler_;
78 /**
79 * @class JAWS_IO_Handler
81 * @brief This class defines the abstract interface for an I/O handler class in
82 * the context of Web-likes servers
84 class JAWS_IO_Handler
86 public:
87 /// Destructor.
88 virtual ~JAWS_IO_Handler ();
90 /// This method is called by the IO class when new client data shows
91 /// up.
92 virtual void read_complete (ACE_Message_Block &data) = 0;
94 /// This method is called by the IO class when there was an error in
95 /// reading new data from the client.
96 virtual void read_error () = 0;
98 /// This method is called by the IO class when the requested file has
99 /// been successfully transmitted to the client.
100 virtual void transmit_file_complete () = 0;
102 /// This method is called by the IO class when there was an error in
103 /// transmitting the requested file to the client.
104 virtual void transmit_file_error (int result) = 0;
106 /// This method is called by the IO class when the requested file has
107 /// been successfully received from the client.
108 virtual void receive_file_complete () = 0;
110 /// This method is called by the IO class when there was an error in
111 /// receiving the requested file from the client.
112 virtual void receive_file_error (int result) = 0;
114 /// This method is called by the IO class when there was an error in
115 /// writing data to the client.
116 virtual void write_error () = 0;
118 /// This method is called by the IO class when the confirmation
119 /// message has been delivered to the client.
120 virtual void confirmation_message_complete () = 0;
122 /// This method is called by the IO class when the error message has
123 /// been delivered to the client.
124 virtual void error_message_complete () = 0;
128 * @class JAWS_Synch_IO
130 * @brief This class defines the interface for a Synchronous I/O class.
132 class JAWS_Synch_IO : public JAWS_IO
134 public:
135 JAWS_Synch_IO ();
137 ~JAWS_Synch_IO ();
139 virtual void handle (ACE_HANDLE h);
140 virtual ACE_HANDLE handle () const;
142 void read (ACE_Message_Block& mb, int size);
144 void transmit_file (const char *filename,
145 const char *header,
146 int header_size,
147 const char *trailer,
148 int trailer_size);
150 void receive_file (const char *filename,
151 void *initial_data,
152 int initial_data_length,
153 int entire_length);
155 void send_confirmation_message (const char *buffer,
156 int length);
158 void send_error_message (const char *buffer,
159 int length);
161 protected:
162 virtual void send_message (const char *buffer,
163 int length);
165 ACE_HANDLE handle_;
168 // This only works on Win32
169 #if defined (ACE_HAS_WIN32_OVERLAPPED_IO)
172 * @class JAWS_Asynch_IO
174 * @brief This class defines the interface for a Asynchronous I/O class.
176 class JAWS_Asynch_IO : public JAWS_IO, public ACE_Handler
178 public:
179 JAWS_Asynch_IO ();
181 ~JAWS_Asynch_IO ();
183 virtual void handle (ACE_HANDLE h) { ACE_Handler::handle (h); };
184 virtual ACE_HANDLE handle () const { return ACE_Handler::handle (); };
186 void read (ACE_Message_Block& mb, int size);
188 void transmit_file (const char *filename,
189 const char *header,
190 int header_size,
191 const char *trailer,
192 int trailer_size);
194 void receive_file (const char *filename,
195 void *initial_data,
196 int initial_data_length,
197 int entire_length);
199 void send_confirmation_message (const char *buffer,
200 int length);
202 void send_error_message (const char *buffer,
203 int length);
205 protected:
206 enum Message_Types
208 CONFORMATION,
209 ERROR_MESSAGE
212 virtual void send_message (const char *buffer,
213 int length,
214 int act);
216 /// This method will be called when an asynchronous read completes on
217 /// a stream.
218 virtual void handle_read_stream (const ACE_Asynch_Read_Stream::Result &result);
220 /// This method will be called when an asynchronous write completes
221 /// on a stream.
222 virtual void handle_write_stream (const ACE_Asynch_Write_Stream::Result &result);
224 /// This method will be called when an asynchronous transmit file
225 /// completes.
226 virtual void handle_transmit_file (const ACE_Asynch_Transmit_File::Result &result);
229 #endif /* ACE_HAS_WIN32_OVERLAPPED_IO */
232 //-------------------Adding SYNCH IO no Caching
235 * @class JAWS_Synch_IO_No_Cache
237 * @brief This class defines the interface for a Synchronous I/O class,
238 * however in this class we do not use any caching.
240 * Wondering how this is useful?
241 * The ACE_Filecache ACE_NOMAP option is broken and even if it were not, there
242 * are other use cases in which we want to avoid caching altogether. For example,
243 * we use JAWS in conjunction with the CIAO Repository Manager, however the two
244 * do not have any explicit knowledge of each other. Therefore if the RM tried
245 * to remove a package and its files from disk, its operation would [partially]
246 * fail if JAWS still holds some of the files in its cache.
248 class JAWS_Synch_IO_No_Cache : public JAWS_IO
250 public:
251 JAWS_Synch_IO_No_Cache ();
253 ~JAWS_Synch_IO_No_Cache ();
255 virtual void handle (ACE_HANDLE h);
256 virtual ACE_HANDLE handle () const;
258 void read (ACE_Message_Block& mb, int size);
260 void transmit_file (const char *filename,
261 const char *header,
262 int header_size,
263 const char *trailer,
264 int trailer_size);
266 void receive_file (const char *filename,
267 void *initial_data,
268 int initial_data_length,
269 int entire_length);
271 void send_confirmation_message (const char *buffer,
272 int length);
274 void send_error_message (const char *buffer,
275 int length);
277 protected:
278 virtual void send_message (const char *buffer, int length);
280 ACE_HANDLE handle_;
283 //-------------------
285 #endif /* JAWS_IO_H */