ACE_Event_Handler_T< T > Class Template Reference

Enable a class that doesn't inherit from the ACE_Event_Handler to be incorporated into the ACE_Reactor framework. Thanks to Greg Lavender (g.lavender@isode.com) for sharing this idea. More...

#include <Event_Handler_T.h>

Inheritance diagram for ACE_Event_Handler_T< T >:

Inheritance graph
[legend]
Collaboration diagram for ACE_Event_Handler_T< T >:

Collaboration graph
[legend]
List of all members.

Public Types

typedef ACE_HANDLE(T::* GET_HANDLE )(void) const
typedef void(T::* SET_HANDLE )(ACE_HANDLE)
typedef int(T::* IO_HANDLER )(ACE_HANDLE)
 Handle I/O events.

typedef int(T::* TO_HANDLER )(const ACE_Time_Value &, const void *)
 Handle timeout events.

typedef int(T::* CL_HANDLER )(ACE_HANDLE, ACE_Reactor_Mask)
 Handle close events.

typedef int(T::* SIG_HANDLER )(int, siginfo_t *, ucontext_t *)
 = Initialization and termination methods.


Public Member Functions

 ACE_Event_Handler_T (T *op_handler, int delete_handler, GET_HANDLE get_handle=0, IO_HANDLER input=0, CL_HANDLER close=0, SIG_HANDLER sig=0, TO_HANDLER timeout=0, IO_HANDLER output=0, SET_HANDLE set_handle=0, IO_HANDLER except=0)
 Initialize the op_handler.

 ~ACE_Event_Handler_T (void)
 Close down and delete the .

virtual ACE_HANDLE get_handle (void) const
 Get the I/O handle.

virtual void set_handle (ACE_HANDLE)
 Set the I/O handle.

virtual int handle_input (ACE_HANDLE fd=ACE_INVALID_HANDLE)
 Called when input events occur (e.g., connection or data).

virtual int handle_output (ACE_HANDLE fd=ACE_INVALID_HANDLE)
virtual int handle_exception (ACE_HANDLE fd=ACE_INVALID_HANDLE)
 Called when an exceptional events occur (e.g., SIGURG).

virtual int handle_timeout (const ACE_Time_Value &tv, const void *arg=0)
virtual int handle_close (ACE_HANDLE fd, ACE_Reactor_Mask close_mask)
virtual int handle_signal (int signum, siginfo_t *=0, ucontext_t *=0)
T * op_handler (void)
void op_handler (T *)
GET_HANDLE handle_get (void)
void handle_get (GET_HANDLE)
SET_HANDLE handle_set (void)
void handle_set (SET_HANDLE)
IO_HANDLER input_handler (void)
void input_handler (IO_HANDLER)
IO_HANDLER output_handler (void)
void output_handler (IO_HANDLER)
IO_HANDLER except_handler (void)
void except_handler (IO_HANDLER)
TO_HANDLER to_handler (void)
void to_handler (TO_HANDLER)
CL_HANDLER cl_handler (void)
void cl_handler (CL_HANDLER)
SIG_HANDLER sig_handler (void)
void sig_handler (SIG_HANDLER)
void dump (void) const
 Dump the state of an object.


Public Attributes

 ACE_ALLOC_HOOK_DECLARE
 Declare the dynamic allocation hooks.


Protected Attributes

T * op_handler_
 Pointer to the object that handles all the delegated operations.

IO_HANDLER input_handler_
IO_HANDLER output_handler_
IO_HANDLER except_handler_
TO_HANDLER to_handler_
 Handle timeout events.

CL_HANDLER cl_handler_
 Handle close events.

SIG_HANDLER sig_handler_
 Handle signal events.

int delete_handler_
SET_HANDLE set_handle_
GET_HANDLE get_handle_

Detailed Description

template<class T>
class ACE_Event_Handler_T< T >

Enable a class that doesn't inherit from the ACE_Event_Handler to be incorporated into the ACE_Reactor framework. Thanks to Greg Lavender (g.lavender@isode.com) for sharing this idea.

