Use =default for skeleton copy constructor
[ACE_TAO.git] / ACE / apps / JAWS2 / JAWS / IO_Handler.h
blob6c5be891c2cbb1522fa738935f3678e17bdd03c0
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 ();
50 virtual void task (JAWS_Pipeline_Handler *ph) = 0;
51 virtual JAWS_Pipeline_Handler *task () = 0;
53 virtual void message_block (JAWS_Data_Block *mb) = 0;
54 virtual JAWS_Data_Block *message_block () = 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 () = 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 () = 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 () = 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 () = 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 () = 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 () = 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 () = 0;
110 /// Returns the factory for this IO handler
111 virtual JAWS_IO_Handler_Factory *factory () = 0;
113 /// Returns the socket handle for this handler
114 virtual ACE_HANDLE handle () const = 0;
116 /// Cleans up the handler.
117 virtual void done () = 0;
119 /// Returns the status of the handler
120 virtual int status () = 0;
122 /// puts handler in an idle state
123 virtual void idle () = 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 };
139 #if defined (ACE_HAS_WIN32_OVERLAPPED_IO) || defined(ACE_HAS_AIO_CALLS)
141 // Forward reference.
142 class JAWS_Asynch_IO_Handler;
144 class JAWS_Export JAWS_Asynch_Handler : public ACE_Service_Handler
146 public:
147 JAWS_Asynch_Handler ();
148 virtual ~JAWS_Asynch_Handler ();
150 /// This method will be called when an asynchronous read completes on
151 /// a stream.
152 virtual void handle_read_stream (const ACE_Asynch_Read_Stream::Result
153 &result);
155 /// This method will be called when an asynchronous write completes
156 /// on a stream.
157 virtual void handle_write_stream (const ACE_Asynch_Write_Stream::Result
158 &result);
160 /// This method will be called when an asynchronous transmit file
161 /// completes.
162 virtual void handle_transmit_file (const ACE_Asynch_Transmit_File::Result
163 &result);
165 /// This method will be called when an asynchronous accept completes.
166 virtual void handle_accept (const ACE_Asynch_Accept::Result &result);
168 virtual void handler (JAWS_Asynch_IO_Handler *ioh);
169 virtual JAWS_Asynch_IO_Handler * handler ();
171 virtual void dispatch_handler ();
173 /// Call back entry point for ACE_Asynch_Acceptor
174 virtual void open (ACE_HANDLE h, ACE_Message_Block &mb);
176 /// Receives the ACT.
177 virtual void act (const void *act_ref);
179 //virtual ACE_HANDLE handle () const;
181 private:
182 JAWS_Asynch_IO_Handler *ioh_;
184 #endif /* defined(ACE_HAS_WIN32_OVERLAPPED_IO) || defined(ACE_HAS_AIO_CALLS) */
187 class JAWS_Export JAWS_IO_Handler : public JAWS_Abstract_IO_Handler
189 public:
190 JAWS_IO_Handler (JAWS_IO_Handler_Factory *factory);
191 virtual ~JAWS_IO_Handler ();
193 // Inherited from JAWS_IO_Handler
195 virtual void accept_complete (ACE_HANDLE handle);
196 virtual void accept_error ();
197 virtual void read_complete (ACE_Message_Block *data);
198 virtual void read_error ();
199 virtual void transmit_file_complete ();
200 virtual void transmit_file_error (int result);
201 virtual void receive_file_complete ();
202 virtual void receive_file_error (int result);
203 virtual void write_error ();
204 virtual void confirmation_message_complete ();
205 virtual void error_message_complete ();
207 virtual JAWS_IO_Handler_Factory *factory ();
208 virtual ACE_HANDLE handle () const;
210 virtual void done ();
211 virtual int status ();
212 virtual void idle ();
214 virtual void acquire ();
215 virtual void lock ();
216 virtual void release ();
218 virtual void task (JAWS_Pipeline_Handler *ph);
219 virtual JAWS_Pipeline_Handler *task ();
221 virtual void message_block (JAWS_Data_Block *mb);
222 virtual JAWS_Data_Block *message_block ();
224 protected:
225 /// The state of the handler.
226 int status_;
228 /// This maintains the state of the request.
229 JAWS_Data_Block *mb_;
231 /// The socket handle returned from accept.
232 ACE_HANDLE handle_;
234 /// This is a reference to the next stage of the pipeline when the IO
235 /// request completes.
236 JAWS_Pipeline_Handler *task_;
238 /// The reference to the handler's factory.
239 JAWS_IO_Handler_Factory *factory_;
242 class JAWS_Export JAWS_IO_Handler_Factory
244 public:
245 /// Destructor
246 virtual ~JAWS_IO_Handler_Factory ();
248 /// This creates a new JAWS_IO_Handler
249 virtual JAWS_IO_Handler *create_io_handler ();
251 /// This deletes a JAWS_IO_Handler
252 virtual void destroy_io_handler (JAWS_IO_Handler *handler);
255 typedef JAWS_IO_Handler JAWS_Synch_IO_Handler;
256 typedef JAWS_IO_Handler_Factory JAWS_Synch_IO_Handler_Factory;
258 typedef ACE_Singleton<JAWS_Synch_IO_Handler_Factory, ACE_SYNCH_MUTEX>
259 JAWS_Synch_IO_Handler_Factory_Singleton;
261 #if defined(ACE_HAS_WIN32_OVERLAPPED_IO) || defined(ACE_HAS_AIO_CALLS)
263 class JAWS_Export JAWS_Asynch_IO_Handler_Factory : public JAWS_IO_Handler_Factory
265 public:
266 /// Destructor
267 virtual ~JAWS_Asynch_IO_Handler_Factory ();
269 /// This creates a new JAWS_IO_Handler
270 virtual JAWS_IO_Handler *create_io_handler ();
272 /// This deletes a JAWS_IO_Handler
273 virtual void destroy_io_handler (JAWS_IO_Handler *handler);
276 class JAWS_Export JAWS_Asynch_IO_Handler : public JAWS_IO_Handler
278 friend class JAWS_Asynch_Handler;
279 friend class JAWS_Asynch_IO_Handler_Factory;
280 friend class JAWS_Waiter;
282 // Provide implementations for the common functions.
283 public:
284 explicit JAWS_Asynch_IO_Handler (JAWS_Asynch_IO_Handler_Factory *factory);
285 virtual ~JAWS_Asynch_IO_Handler ();
287 virtual ACE_Handler *handler ();
289 virtual void acquire ();
290 virtual void lock ();
291 virtual void release ();
293 protected:
294 JAWS_Asynch_Handler *handler_;
295 ACE_SYNCH_RW_MUTEX count_;
298 #else
300 typedef JAWS_IO_Handler JAWS_Asynch_IO_Handler;
301 typedef JAWS_IO_Handler_Factory JAWS_Asynch_IO_Handler_Factory;
303 #endif /* defined(ACE_HAS_WIN32_OVERLAPPED_IO) || defined(ACE_HAS_AIO_CALLS) */
305 typedef ACE_Singleton<JAWS_Asynch_IO_Handler_Factory, ACE_SYNCH_MUTEX>
306 JAWS_Asynch_IO_Handler_Factory_Singleton;
308 #endif /* JAWS_IO_HANDLER_H */