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

Event_Handler_T.h

Go to the documentation of this file.
00001 /* -*- C++ -*- */
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    Event_Handler_T.h
00006  *
00007  *  $Id: Event_Handler_T.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_T_H
00014 #define ACE_EVENT_HANDLER_T_H
00015 #include "ace/pre.h"
00016 
00017 #include "ace/Event_Handler.h"
00018 
00019 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00020 # pragma once
00021 #endif /* ACE_LACKS_PRAGMA_ONCE */
00022 
00023 #if defined (ACE_HAS_TEMPLATE_TYPEDEFS)
00024 
00025 /**
00026  * @class ACE_Event_Handler_T
00027  *
00028  * @brief Enable a class that doesn't inherit from the
00029  * ACE_Event_Handler to be incorporated into the ACE_Reactor
00030  * framework.  Thanks to Greg Lavender (g.lavender@isode.com)
00031  * for sharing this idea.
00032  *
00033  * It is sometimes the case that an application has a hierarchy
00034  * of operation dispatcher classes that have their own
00035  * inheritance hierarchy but also would like to integrate with
00036  * the ACE_Reactor.  Rather than adopt a "mixin" approach, it is
00037  * often cleaner to define a template as a subclass of
00038  * ACE_Event_Handler and paramterize it with an operation
00039  * dispatcher type.
00040  * When constructing an instantiation of the ACE_Event_Handler_T
00041  * object, a set of pointers to member functions must be
00042  * provided so that when one of the handle_* methods is called
00043  * by the ACE_Reactor, the appropriate method is called on the
00044  * underlying operations object.  This is done since in some
00045  * cases it is useful to map any event that happens to the same
00046  * method on an object.
00047  * The ACE_Event_Handler_T template is instantiated by an
00048  * operations object and registered with the ACE_Reactor, and it
00049  * then calls the appropriate op_handler.  So, it's basically
00050  * just another level of indirection in event dispatching. The
00051  * coupling betweent the ultimate handler of the event and the
00052  * ACE_Event_Handler class is relaxed a bit by have this
00053  * intermediate <op_handler_> object of type <T> around. The
00054  * client object can then dynamically change the bindings for
00055  * the various handlers so that during the life of one of the
00056  * operation objects, it can change how it wants events to be
00057  * handled. It just instantiates a new instance of the template
00058  * with different bindings and reregisters this new object with
00059  * the ACE_Reactor.
00060  */
00061 template <class T>
00062 class ACE_Event_Handler_T : public ACE_Event_Handler
00063 {
00064 public:
00065   // = Typedefs to simplify pointer-to-member-function registration.
00066 
00067   // Get/set the underlying handle.
00068   typedef ACE_HANDLE (T::*GET_HANDLE) (void) const;
00069   typedef void (T::*SET_HANDLE) (ACE_HANDLE);
00070 
00071   /// Handle I/O events.
00072   typedef int (T::*IO_HANDLER) (ACE_HANDLE);
00073 
00074   /// Handle timeout events.
00075   typedef int (T::*TO_HANDLER) (const ACE_Time_Value &, const void *);
00076 
00077   /// Handle close events.
00078   typedef int (T::*CL_HANDLER) (ACE_HANDLE, ACE_Reactor_Mask);
00079 
00080   /// = Initialization and termination methods.
00081   typedef int (T::*SIG_HANDLER) (ACE_HANDLE, siginfo_t*, ucontext_t*);
00082 
00083   /// Initialize the op_handler.
00084   ACE_Event_Handler_T (T *op_handler,
00085                        int delete_handler,
00086                        GET_HANDLE get_handle = 0,
00087                        IO_HANDLER input = 0,
00088                        CL_HANDLER close = 0,
00089                        SIG_HANDLER sig = 0,
00090                        TO_HANDLER timeout = 0,
00091                        IO_HANDLER output = 0,
00092                        SET_HANDLE set_handle = 0,
00093                        IO_HANDLER except = 0);
00094 
00095   /// Close down and delete the <op_handler>
00096   ~ACE_Event_Handler_T (void);
00097 
00098   // = Override all the ACE_Event_Handler methods.
00099 
00100   // These methods all delegate down to the <T> operations handler.
00101   virtual ACE_HANDLE get_handle (void) const;
00102   virtual void set_handle (ACE_HANDLE);
00103   virtual int handle_input (ACE_HANDLE fd = -1);
00104   virtual int handle_output (ACE_HANDLE fd = -1);
00105   virtual int handle_exception (ACE_HANDLE fd = -1);
00106   virtual int handle_timeout (const ACE_Time_Value &tv, const void *arg = 0);
00107   virtual int handle_close (ACE_HANDLE fd, ACE_Reactor_Mask close_mask);
00108   virtual int handle_signal (int signum, siginfo_t * = 0, ucontext_t * = 0);
00109 
00110   // = Get/set the operations handler.
00111   T *op_handler (void);
00112   void op_handler (T *);
00113 
00114   // = Get/set the target pointer-to-method used for dispatching.
00115 
00116   GET_HANDLE handle_get (void);
00117   void handle_get (GET_HANDLE);
00118 
00119   SET_HANDLE handle_set (void);
00120   void handle_set (SET_HANDLE);
00121 
00122   IO_HANDLER input_handler (void);
00123   void input_handler (IO_HANDLER);
00124 
00125   IO_HANDLER output_handler (void);
00126   void output_handler (IO_HANDLER);
00127 
00128   IO_HANDLER except_handler (void);
00129   void except_handler (IO_HANDLER);
00130 
00131   TO_HANDLER to_handler (void);
00132   void to_handler (TO_HANDLER);
00133 
00134   CL_HANDLER cl_handler (void);
00135   void cl_handler (CL_HANDLER);
00136 
00137   SIG_HANDLER sig_handler (void);
00138   void sig_handler (SIG_HANDLER);
00139 
00140   /// Dump the state of an object.
00141   void dump (void) const;
00142 
00143   /// Declare the dynamic allocation hooks.
00144   ACE_ALLOC_HOOK_DECLARE;
00145 
00146 protected:
00147   /// Pointer to the object that handles all the delegated operations.
00148   T *op_handler_;
00149 
00150   // = Handle input, output, and exception events.
00151   IO_HANDLER input_handler_;
00152   IO_HANDLER output_handler_;
00153   IO_HANDLER except_handler_;
00154 
00155   /// Handle timeout events.
00156   TO_HANDLER to_handler_;
00157 
00158   /// Handle close events.
00159   CL_HANDLER cl_handler_;
00160 
00161   /// Handle signal events.
00162   SIG_HANDLER sig_handler_;
00163 
00164   /// Keeps track of whether we need to delete the handler in the
00165   /// destructor.
00166   int delete_handler_;
00167 
00168   // = Get/set underlying handle.
00169   SET_HANDLE set_handle_;
00170   GET_HANDLE get_handle_;
00171 };
00172 
00173 #if defined (__ACE_INLINE__)
00174 #include "ace/Event_Handler_T.i"
00175 #endif /* __ACE_INLINE__ */
00176 
00177 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
00178 #include "ace/Event_Handler_T.cpp"
00179 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
00180 
00181 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
00182 #pragma implementation ("Event_Handler_T.cpp")
00183 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
00184 
00185 #endif /* ACE_HAS_TEMPLATE_TYPEDEFS */
00186 #include "ace/post.h"
00187 #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