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 class ACE_Export ACE_Event_Handler
00049 {
00050 public:
00051   enum
00052   {
00053     LO_PRIORITY = 0,
00054     HI_PRIORITY = 10,
00055     NULL_MASK = 0,
00056 #if defined (ACE_USE_POLL)
00057     READ_MASK = POLLIN,
00058     WRITE_MASK = POLLOUT,
00059     EXCEPT_MASK = POLLPRI,
00060 #else 
00061     READ_MASK = (1 << 0),
00062     WRITE_MASK = (1 << 1),
00063     EXCEPT_MASK = (1 << 2),
00064 #endif 
00065     ACCEPT_MASK = (1 << 3),
00066     CONNECT_MASK = (1 << 4),
00067     TIMER_MASK = (1 << 5),
00068     QOS_MASK = (1 << 6),
00069     GROUP_QOS_MASK = (1 << 7),
00070     SIGNAL_MASK = (1 << 8),
00071     ALL_EVENTS_MASK = READ_MASK |
00072                       WRITE_MASK |
00073                       EXCEPT_MASK |
00074                       ACCEPT_MASK |
00075                       CONNECT_MASK |
00076                       TIMER_MASK |
00077                       QOS_MASK |
00078                       GROUP_QOS_MASK |
00079                       SIGNAL_MASK,
00080     RWE_MASK = READ_MASK |
00081                WRITE_MASK |
00082                EXCEPT_MASK,
00083     DONT_CALL = (1 << 9)
00084   };
00085 
00086 
00087   virtual ~ACE_Event_Handler (void);
00088 
00089 
00090   virtual ACE_HANDLE get_handle (void) const;
00091 
00092 
00093   virtual void set_handle (ACE_HANDLE);
00094 
00095   
00096 
00097   
00098   
00099 
00100   virtual int priority (void) const;
00101 
00102 
00103   virtual void priority (int priority);
00104 
00105 
00106   virtual int handle_input (ACE_HANDLE fd = ACE_INVALID_HANDLE);
00107 
00108 
00109 
00110   virtual int handle_output (ACE_HANDLE fd = ACE_INVALID_HANDLE);
00111 
00112 
00113   virtual int handle_exception (ACE_HANDLE fd = ACE_INVALID_HANDLE);
00114 
00115 
00116 
00117 
00118 
00119 
00120 
00121   virtual int handle_timeout (const ACE_Time_Value ¤t_time,
00122                               const void *act = 0);
00123 
00124 
00125   virtual int handle_exit (ACE_Process *);
00126 
00127 
00128 
00129 
00130 
00131   virtual int handle_close (ACE_HANDLE handle,
00132                             ACE_Reactor_Mask close_mask);
00133 
00134 
00135 
00136   virtual int handle_signal (int signum, siginfo_t * = 0, ucontext_t * = 0);
00137 
00138   enum
00139     {
00140 
00141       ACE_EVENT_HANDLER_NOT_RESUMED = -1,
00142 
00143 
00144       ACE_REACTOR_RESUMES_HANDLER = 0,
00145 
00146       ACE_APPLICATION_RESUMES_HANDLER
00147     };
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 
00186   static ACE_THR_FUNC_RETURN read_adapter (void *event_handler);
00187 
00188 
00189 
00190 
00191 
00192 
00193   static int register_stdin_handler (ACE_Event_Handler *eh,
00194                                      ACE_Reactor *reactor,
00195                                      ACE_Thread_Manager *thr_mgr,
00196                                      int flags = THR_DETACHED);
00197 
00198 
00199   static int remove_stdin_handler (ACE_Reactor *reactor,
00200                                    ACE_Thread_Manager *thr_mgr);
00201   
00202 
00203 
00204   typedef long Reference_Count;
00205 
00206 
00207 
00208 
00209 
00210 
00211 
00212 
00213 
00214   virtual Reference_Count add_reference (void);
00215 
00216 
00217 
00218 
00219 
00220 
00221 
00222 
00223 
00224 
00225   virtual Reference_Count remove_reference (void);
00226 
00227 
00228 
00229 
00230 
00231 
00232   class ACE_Export Policy
00233   {
00234 
00235   public:
00236 
00237 
00238     virtual ~Policy (void);
00239   };
00240 
00241 
00242 
00243 
00244 
00245 
00246 
00247 
00248 
00249 
00250 
00251 
00252 
00253   class ACE_Export Reference_Counting_Policy : public Policy
00254   {
00255 
00256     friend class ACE_Event_Handler;
00257 
00258   public:
00259 
00260     enum Value
00261       {
00262 
00263         ENABLED,
00264 
00265         DISABLED
00266       };
00267 
00268 
00269     Value value (void) const;
00270 
00271 
00272     void value (Value value);
00273 
00274   private:
00275 
00276 
00277     Reference_Counting_Policy (Value value);
00278 
00279 
00280     Value value_;
00281    };
00282 
00283 
00284   Reference_Counting_Policy &reference_counting_policy (void);
00285 
00286 protected:
00287 
00288   ACE_Event_Handler (ACE_Reactor * = 0,
00289                      int priority = ACE_Event_Handler::LO_PRIORITY);
00290 
00291 
00292   typedef ACE_Atomic_Op<ACE_SYNCH_MUTEX, Reference_Count> Atomic_Reference_Count;
00293 
00294 
00295   Atomic_Reference_Count reference_count_;
00296 
00297 private:
00298 
00299 
00300   int priority_;
00301 
00302 
00303   ACE_Reactor *reactor_;
00304 
00305 
00306   Reference_Counting_Policy reference_counting_policy_;
00307 };
00308 
00309 
00310 
00311 
00312 
00313 
00314 
00315 
00316 
00317 class ACE_Export ACE_Event_Handler_var
00318 {
00319 
00320 public:
00321 
00322 
00323   ACE_Event_Handler_var (void);
00324 
00325 
00326   ACE_Event_Handler_var (ACE_Event_Handler *p);
00327 
00328 
00329   ACE_Event_Handler_var (const ACE_Event_Handler_var &b);
00330 
00331 
00332   ~ACE_Event_Handler_var (void);
00333 
00334 
00335   ACE_Event_Handler_var &operator= (ACE_Event_Handler *p);
00336 
00337 
00338   ACE_Event_Handler_var &operator= (const ACE_Event_Handler_var &b);
00339 
00340 
00341   ACE_Event_Handler *operator-> () const;
00342 
00343 
00344   ACE_Event_Handler *handler (void) const;
00345 
00346 
00347   ACE_Event_Handler *release (void);
00348 
00349 
00350   void reset (ACE_Event_Handler *p = 0);
00351 
00352 private:
00353 
00354 
00355   ACE_Event_Handler *ptr_;
00356 };
00357 
00358 
00359 
00360 
00361 
00362 
00363 
00364 class ACE_Export ACE_Notification_Buffer
00365 {
00366 public:
00367   ACE_Notification_Buffer (void);
00368 
00369   ACE_Notification_Buffer (ACE_Event_Handler *eh,
00370                            ACE_Reactor_Mask mask);
00371 
00372 
00373   ~ACE_Notification_Buffer (void);
00374 
00375 
00376 
00377   ACE_Event_Handler *eh_;
00378 
00379 
00380   ACE_Reactor_Mask mask_;
00381 };
00382 
00383 ACE_END_VERSIONED_NAMESPACE_DECL
00384 
00385 #if defined (__ACE_INLINE__)
00386 #include "ace/Event_Handler.inl"
00387 #endif 
00388 
00389 #include  "ace/post.h"
00390 #endif