Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / ACE / apps / JAWS3 / jaws3 / Reactive_IO_Helpers.h
blob08258f888df3940cd984649cc3cfef76ddf6a8ed
1 /* -*- c++ -*- */
2 #ifndef JAWS_REACTIVE_IO_HELPERS_H
3 #define JAWS_REACTIVE_IO_HELPERS_H
5 #include "ace/Event_Handler.h"
6 #include "ace/Message_Block.h"
7 #include "ace/Singleton.h"
8 #include "ace/Time_Value.h"
10 #include "jaws3/Export.h"
11 #include "jaws3/Jaws_IO.h"
12 #include "jaws3/Event_Result.h"
13 #include "jaws3/Event_Completer.h"
15 class JAWS_Reactive_IO;
17 class JAWS_IO_Reactive_Handler : public ACE_Event_Handler
19 friend class JAWS_IO_Reactive_Send;
20 friend class JAWS_IO_Reactive_Recv;
21 friend class JAWS_IO_Reactive_Transmit;
23 public:
24 virtual void open ();
26 int handle_timeout (const ACE_Time_Value &, const void *);
28 int handle_close (ACE_HANDLE, ACE_Reactor_Mask);
30 int handle_exception (ACE_HANDLE);
32 ACE_HANDLE get_handle () const { return this->handle_; }
34 void set_handle (ACE_HANDLE handle) { this->handle_ = handle; }
36 protected:
37 virtual void close (int result);
39 private:
40 JAWS_IO_Reactive_Handler ( ACE_HANDLE handle
41 , JAWS_Event_Completer *completer
42 , const ACE_Time_Value &tv
43 , void *act
44 , ACE_Reactor_Mask mask
46 : bytes_ (0)
47 , handle_ (handle)
48 , completer_ (completer)
49 , tv_ (tv)
50 , act_ (act)
51 , mask_ (mask)
52 , timer_id_ (-1)
53 , was_active_ (0)
55 if (ACE_Time_Value::zero < this->tv_)
56 this->timer_id_ =
57 ACE_Reactor::instance ()->schedule_timer (this, 0, this->tv_);
60 public: // needed for destructor due to "aCC: HP ANSI C++ B3910B A.03.39" compiler bug
62 ~JAWS_IO_Reactive_Handler ()
64 if (this->timer_id_ != -1)
65 ACE_Reactor::instance ()->cancel_timer (this->timer_id_);
68 private:
69 JAWS_Event_Result io_result_;
71 size_t bytes_;
72 ACE_HANDLE handle_;
73 JAWS_Event_Completer *completer_;
74 ACE_Time_Value tv_;
75 void *act_;
77 ACE_Reactor_Mask mask_;
78 long timer_id_;
80 int was_active_;
84 class JAWS_IO_Reactive_Send : public JAWS_IO_Reactive_Handler
86 friend class JAWS_Reactive_IO;
88 public:
89 int handle_output (ACE_HANDLE handle);
91 static JAWS_IO_Reactive_Send * make ( ACE_HANDLE handle
92 , ACE_Message_Block *mb
93 , JAWS_Event_Completer *completer
94 , void *act
97 return new JAWS_IO_Reactive_Send ( handle
98 , mb
99 , completer
100 , ACE_Time_Value::zero
101 , act
102 , ACE_Event_Handler::WRITE_MASK
106 static JAWS_IO_Reactive_Send * make ( ACE_HANDLE handle
107 , ACE_Message_Block *mb
108 , JAWS_Event_Completer *completer
109 , const ACE_Time_Value &tv
110 , void *act
113 return new JAWS_IO_Reactive_Send ( handle
114 , mb
115 , completer
116 , tv
117 , act
118 , ACE_Event_Handler::WRITE_MASK
122 private:
123 JAWS_IO_Reactive_Send ( ACE_HANDLE handle
124 , ACE_Message_Block *mb
125 , JAWS_Event_Completer *completer
126 , const ACE_Time_Value &tv
127 , void *act
128 , ACE_Reactor_Mask mask
130 : JAWS_IO_Reactive_Handler (handle, completer, tv, act, mask)
131 , mb_ (mb)
135 private:
136 ACE_Message_Block *mb_;
140 class JAWS_IO_Reactive_Recv : public JAWS_IO_Reactive_Handler
142 friend class JAWS_Reactive_IO;
144 public:
145 int handle_input (ACE_HANDLE handle);
147 static JAWS_IO_Reactive_Recv * make ( ACE_HANDLE handle
148 , ACE_Message_Block *mb
149 , JAWS_Event_Completer *completer
150 , void *act
153 return new JAWS_IO_Reactive_Recv ( handle
154 , mb
155 , completer
156 , ACE_Time_Value::zero
157 , act
158 , ACE_Event_Handler::READ_MASK
162 static JAWS_IO_Reactive_Recv * make ( ACE_HANDLE handle
163 , ACE_Message_Block *mb
164 , JAWS_Event_Completer *completer
165 , const ACE_Time_Value &tv
166 , void *act
169 return new JAWS_IO_Reactive_Recv ( handle
170 , mb
171 , completer
172 , tv
173 , act
174 , ACE_Event_Handler::READ_MASK
178 private:
179 JAWS_IO_Reactive_Recv ( ACE_HANDLE handle
180 , ACE_Message_Block *mb
181 , JAWS_Event_Completer *completer
182 , const ACE_Time_Value &tv
183 , void *act
184 , ACE_Reactor_Mask mask
186 : JAWS_IO_Reactive_Handler (handle, completer, tv, act, mask)
187 , mb_ (mb)
191 private:
192 ACE_Message_Block *mb_;
196 class JAWS_IO_Reactive_Transmit : public JAWS_IO_Reactive_Handler
198 friend class JAWS_Reactive_IO;
200 public:
201 int handle_timeout (const ACE_Time_Value &, const void *);
203 int handle_output (ACE_HANDLE handle);
205 int handle_exception (ACE_HANDLE handle);
207 static JAWS_IO_Reactive_Transmit * make ( ACE_HANDLE handle
208 , ACE_HANDLE source
209 , JAWS_Event_Completer *completer
210 , ACE_Message_Block *header
211 , ACE_Message_Block *trailer
212 , void *act
215 return new JAWS_IO_Reactive_Transmit ( handle
216 , source
217 , completer
218 , ACE_Time_Value::zero
219 , header
220 , trailer
221 , act
222 , ACE_Event_Handler::WRITE_MASK
226 static JAWS_IO_Reactive_Transmit * make ( ACE_HANDLE handle
227 , ACE_HANDLE source
228 , JAWS_Event_Completer *completer
229 , const ACE_Time_Value &tv
230 , ACE_Message_Block *header
231 , ACE_Message_Block *trailer
232 , void *act
235 return new JAWS_IO_Reactive_Transmit ( handle
236 , source
237 , completer
238 , tv
239 , header
240 , trailer
241 , act
242 , ACE_Event_Handler::WRITE_MASK
246 protected:
247 void close (int result);
249 int handle_output_header (ACE_HANDLE handle);
251 int handle_output_source (ACE_HANDLE handle);
253 int handle_output_trailer (ACE_HANDLE handle);
255 int handle_output_mb (ACE_HANDLE handle, ACE_Message_Block *&mb);
257 private:
258 JAWS_IO_Reactive_Transmit ( ACE_HANDLE handle
259 , ACE_HANDLE source
260 , JAWS_Event_Completer *completer
261 , const ACE_Time_Value &tv
262 , ACE_Message_Block *header
263 , ACE_Message_Block *trailer
264 , void *act
265 , ACE_Reactor_Mask mask
267 : JAWS_IO_Reactive_Handler (handle, completer, tv, act, mask)
268 , source_ (source)
269 , source_mb_ (8 * 1024)
270 , source_buf_ (& this->source_mb_)
271 , header_ (header)
272 , trailer_ (trailer)
276 private:
277 ACE_HANDLE source_;
278 ACE_Message_Block source_mb_;
279 ACE_Message_Block *source_buf_;
280 ACE_Message_Block *header_;
281 ACE_Message_Block *trailer_;
284 #endif /* JAWS_REACTIVE_IO_HELPERS_H */