Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

Event_Handler.h

Go to the documentation of this file.
00001 /* -*- C++ -*- */
00002 
00003 //==========================================================================
00004 /**
00005  *  @file    Event_Handler.h
00006  *
00007  *  $Id: Event_Handler.h,v 1.1.1.4 2003/02/21 18:36:32 chad Exp $
00008  *
00009  *  @author Douglas C. Schmidt <schmidt@cs.wustl.edu>
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 /* ACE_LACKS_PRAGMA_ONCE */
00022 
00023 #include "ace/OS.h"
00024 
00025 // Forward declaration.
00026 class ACE_Message_Block;
00027 class ACE_Reactor;
00028 class ACE_Thread_Manager;
00029 class ACE_Process;
00030 
00031 typedef u_long ACE_Reactor_Mask;
00032 
00033 /**
00034  * @class ACE_Event_Handler
00035  *
00036  * @brief Provides an abstract interface for handling various types of
00037  * I/O, timer, and signal events.
00038  *
00039  * Subclasses read/write input/output on an I/O descriptor,
00040  * handle an exception raised on an I/O descriptor, handle a
00041  * timer's expiration, or handle a signal.
00042  */
00043 class ACE_Export ACE_Event_Handler
00044 {
00045 public:
00046   enum
00047   {
00048     LO_PRIORITY = 0,
00049     HI_PRIORITY = 10,
00050     NULL_MASK = 0,
00051 #if defined (ACE_USE_POLL)
00052     READ_MASK = POLLIN,
00053     WRITE_MASK = POLLOUT,
00054     EXCEPT_MASK = POLLPRI,
00055 #else /* USE SELECT */
00056     READ_MASK = (1 << 0),
00057     WRITE_MASK = (1 << 1),
00058     EXCEPT_MASK = (1 << 2),
00059 #endif /* ACE_USE_POLL */
00060     ACCEPT_MASK = (1 << 3),
00061     CONNECT_MASK = (1 << 4),
00062     TIMER_MASK = (1 << 5),
00063     QOS_MASK = (1 << 6),
00064     GROUP_QOS_MASK = (1 << 7),
00065     SIGNAL_MASK = (1 << 8),
00066     ALL_EVENTS_MASK = READ_MASK |
00067                       WRITE_MASK |
00068                       EXCEPT_MASK |
00069                       ACCEPT_MASK |
00070                       CONNECT_MASK |
00071                       TIMER_MASK |
00072                       QOS_MASK |
00073                       GROUP_QOS_MASK |
00074                       SIGNAL_MASK,
00075     RWE_MASK = READ_MASK |
00076                WRITE_MASK |
00077                EXCEPT_MASK,
00078     DONT_CALL = (1 << 9)
00079   };
00080 
00081   /// Destructor is virtual to enable proper cleanup.
00082   virtual ~ACE_Event_Handler (void);
00083 
00084   /// Get the I/O handle.
00085   virtual ACE_HANDLE get_handle (void) const;
00086 
00087   /// Set the I/O handle.
00088   virtual void set_handle (ACE_HANDLE);
00089 
00090   // = Get/set priority
00091 
00092   // Priorities run from MIN_PRIORITY (which is the "lowest priority")
00093   // to MAX_PRIORITY (which is the "highest priority").
00094   /// Get the priority of the Event_Handler.
00095   virtual int priority (void) const;
00096 
00097   /// Set the priority of the Event_Handler.
00098   virtual void priority (int priority);
00099 
00100   /// Called when input events occur (e.g., connection or data).
00101   virtual int handle_input (ACE_HANDLE fd = ACE_INVALID_HANDLE);
00102 
00103   /// Called when output events are possible (e.g., when flow control
00104   /// abates or non-blocking connection completes).
00105   virtual int handle_output (ACE_HANDLE fd = ACE_INVALID_HANDLE);
00106 
00107   /// Called when an exceptional events occur (e.g., SIGURG).
00108   virtual int handle_exception (ACE_HANDLE fd = ACE_INVALID_HANDLE);
00109 
00110   /**
00111    * Called when timer expires.  <current_time> represents the current
00112    * time that the <Event_Handler> was selected for timeout
00113    * dispatching and <act> is the asynchronous completion token that
00114    * was passed in when <schedule_timer> was invoked.
00115    */
00116   virtual int handle_timeout (const ACE_Time_Value &current_time,
00117                               const void *act = 0);
00118 
00119   /// Called when a process exits.
00120   virtual int handle_exit (ACE_Process *);
00121 
00122   /// Called when a <handle_*()> method returns -1 or when the
00123   /// <remove_handler> method is called on an <ACE_Reactor>.  The
00124   /// <close_mask> indicates which event has triggered the
00125   /// <handle_close> method callback on a particular <handle>.
00126   virtual int handle_close (ACE_HANDLE handle,
00127                             ACE_Reactor_Mask close_mask);
00128 
00129   /// Called when object is signaled by OS (either via UNIX signals or
00130   /// when a Win32 object becomes signaled).
00131   virtual int handle_signal (int signum, siginfo_t * = 0, ucontext_t * = 0);
00132 
00133   enum
00134     {
00135       /// The handler is not resumed at all. Could lead to deadlock..
00136       ACE_EVENT_HANDLER_NOT_RESUMED = -1,
00137       /// The reactor takes responsibility of resuming the handler and
00138       /// is the default
00139       ACE_REACTOR_RESUMES_HANDLER = 0,
00140       /// The application takes responsibility of resuming the handler
00141       ACE_APPLICATION_RESUMES_HANDLER
00142     };
00143   /* Called to figure out whether the handler needs to resumed by the
00144    * reactor or the application can take care of it. The default
00145    * value of 0 would be returned which would allow the reactor to
00146    * take care of resumption of the handler. The application can
00147    * return a value more than zero and decide to resume the handler
00148    * themseleves.
00149    */
00150   // @@ NOTE: This method is only useful for the ACE_TP_Reactor. Sad
00151   // that we have to have this method in a class that is supposed to
00152   // be used across different componets in ACE.
00153   virtual int resume_handler (void);
00154 
00155   virtual int handle_qos (ACE_HANDLE = ACE_INVALID_HANDLE);
00156   virtual int handle_group_qos (ACE_HANDLE = ACE_INVALID_HANDLE);
00157 
00158   // = Accessors to set/get the various event demultiplexors.
00159   /// Set the event demultiplexors.
00160   virtual void reactor (ACE_Reactor *reactor);
00161 
00162   /// Get the event demultiplexors.
00163   virtual ACE_Reactor *reactor (void) const;
00164 
00165 #if !defined (ACE_HAS_WINCE)
00166   /**
00167    * Used to read from non-socket ACE_HANDLEs in our own thread to
00168    * work around Win32 limitations that don't allow us to <select> on
00169    * non-sockets (such as ACE_STDIN).  This is commonly used in
00170    * situations where the Reactor is used to demultiplex read events
00171    * on ACE_STDIN on UNIX.  Note that <event_handler> must be a
00172    * subclass of <ACE_Event_Handler>.  If the <get_handle> method of
00173    * this event handler returns <ACE_INVALID_HANDLE> we default to
00174    * reading from ACE_STDIN.
00175    */
00176   static ACE_THR_FUNC_RETURN read_adapter (void *event_handler);
00177 
00178   /**
00179    * Abstracts away from the differences between Win32 and ACE with
00180    * respect to reading from ACE_STDIN, which is non-<select>'able on
00181    * Win32.
00182    */
00183   static int register_stdin_handler (ACE_Event_Handler *eh,
00184                                      ACE_Reactor *reactor,
00185                                      ACE_Thread_Manager *thr_mgr,
00186                                      int flags = THR_DETACHED);
00187 
00188   /// Performs the inverse of the <register_stdin_handler> method.
00189   static int remove_stdin_handler (ACE_Reactor *reactor,
00190                                    ACE_Thread_Manager *thr_mgr);
00191 #endif /* ACE_HAS_WINCE */
00192 
00193 protected:
00194   /// Force ACE_Event_Handler to be an abstract base class.
00195   ACE_Event_Handler (ACE_Reactor * = 0,
00196                      int priority = ACE_Event_Handler::LO_PRIORITY);
00197 
00198 private:
00199 
00200   /// Priority of this Event_Handler.
00201   int priority_;
00202 
00203   /// Pointer to the various event demultiplexors.
00204   ACE_Reactor *reactor_;
00205 };
00206 
00207 /**
00208  * @class ACE_Notification_Buffer
00209  *
00210  * @brief Simple wrapper for passing <ACE_Event_Handler *>s and
00211  * <ACE_Reactor_Mask>s between threads.
00212  */
00213 class ACE_Export ACE_Notification_Buffer
00214 {
00215 public:
00216   ACE_Notification_Buffer (void);
00217 
00218   ACE_Notification_Buffer (ACE_Event_Handler *eh,
00219                            ACE_Reactor_Mask mask);
00220 
00221   /// Default dtor.
00222   ~ACE_Notification_Buffer (void);
00223 
00224   /// Pointer to the Event_Handler that will be dispatched
00225   /// by the main event loop.
00226   ACE_Event_Handler *eh_;
00227 
00228   /// Mask that indicates which method to call.
00229   ACE_Reactor_Mask mask_;
00230 };
00231 
00232 #if defined (__ACE_INLINE__)
00233 #include "ace/Event_Handler.i"
00234 #endif /* __ACE_INLINE__ */
00235 
00236 #include "ace/post.h"
00237 #endif /* ACE_EVENT_HANDLER_H */

Generated on Mon Jun 16 11:19:38 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002