It is sometimes the case that an application has a hierarchy of operation dispatcher classes that have their own inheritance hierarchy but also would like to integrate with the ACE_Reactor. Rather than adopt a "mixin" approach, it is often cleaner to define a template as a subclass of ACE_Event_Handler and paramterize it with an operation dispatcher type. When constructing an instantiation of the ACE_Event_Handler_T object, a set of pointers to member functions must be provided so that when one of the handle_* methods is called by the ACE_Reactor, the appropriate method is called on the underlying operations object. This is done since in some cases it is useful to map any event that happens to the same method on an object. The ACE_Event_Handler_T template is instantiated by an operations object and registered with the ACE_Reactor, and it then calls the appropriate op_handler. So, it's basically just another level of indirection in event dispatching. The coupling betweent the ultimate handler of the event and the ACE_Event_Handler class is relaxed a bit by have this intermediate object of type around. The client object can then dynamically change the bindings for the various handlers so that during the life of one of the operation objects, it can change how it wants events to be handled. It just instantiates a new instance of the template with different bindings and reregisters this new object with the ACE_Reactor.

Definition at line 64 of file Event_Handler_T.h.


Member Typedef Documentation

template<class T>
typedef int(T::* ACE_Event_Handler_T< T >::CL_HANDLER)(ACE_HANDLE, ACE_Reactor_Mask)
 

Handle close events.

Definition at line 80 of file Event_Handler_T.h.

Referenced by ACE_Event_Handler_T< T >::ACE_Event_Handler_T().

template<class T>
typedef ACE_HANDLE(T::* ACE_Event_Handler_T< T >::GET_HANDLE)(void) const
 

Definition at line 70 of file Event_Handler_T.h.

Referenced by ACE_Event_Handler_T< T >::ACE_Event_Handler_T().

template<class T>
typedef int(T::* ACE_Event_Handler_T< T >::IO_HANDLER)(ACE_HANDLE)
 

Handle I/O events.

Definition at line 74 of file Event_Handler_T.h.

Referenced by ACE_Event_Handler_T< T >::ACE_Event_Handler_T().

template<class T>
typedef void(T::* ACE_Event_Handler_T< T >::SET_HANDLE)(ACE_HANDLE)
 

Definition at line 71 of file Event_Handler_T.h.

Referenced by ACE_Event_Handler_T< T >::ACE_Event_Handler_T().

template<class T>
typedef int(T::* ACE_Event_Handler_T< T >::SIG_HANDLER)(int, siginfo_t*, ucontext_t*)
 

= Initialization and termination methods.

Definition at line 83 of file Event_Handler_T.h.

Referenced by ACE_Event_Handler_T< T >::ACE_Event_Handler_T().

template<class T>
typedef int(T::* ACE_Event_Handler_T< T >::TO_HANDLER)(const ACE_Time_Value &, const void *)
 

Handle timeout events.

Definition at line 77 of file Event_Handler_T.h.

Referenced by ACE_Event_Handler_T< T >::ACE_Event_Handler_T().


Constructor & Destructor Documentation

template<class T>
ACE_Event_Handler_T< T >::ACE_Event_Handler_T T *  op_handler,
int  delete_handler,
GET_HANDLE  get_handle = 0,
IO_HANDLER  input = 0,
CL_HANDLER  close = 0,
SIG_HANDLER  sig = 0,
TO_HANDLER  timeout = 0,
IO_HANDLER  output = 0,
SET_HANDLE  set_handle = 0,
IO_HANDLER  except = 0
 

Initialize the op_handler.

Definition at line 41 of file Event_Handler_T.cpp.

References ACE_TRACE, ACE_Event_Handler_T< T >::CL_HANDLER, ACE_Event_Handler_T< T >::GET_HANDLE, ACE_Event_Handler_T< T >::IO_HANDLER, ACE_Event_Handler_T< T >::SET_HANDLE, ACE_Event_Handler_T< T >::SIG_HANDLER, and ACE_Event_Handler_T< T >::TO_HANDLER.

