Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef ACE_EVENT_HANDLER_H
00014 #define ACE_EVENT_HANDLER_H
00015 #include "ace/pre.h"
00016
00017 #include "ace/ACE_export.h"
00018
00019 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00020 # pragma once
00021 #endif
00022
00023 #include "ace/os_include/os_signal.h"
00024 #include "ace/Atomic_Op.h"
00025 #include "ace/Synch_Traits.h"
00026
00027 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00028
00029
00030 class ACE_Message_Block;
00031 class ACE_Reactor;
00032 class ACE_Reactor_Timer_Interface;
00033 class ACE_Thread_Manager;
00034 class ACE_Process;
00035
00036 typedef unsigned long ACE_Reactor_Mask;
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 class ACE_Export ACE_Event_Handler
00050 {
00051 public:
00052 enum
00053 {
00054 LO_PRIORITY = 0,
00055 HI_PRIORITY = 10,
00056 NULL_MASK = 0,
00057 #if defined (ACE_USE_POLL)
00058 READ_MASK = POLLIN,
00059 WRITE_MASK = POLLOUT,
00060 EXCEPT_MASK = POLLPRI,
00061 #else
00062 READ_MASK = (1 << 0),
00063 WRITE_MASK = (1 << 1),
00064 EXCEPT_MASK = (1 << 2),
00065 #endif
00066 ACCEPT_MASK = (1 << 3),
00067 CONNECT_MASK = (1 << 4),
00068 TIMER_MASK = (1 << 5),
00069 QOS_MASK = (1 << 6),
00070 GROUP_QOS_MASK = (1 << 7),
00071 SIGNAL_MASK = (1 << 8),
00072 ALL_EVENTS_MASK = READ_MASK |
00073 WRITE_MASK |
00074 EXCEPT_MASK |
00075 ACCEPT_MASK |
00076 CONNECT_MASK |
00077 TIMER_MASK |
00078 QOS_MASK |
00079 GROUP_QOS_MASK |
00080 SIGNAL_MASK,
00081 RWE_MASK = READ_MASK |
00082 WRITE_MASK |
00083 EXCEPT_MASK,
00084 DONT_CALL = (1 << 9)
00085 };
00086
00087
00088 virtual ~ACE_Event_Handler (void);
00089
00090
00091 virtual ACE_HANDLE get_handle (void) const;
00092
00093
00094 virtual void set_handle (ACE_HANDLE);
00095
00096
00097
00098
00099
00100
00101 virtual int priority (void) const;
00102
00103
00104 virtual void priority (int priority);
00105
00106
00107 virtual int handle_input (ACE_HANDLE fd = ACE_INVALID_HANDLE);
00108
00109
00110
00111 virtual int handle_output (ACE_HANDLE fd = ACE_INVALID_HANDLE);
00112
00113
00114 virtual int handle_exception (ACE_HANDLE fd = ACE_INVALID_HANDLE);
00115
00116
00117
00118
00119
00120
00121
00122 virtual int handle_timeout (const ACE_Time_Value ¤t_time,
00123 const void *act = 0);
00124
00125
00126 virtual int handle_exit (ACE_Process *);
00127
00128
00129
00130
00131
00132 virtual int handle_close (ACE_HANDLE handle,
00133 ACE_Reactor_Mask close_mask);
00134
00135
00136
00137 virtual int handle_signal (int signum, siginfo_t * = 0, ucontext_t * = 0);
00138
00139 enum
00140 {
00141
00142 ACE_EVENT_HANDLER_NOT_RESUMED = -1,
00143
00144
00145 ACE_REACTOR_RESUMES_HANDLER = 0,
00146
00147 ACE_APPLICATION_RESUMES_HANDLER
00148 };
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160 virtual int resume_handler (void);
00161
00162 virtual int handle_qos (ACE_HANDLE = ACE_INVALID_HANDLE);
00163 virtual int handle_group_qos (ACE_HANDLE = ACE_INVALID_HANDLE);
00164
00165
00166
00167 virtual void reactor (ACE_Reactor *reactor);
00168
00169
00170 virtual ACE_Reactor *reactor (void) const;
00171
00172
00173 virtual ACE_Reactor_Timer_Interface *reactor_timer_interface (void) const;
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185 static ACE_THR_FUNC_RETURN read_adapter (void *event_handler);
00186
00187
00188
00189
00190
00191
00192 static int register_stdin_handler (ACE_Event_Handler *eh,
00193 ACE_Reactor *reactor,
00194 ACE_Thread_Manager *thr_mgr,
00195 int flags = THR_DETACHED);
00196
00197
00198 static int remove_stdin_handler (ACE_Reactor *reactor,
00199 ACE_Thread_Manager *thr_mgr);
00200
00201
00202 typedef long Reference_Count;
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212 virtual Reference_Count add_reference (void);
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223 virtual Reference_Count remove_reference (void);
00224
00225
00226
00227
00228
00229
00230 class ACE_Export Policy
00231 {
00232
00233 public:
00234
00235
00236 virtual ~Policy (void);
00237 };
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252 class ACE_Export Reference_Counting_Policy : public Policy
00253 {
00254
00255 friend class ACE_Event_Handler;
00256
00257 public:
00258
00259 enum Value
00260 {
00261
00262 ENABLED,
00263
00264 DISABLED
00265 };
00266
00267
00268 Value value (void) const;
00269
00270
00271 void value (Value value);
00272
00273 private:
00274
00275
00276 Reference_Counting_Policy (Value value);
00277
00278
00279 Value value_;
00280 };
00281
00282
00283 Reference_Counting_Policy &reference_counting_policy (void);
00284
00285 protected:
00286
00287 ACE_Event_Handler (ACE_Reactor * = 0,
00288 int priority = ACE_Event_Handler::LO_PRIORITY);
00289
00290
00291 typedef ACE_Atomic_Op<ACE_SYNCH_MUTEX, Reference_Count> Atomic_Reference_Count;
00292
00293
00294 Atomic_Reference_Count reference_count_;
00295
00296 private:
00297
00298
00299 int priority_;
00300
00301
00302 ACE_Reactor *reactor_;
00303
00304
00305 Reference_Counting_Policy reference_counting_policy_;
00306 };
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316 class ACE_Export ACE_Event_Handler_var
00317 {
00318
00319 public:
00320
00321
00322 ACE_Event_Handler_var (void);
00323
00324
00325 ACE_Event_Handler_var (ACE_Event_Handler *p);
00326
00327
00328 ACE_Event_Handler_var (const ACE_Event_Handler_var &b);
00329
00330
00331 ~ACE_Event_Handler_var (void);
00332
00333
00334 ACE_Event_Handler_var &operator= (ACE_Event_Handler *p);
00335
00336
00337 ACE_Event_Handler_var &operator= (const ACE_Event_Handler_var &b);
00338
00339
00340 ACE_Event_Handler *operator-> () const;
00341
00342
00343 ACE_Event_Handler *handler (void) const;
00344
00345
00346 ACE_Event_Handler *release (void);
00347
00348
00349 void reset (ACE_Event_Handler *p = 0);
00350
00351 private:
00352
00353
00354 ACE_Event_Handler *ptr_;
00355 };
00356
00357
00358
00359
00360
00361
00362
00363 class ACE_Export ACE_Notification_Buffer
00364 {
00365 public:
00366 ACE_Notification_Buffer (void);
00367
00368 ACE_Notification_Buffer (ACE_Event_Handler *eh,
00369 ACE_Reactor_Mask mask);
00370
00371
00372 ~ACE_Notification_Buffer (void);
00373
00374
00375
00376 ACE_Event_Handler *eh_;
00377
00378
00379 ACE_Reactor_Mask mask_;
00380 };
00381
00382 ACE_END_VERSIONED_NAMESPACE_DECL
00383
00384 #if defined (__ACE_INLINE__)
00385 #include "ace/Event_Handler.inl"
00386 #endif
00387
00388 #include "ace/post.h"
00389 #endif