Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / ACE / apps / JAWS2 / JAWS / IO_Handler.h
blobe7ea5383746a08c494e3232bcea96dc46ea76414
1 /* -*- c++ -*- */
3 //=============================================================================
4 /**
5 * @file IO_Handler.h
7 * @author James Hu
8 */
9 //=============================================================================
11 #ifndef JAWS_IO_HANDLER_H
12 #define JAWS_IO_HANDLER_H
14 #include "ace/Asynch_IO.h"
16 #if !defined (ACE_LACKS_PRAGMA_ONCE)
17 # pragma once
18 #endif /* ACE_LACKS_PRAGMA_ONCE */
20 #include "ace/Singleton.h"
21 #include "ace/Synch_Traits.h"
22 #include "ace/RW_Thread_Mutex.h"
24 #include "JAWS/Export.h"
26 class JAWS_IO;
27 class JAWS_Synch_IO;
28 class JAWS_Asynch_IO;
29 class JAWS_IO_Handler;
30 class JAWS_IO_Handler_Factory;
31 class JAWS_Data_Block;
32 class JAWS_Pipeline_Handler;
33 class JAWS_Waiter;
35 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
36 class ACE_Message_Block;
37 ACE_END_VERSIONED_NAMESPACE_DECL
39 /**
40 * @class JAWS_Abstract_IO_Handler
42 * @brief This class defines the abstract interface for an I/O handler
43 * class in the context of Web-likes servers
45 class JAWS_Export JAWS_Abstract_IO_Handler
47 public:
48 virtual ~JAWS_Abstract_IO_Handler (void);
50 virtual void task (JAWS_Pipeline_Handler *ph) = 0;
51 virtual JAWS_Pipeline_Handler *task (void) = 0;
53 virtual void message_block (JAWS_Data_Block *mb) = 0;
54 virtual JAWS_Data_Block *message_block (void) = 0;
56 /// This method is called by the IO class when new passive connection has
57 /// been established.
58 virtual void accept_complete (ACE_HANDLE handle) = 0;
60 /// This method is called by the IO class when new passive connection has
61 /// been established.
62 virtual void accept_error (void) = 0;
64 #if 0
65 /// This method is called by the IO class when new active connection has
66 /// been established.
67 virtual void connect_complete (ACE_Message_Block *) = 0;
69 /// This method is called by the IO class when new active connection has
70 /// been established.
71 virtual void connect_error (ACE_Message_Block *) = 0;
72 #endif
74 /// This method is called by the IO class when new client data shows
75 /// up.
76 virtual void read_complete (ACE_Message_Block *data) = 0;
78 /// This method is called by the IO class when there was an error in
79 /// reading new data from the client.
80 virtual void read_error (void) = 0;
82 /// This method is called by the IO class when the requested file has
83 /// been successfully transmitted to the client.
84 virtual void transmit_file_complete (void) = 0;
86 /// This method is called by the IO class when there was an error in
87 /// transmitting the requested file to the client.
88 virtual void transmit_file_error (int result) = 0;
90 /// This method is called by the IO class when the requested file has
91 /// been successfully received from the client.
92 virtual void receive_file_complete (void) = 0;
94 /// This method is called by the IO class when there was an error in
95 /// receiving the requested file from the client.
96 virtual void receive_file_error (int result) = 0;
98 /// This method is called by the IO class when there was an error in
99 /// writing data to the client.
100 virtual void write_error (void) = 0;
102 /// This method is called by the IO class when the confirmation
103 /// message has been delivered to the client.
104 virtual void confirmation_message_complete (void) = 0;
106 /// This method is called by the IO class when the error message has
107 /// been delivered to the client.
108 virtual void error_message_complete (void) = 0;
110 /// Returns the factory for this IO handler
111 virtual JAWS_IO_Handler_Factory *factory (void) = 0;
113 /// Returns the socket handle for this handler
114 virtual ACE_HANDLE handle (void) const = 0;
116 /// Cleans up the handler.
117 virtual void done (void) = 0;
119 /// Returns the status of the handler
120 virtual int status (void) = 0;
122 /// puts handler in an idle state
123 virtual void idle (void) = 0;
125 enum { IDLE = 0, IDLE_A = 1,
126 ACCEPT_OK = 2, ACCEPT_OK_A = 3,
127 ACCEPT_ERROR = 4, ACCEPT_ERROR_A = 5,
128 READ_OK = 6, READ_OK_A = 7,
129 READ_ERROR = 8, READ_ERROR_A = 9,
130 WRITE_OK = 10, WRITE_OK_A = 11,
131 WRITE_ERROR = 12, WRITE_ERROR_A = 13,
132 TRANSMIT_OK = 14, TRANSMIT_OK_A = 15,
133 TRANSMIT_ERROR = 16, TRANSMIT_ERROR_A = 17,
134 RECEIVE_OK = 18, RECEIVE_OK_A = 19,
135 /// The different states of the handler
136 RECEIVE_ERROR = 20, RECEIVE_ERROR_A = 21 };
140 #if defined (ACE_HAS_WIN32_OVERLAPPED_IO) || defined(ACE_HAS_AIO_CALLS)
142 // Forward reference.
143 class JAWS_Asynch_IO_Handler;
145 class JAWS_Export JAWS_Asynch_Handler : public ACE_Service_Handler
147 public:
148 JAWS_Asynch_Handler (void);
149 virtual ~JAWS_Asynch_Handler (void);
151 /// This method will be called when an asynchronous read completes on
152 /// a stream.
153 virtual void handle_read_stream (const ACE_Asynch_Read_Stream::Result
154 &result);
156 /// This method will be called when an asynchronous write completes
157 /// on a stream.
158 virtual void handle_write_stream (const ACE_Asynch_Write_Stream::Result
159 &result);
161 /// This method will be called when an asynchronous transmit file
162 /// completes.
163 virtual void handle_transmit_file (const ACE_Asynch_Transmit_File::Result
164 &result);
166 /// This method will be called when an asynchronous accept completes.
167 virtual void handle_accept (const ACE_Asynch_Accept::Result &result);
169 virtual void handler (JAWS_Asynch_IO_Handler *ioh);
170 virtual JAWS_Asynch_IO_Handler * handler (void);
172 virtual void dispatch_handler (void);
174 /// Call back entry point for ACE_Asynch_Acceptor
175 virtual void open (ACE_HANDLE h, ACE_Message_Block &mb);
177 /// Receives the ACT.
178 virtual void act (const void *act_ref);
180 //virtual ACE_HANDLE handle (void) const;
182 private:
183 JAWS_Asynch_IO_Handler *ioh_;
185 #endif /* defined(ACE_HAS_WIN32_OVERLAPPED_IO) || defined(ACE_HAS_AIO_CALLS) */
188 class JAWS_Export JAWS_IO_Handler : public JAWS_Abstract_IO_Handler
190 public:
191 JAWS_IO_Handler (JAWS_IO_Handler_Factory *factory);
192 virtual ~JAWS_IO_Handler (void);
194 // Inherited from JAWS_IO_Handler
196 virtual void accept_complete (ACE_HANDLE handle);
197 virtual void accept_error (void);
198 virtual void read_complete (ACE_Message_Block *data);
199 virtual void read_error (void);
200 virtual void transmit_file_complete (void);
201 virtual void transmit_file_error (int result);
202 virtual void receive_file_complete (void);
203 virtual void receive_file_error (int result);
204 virtual void write_error (void);
205 virtual void confirmation_message_complete (void);
206 virtual void error_message_complete (void);
208 virtual JAWS_IO_Handler_Factory *factory (void);
209 virtual ACE_HANDLE handle (void) const;
211 virtual void done (void);
212 virtual int status (void);
213 virtual void idle (void);
215 virtual void acquire (void);
216 virtual void lock (void);
217 virtual void release (void);
219 virtual void task (JAWS_Pipeline_Handler *ph);
220 virtual JAWS_Pipeline_Handler *task (void);
222 virtual void message_block (JAWS_Data_Block *mb);
223 virtual JAWS_Data_Block *message_block (void);
225 protected:
226 /// The state of the handler.
227 int status_;
229 /// This maintains the state of the request.
230 JAWS_Data_Block *mb_;
232 /// The socket handle returned from accept.
233 ACE_HANDLE handle_;
235 /// This is a reference to the next stage of the pipeline when the IO
236 /// request completes.
237 JAWS_Pipeline_Handler *task_;
239 /// The reference to the handler's factory.
240 JAWS_IO_Handler_Factory *factory_;
243 class JAWS_Export JAWS_IO_Handler_Factory
245 public:
246 /// Destructor
247 virtual ~JAWS_IO_Handler_Factory (void);
249 /// This creates a new JAWS_IO_Handler
250 virtual JAWS_IO_Handler *create_io_handler (void);
252 /// This deletes a JAWS_IO_Handler
253 virtual void destroy_io_handler (JAWS_IO_Handler *handler);
256 typedef JAWS_IO_Handler JAWS_Synch_IO_Handler;
257 typedef JAWS_IO_Handler_Factory JAWS_Synch_IO_Handler_Factory;
259 typedef ACE_Singleton<JAWS_Synch_IO_Handler_Factory, ACE_SYNCH_MUTEX>
260 JAWS_Synch_IO_Handler_Factory_Singleton;
262 #if defined(ACE_HAS_WIN32_OVERLAPPED_IO) || defined(ACE_HAS_AIO_CALLS)
264 class JAWS_Export JAWS_Asynch_IO_Handler_Factory : public JAWS_IO_Handler_Factory
266 public:
267 /// Destructor
268 virtual ~JAWS_Asynch_IO_Handler_Factory (void);
270 /// This creates a new JAWS_IO_Handler
271 virtual JAWS_IO_Handler *create_io_handler (void);
273 /// This deletes a JAWS_IO_Handler
274 virtual void destroy_io_handler (JAWS_IO_Handler *handler);
277 class JAWS_Export JAWS_Asynch_IO_Handler : public JAWS_IO_Handler
279 friend class JAWS_Asynch_Handler;
280 friend class JAWS_Asynch_IO_Handler_Factory;
281 friend class JAWS_Waiter;
283 // Provide implementations for the common functions.
284 public:
285 explicit JAWS_Asynch_IO_Handler (JAWS_Asynch_IO_Handler_Factory *factory);
286 virtual ~JAWS_Asynch_IO_Handler (void);
288 virtual ACE_Handler *handler (void);
290 virtual void acquire (void);
291 virtual void lock (void);
292 virtual void release (void);
294 protected:
296 JAWS_Asynch_Handler *handler_;
297 ACE_SYNCH_RW_MUTEX count_;
300 #else
302 typedef JAWS_IO_Handler JAWS_Asynch_IO_Handler;
303 typedef JAWS_IO_Handler_Factory JAWS_Asynch_IO_Handler_Factory;
305 #endif /* defined(ACE_HAS_WIN32_OVERLAPPED_IO) || defined(ACE_HAS_AIO_CALLS) */
307 typedef ACE_Singleton<JAWS_Asynch_IO_Handler_Factory, ACE_SYNCH_MUTEX>
308 JAWS_Asynch_IO_Handler_Factory_Singleton;
310 #endif /* JAWS_IO_HANDLER_H */