00050   : op_handler_ (op_handler),
00051     input_handler_ (input_h),
00052     output_handler_ (output_h),
00053     except_handler_ (except_h),
00054     to_handler_ (timeout_h),
00055     cl_handler_ (close_h),
00056     sig_handler_ (sig_h),
00057     delete_handler_ (delete_handler),
00058     set_handle_ (set_handle),
00059     get_handle_ (get_handle)
00060 {
00061   ACE_TRACE ("ACE_Event_Handler_T<T>::ACE_Event_Handler_T");
00062 }

template<class T>
ACE_Event_Handler_T< T >::~ACE_Event_Handler_T void   ) 
 

Close down and delete the .

Definition at line 33 of file Event_Handler_T.cpp.

References ACE_TRACE, ACE_Event_Handler_T< T >::delete_handler_, and ACE_Event_Handler_T< T >::op_handler_.

00034 {
00035   ACE_TRACE ("ACE_Event_Handler_T<T>::~ACE_Event_Handler_T");
00036   if (this->delete_handler_)
00037     delete this->op_handler_;
00038 }


Member Function Documentation

template<class T>
void ACE_Event_Handler_T< T >::cl_handler CL_HANDLER   ) 
 

template<class T>
ACE_INLINE ACE_TYPENAME ACE_Event_Handler_T< T >::CL_HANDLER ACE_Event_Handler_T< T >::cl_handler void   ) 
 

Definition at line 108 of file Event_Handler_T.inl.

References ACE_TRACE, and ACE_Event_Handler_T< T >::cl_handler_.

00109 {
00110   ACE_TRACE ("ACE_Event_Handler_T<T>::cl_handler");
00111   return this->cl_handler_;
00112 }

template<class T>
ACE_BEGIN_VERSIONED_NAMESPACE_DECL void ACE_Event_Handler_T< T >::dump void   )  const
 

Dump the state of an object.

Definition at line 25 of file Event_Handler_T.cpp.

References ACE_TRACE.

00026 {
00027 #if defined (ACE_HAS_DUMP)
00028   ACE_TRACE ("ACE_Event_Handler_T<T>::dump");
00029 #endif /* ACE_HAS_DUMP */
00030 }

template<class T>
void ACE_Event_Handler_T< T >::except_handler IO_HANDLER   ) 
 

template<class T>
ACE_INLINE ACE_TYPENAME ACE_Event_Handler_T< T >::IO_HANDLER ACE_Event_Handler_T< T >::except_handler void   ) 
 

Definition at line 80 of file Event_Handler_T.inl.

References ACE_TRACE, and ACE_Event_Handler_T< T >::except_handler_.

00081 {
00082   ACE_TRACE ("ACE_Event_Handler_T<T>::except_handler");
00083   return this->except_handler_;
00084 }

template<class T>
ACE_HANDLE ACE_Event_Handler_T< T >::get_handle void   )  const [virtual]
 

Get the I/O handle.

Reimplemented from ACE_Event_Handler.

Definition at line 65 of file Event_Handler_T.cpp.

References ACE_TRACE, ACE_Event_Handler_T< T >::get_handle_, and ACE_Event_Handler_T< T >::op_handler_.

00066 {
00067   ACE_TRACE ("ACE_Event_Handler_T<T>::get_handle");
00068   return this->get_handle_ == 0 ? ACE_INVALID_HANDLE : (this->op_handler_->*get_handle_) ();
00069 }

template<class T>
int ACE_Event_Handler_T< T >::handle_close ACE_HANDLE  fd,
ACE_Reactor_Mask  close_mask
[virtual]
 

Called when a <handle_*()> method returns -1 or when the method is called on an ACE_Reactor. The indicates which event has triggered the method callback on a particular .

Reimplemented from ACE_Event_Handler.

Definition at line 108 of file Event_Handler_T.cpp.

References ACE_Reactor_Mask, ACE_TRACE, ACE_Event_Handler_T< T >::cl_handler_, and ACE_Event_Handler_T< T >::op_handler_.

00109 {
00110   ACE_TRACE ("ACE_Event_Handler_T<T>::handle_close");
00111   return this->cl_handler_ == 0 ? 0 : (this->op_handler_->*cl_handler_) (fd, close_mask);
00112 }

template<class T>
int ACE_Event_Handler_T< T >::handle_exception ACE_HANDLE  fd = ACE_INVALID_HANDLE  )  [virtual]
 

