Event_Handler_T.h

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

Generated on Thu Nov 9 09:41:50 2006 for ACE by doxygen 1.3.6