Called when an exceptional events occur (e.g., SIGURG).

Reimplemented from ACE_Event_Handler.

Definition at line 94 of file Event_Handler_T.cpp.

References ACE_TRACE, ACE_Event_Handler_T< T >::except_handler_, and ACE_Event_Handler_T< T >::op_handler_.

00095 {
00096   ACE_TRACE ("ACE_Event_Handler_T<T>::handle_exception");
00097   return this->except_handler_ == 0 ? 0 : (this->op_handler_->*except_handler_) (fd);
00098 }

template<class T>
void ACE_Event_Handler_T< T >::handle_get GET_HANDLE   ) 
 

template<class T>
ACE_INLINE ACE_TYPENAME ACE_Event_Handler_T< T >::GET_HANDLE ACE_Event_Handler_T< T >::handle_get void   ) 
 

Definition at line 24 of file Event_Handler_T.inl.

References ACE_TRACE, and ACE_Event_Handler_T< T >::get_handle_.

00025 {
00026   ACE_TRACE ("ACE_Event_Handler_T<T>::handle_get");
00027   return this->get_handle_;
00028 }

template<class T>
int ACE_Event_Handler_T< T >::handle_input ACE_HANDLE  fd = ACE_INVALID_HANDLE  )  [virtual]
 

Called when input events occur (e.g., connection or data).

Reimplemented from ACE_Event_Handler.

Definition at line 80 of file Event_Handler_T.cpp.

References ACE_TRACE, ACE_Event_Handler_T< T >::input_handler_, and ACE_Event_Handler_T< T >::op_handler_.

00081 {
00082   ACE_TRACE ("ACE_Event_Handler_T<T>::handle_input");
00083   return this->input_handler_ == 0 ? 0 : (this->op_handler_->*input_handler_) (fd);
00084 }

template<class T>
int ACE_Event_Handler_T< T >::handle_output ACE_HANDLE  fd = ACE_INVALID_HANDLE  )  [virtual]
 

Called when output events are possible (e.g., when flow control abates or non-blocking connection completes).

Reimplemented from ACE_Event_Handler.

Definition at line 87 of file Event_Handler_T.cpp.

References ACE_TRACE, ACE_Event_Handler_T< T >::op_handler_, and ACE_Event_Handler_T< T >::output_handler_.

00088 {
00089   ACE_TRACE ("ACE_Event_Handler_T<T>::handle_output");
00090   return this->output_handler_ == 0 ? 0 : (this->op_handler_->*output_handler_) (fd);
00091 }

template<class T>
void ACE_Event_Handler_T< T >::handle_set SET_HANDLE   ) 
 

template<class T>
ACE_INLINE ACE_TYPENAME ACE_Event_Handler_T< T >::SET_HANDLE ACE_Event_Handler_T< T >::handle_set void   ) 
 

Definition at line 38 of file Event_Handler_T.inl.

References ACE_TRACE, and ACE_Event_Handler_T< T >::set_handle_.

00039 {
00040   ACE_TRACE ("ACE_Event_Handler_T<T>::handle_set");
00041   return this->set_handle_;
00042 }

template<class T>
int ACE_Event_Handler_T< T >::handle_signal int  signum,
siginfo_t = 0,
ucontext_t = 0
[virtual]
 

Called when object is signaled by OS (either via UNIX signals or when a Win32 object becomes signaled).

Reimplemented from ACE_Event_Handler.

Definition at line 115 of file Event_Handler_T.cpp.

References ACE_TRACE, ACE_Event_Handler_T< T >::op_handler_, ACE_Event_Handler_T< T >::sig_handler_, and ucontext_t.

00116 {
00117   ACE_TRACE ("ACE_Event_Handler_T<T>::handle_signal");
00118   return this->sig_handler_ == 0 ? 0 : (this->op_handler_->*sig_handler_) (signum, s, u);
00119 }

template<class T>
int ACE_Event_Handler_T< T >::handle_timeout const ACE_Time_Value tv,
const void *  arg = 0
[virtual]
 

Called when timer expires. represents the current time that the was selected for timeout dispatching and is the asynchronous completion token that was passed in when was invoked.

Reimplemented from ACE_Event_Handler.

Definition at line 101 of file Event_Handler_T.cpp.

References ACE_TRACE, ACE_Event_Handler_T< T >::op_handler_, and ACE_Event_Handler_T< T >::to_handler_.

00102 {
00103   ACE_TRACE ("ACE_Event_Handler_T<T>::handle_timeout");
00104   return this->to_handler_ == 0 ? 0 : (this->op_handler_->*to_handler_) (tv, arg);
00105 }

template<class T>
void ACE_Event_Handler_T< T >::input_handler IO_HANDLER   ) 
 

template<class T>
ACE_INLINE ACE_TYPENAME ACE_Event_Handler_T< T >::IO_HANDLER ACE_Event_Handler_T< T >::input_handler void   ) 
 

Definition at line 52 of file Event_Handler_T.inl.

References ACE_TRACE, and ACE_Event_Handler_T< T >::input_handler_.

00053 {
00054   ACE_TRACE ("ACE_Event_Handler_T<T>::input_handler");
00055   return this->input_handler_;
00056 }

template<class T>
ACE_BEGIN_VERSIONED_NAMESPACE_DECL ACE_INLINE void ACE_Event_Handler_T< T >::op_handler T *   ) 
 

Definition at line 10 of file Event_Handler_T.inl.

References ACE_TRACE, and ACE_Event_Handler_T< T >::op_handler_.

00011 {
00012   ACE_TRACE ("ACE_Event_Handler_T<T>::op_handler");
00013   this->op_handler_ = op;
00014 }

template<class T>
ACE_INLINE T * ACE_Event_Handler_T< T >::op_handler void   ) 
 

Definition at line 17 of file Event_Handler_T.inl.

References ACE_TRACE, and ACE_Event_Handler_T< T >::op_handler_.

00018 {
00019   ACE_TRACE ("ACE_Event_Handler_T<T>::op_handler");
00020   return this->op_handler_;
00021 }

template<class T>
void ACE_Event_Handler_T< T >::output_handler IO_HANDLER   ) 
 

template<class T>
ACE_INLINE ACE_TYPENAME ACE_Event_Handler_T< T >::IO_HANDLER ACE_Event_Handler_T< T >::output_handler void   ) 
 

Definition at line 66 of file Event_Handler_T.inl.

References ACE_TRACE, and ACE_Event_Handler_T< T >::output_handler_.

00067 {
00068   ACE_TRACE ("ACE_Event_Handler_T<T>::output_handler");
00069   return this->output_handler_;
00070 }

template<class T>
void ACE_Event_Handler_T< T >::set_handle ACE_HANDLE   )  [virtual]
 

Set the I/O handle.

Reimplemented from ACE_Event_Handler.

Definition at line 72 of file Event_Handler_T.cpp.

References ACE_TRACE, ACE_Event_Handler_T< T >::op_handler_, and ACE_Event_Handler_T< T >::set_handle_.

00073 {
00074   ACE_TRACE ("ACE_Event_Handler_T<T>::set_handle");
00075   if (this->set_handle_ != 0)
00076     (this->op_handler_->*set_handle_) (h);
00077 }

template<class T>
void ACE_Event_Handler_T< T >::sig_handler SIG_HANDLER   ) 
 

template<class T>
ACE_INLINE ACE_TYPENAME ACE_Event_Handler_T< T >::SIG_HANDLER ACE_Event_Handler_T< T >::sig_handler void   ) 
 

Definition at line 122 of file Event_Handler_T.inl.

References ACE_TRACE, and ACE_Event_Handler_T< T >::sig_handler_.

00123 {
00124   ACE_TRACE ("ACE_Event_Handler_T<T>::sig_handler");
00125   return this->sig_handler_;
00126 }

template<class T>
void ACE_Event_Handler_T< T >::to_handler TO_HANDLER   ) 
 

template<class T>
ACE_INLINE ACE_TYPENAME ACE_Event_Handler_T< T >::TO_HANDLER ACE_Event_Handler_T< T >::to_handler void   ) 
 

Definition at line 94 of file Event_Handler_T.inl.

References ACE_TRACE, and ACE_Event_Handler_T< T >::to_handler_.

00095 {
00096   ACE_TRACE ("ACE_Event_Handler_T<T>::to_handler");
00097   return this->to_handler_;
00098 }


Member Data Documentation

template<class T>
ACE_Event_Handler_T< T >::ACE_ALLOC_HOOK_DECLARE
 

Declare the dynamic allocation hooks.

Definition at line 146 of file Event_Handler_T.h.

template<class T>
CL_HANDLER ACE_Event_Handler_T< T >::cl_handler_ [protected]
 

Handle close events.

Definition at line 161 of file Event_Handler_T.h.

Referenced by ACE_Event_Handler_T< T >::cl_handler(), and ACE_Event_Handler_T< T >::handle_close().

template<class T>
int ACE_Event_Handler_T< T >::delete_handler_ [protected]
 

Keeps track of whether we need to delete the handler in the destructor.

Definition at line 168 of file Event_Handler_T.h.

Referenced by ACE_Event_Handler_T< T >::~ACE_Event_Handler_T().

template<class T>
IO_HANDLER ACE_Event_Handler_T< T >::except_handler_ [protected]
 

Definition at line 155 of file Event_Handler_T.h.

Referenced by ACE_Event_Handler_T< T >::except_handler(), and ACE_Event_Handler_T< T >::handle_exception().

template<class T>
GET_HANDLE ACE_Event_Handler_T< T >::get_handle_ [protected]
 

Definition at line 172 of file Event_Handler_T.h.

Referenced by ACE_Event_Handler_T< T >::get_handle(), and ACE_Event_Handler_T< T >::handle_get().

template<class T>
IO_HANDLER ACE_Event_Handler_T< T >::input_handler_ [protected]
 

Definition at line 153 of file Event_Handler_T.h.

Referenced by ACE_Event_Handler_T< T >::handle_input(), and ACE_Event_Handler_T< T >::input_handler().

template<class T>
T* ACE_Event_Handler_T< T >::op_handler_ [protected]
 

Pointer to the object that handles all the delegated operations.

Definition at line 150 of file Event_Handler_T.h.

Referenced by ACE_Event_Handler_T< T >::get_handle(), ACE_Event_Handler_T< T >::handle_close(), ACE_Event_Handler_T< T >::handle_exception(), ACE_Event_Handler_T< T >::handle_input(), ACE_Event_Handler_T< T >::handle_output(), ACE_Event_Handler_T< T >::handle_signal(), ACE_Event_Handler_T< T >::handle_timeout(), ACE_Event_Handler_T< T >::op_handler(), ACE_Event_Handler_T< T >::set_handle(), and ACE_Event_Handler_T< T >::~ACE_Event_Handler_T().

template<class T>
IO_HANDLER ACE_Event_Handler_T< T >::output_handler_ [protected]
 

Definition at line 154 of file Event_Handler_T.h.

Referenced by ACE_Event_Handler_T< T >::handle_output(), and ACE_Event_Handler_T< T >::output_handler().

template<class T>
SET_HANDLE ACE_Event_Handler_T< T >::set_handle_ [protected]
 

Definition at line 171 of file Event_Handler_T.h.

Referenced by ACE_Event_Handler_T< T >::handle_set(), and ACE_Event_Handler_T< T >::set_handle().

template<class T>
SIG_HANDLER ACE_Event_Handler_T< T >::sig_handler_ [protected]
 

Handle signal events.

Definition at line 164 of file Event_Handler_T.h.

Referenced by ACE_Event_Handler_T< T >::handle_signal(), and ACE_Event_Handler_T< T >::sig_handler().

template<class T>
TO_HANDLER ACE_Event_Handler_T< T >::to_handler_ [protected]
 

Handle timeout events.

Definition at line 158 of file Event_Handler_T.h.

Referenced by ACE_Event_Handler_T< T >::handle_timeout(), and ACE_Event_Handler_T< T >::to_handler().


The documentation for this class was generated from the following files:
Generated on Thu Nov 9 11:22:06 2006 for ACE by doxygen 1.3.6