Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / ace / Event_Handler_T.h
blobc45979267625cba0e0068ddff70a607bc7b11d03
1 /* -*- C++ -*- */
3 //=============================================================================
4 /**
5 * @file Event_Handler_T.h
7 * @author Douglas C. Schmidt <d.schmidt@vanderbilt.edu>
8 */
9 //=============================================================================
11 #ifndef ACE_EVENT_HANDLER_T_H
12 #define ACE_EVENT_HANDLER_T_H
13 #include /**/ "ace/pre.h"
15 #include "ace/Event_Handler.h"
17 #if !defined (ACE_LACKS_PRAGMA_ONCE)
18 # pragma once
19 #endif /* ACE_LACKS_PRAGMA_ONCE */
21 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
23 /**
24 * @class ACE_Event_Handler_T
26 * @brief Enable a class that doesn't inherit from the
27 * ACE_Event_Handler to be incorporated into the ACE_Reactor
28 * framework. Thanks to Greg Lavender (g.lavender@isode.com)
29 * for sharing this idea.
31 * It is sometimes the case that an application has a hierarchy
32 * of operation dispatcher classes that have their own
33 * inheritance hierarchy but also would like to integrate with
34 * the ACE_Reactor. Rather than adopt a "mixin" approach, it is
35 * often cleaner to define a template as a subclass of
36 * ACE_Event_Handler and parameterize it with an operation
37 * dispatcher type.
38 * When constructing an instantiation of the ACE_Event_Handler_T
39 * object, a set of pointers to member functions must be
40 * provided so that when one of the handle_* methods is called
41 * by the ACE_Reactor, the appropriate method is called on the
42 * underlying operations object. This is done since in some
43 * cases it is useful to map any event that happens to the same
44 * method on an object.
45 * The ACE_Event_Handler_T template is instantiated by an
46 * operations object and registered with the ACE_Reactor, and it
47 * then calls the appropriate op_handler. So, it's basically
48 * just another level of indirection in event dispatching. The
49 * coupling betweent the ultimate handler of the event and the
50 * ACE_Event_Handler class is relaxed a bit by have this
51 * intermediate <op_handler_> object of type <T> around. The
52 * client object can then dynamically change the bindings for
53 * the various handlers so that during the life of one of the
54 * operation objects, it can change how it wants events to be
55 * handled. It just instantiates a new instance of the template
56 * with different bindings and reregisters this new object with
57 * the ACE_Reactor.
59 template <class T>
60 class ACE_Event_Handler_T : public ACE_Event_Handler
62 public:
63 // = Typedefs to simplify pointer-to-member-function registration.
65 // Get/set the underlying handle.
66 typedef ACE_HANDLE (T::*GET_HANDLE) () const;
67 typedef void (T::*SET_HANDLE) (ACE_HANDLE);
69 /// Handle I/O events.
70 typedef int (T::*IO_HANDLER) (ACE_HANDLE);
72 /// Handle timeout events.
73 typedef int (T::*TO_HANDLER) (const ACE_Time_Value &, const void *);
75 /// Handle close events.
76 typedef int (T::*CL_HANDLER) (ACE_HANDLE, ACE_Reactor_Mask);
78 typedef int (T::*SIG_HANDLER) (int, siginfo_t*, ucontext_t*);
80 /// Initialize the op_handler.
81 ACE_Event_Handler_T (T *op_handler,
82 int delete_handler,
83 GET_HANDLE get_handle = 0,
84 IO_HANDLER input = 0,
85 CL_HANDLER close = 0,
86 SIG_HANDLER sig = 0,
87 TO_HANDLER timeout = 0,
88 IO_HANDLER output = 0,
89 SET_HANDLE set_handle = 0,
90 IO_HANDLER except = 0);
92 /// Close down and delete the <op_handler>
93 ~ACE_Event_Handler_T ();
95 // = Override all the ACE_Event_Handler methods.
97 // These methods all delegate down to the <T> operations handler.
98 virtual ACE_HANDLE get_handle () const;
99 virtual void set_handle (ACE_HANDLE);
100 virtual int handle_input (ACE_HANDLE fd = ACE_INVALID_HANDLE);
101 virtual int handle_output (ACE_HANDLE fd = ACE_INVALID_HANDLE);
102 virtual int handle_exception (ACE_HANDLE fd = ACE_INVALID_HANDLE);
103 virtual int handle_timeout (const ACE_Time_Value &tv, const void *arg = 0);
104 virtual int handle_close (ACE_HANDLE fd, ACE_Reactor_Mask close_mask);
105 virtual int handle_signal (int signum, siginfo_t * = 0, ucontext_t * = 0);
107 // = Get/set the operations handler.
108 T *op_handler ();
109 void op_handler (T *);
111 // = Get/set the target pointer-to-method used for dispatching.
113 GET_HANDLE handle_get ();
114 void handle_get (GET_HANDLE);
116 SET_HANDLE handle_set ();
117 void handle_set (SET_HANDLE);
119 IO_HANDLER input_handler ();
120 void input_handler (IO_HANDLER);
122 IO_HANDLER output_handler ();
123 void output_handler (IO_HANDLER);
125 IO_HANDLER except_handler ();
126 void except_handler (IO_HANDLER);
128 TO_HANDLER to_handler ();
129 void to_handler (TO_HANDLER);
131 CL_HANDLER cl_handler ();
132 void cl_handler (CL_HANDLER);
134 SIG_HANDLER sig_handler ();
135 void sig_handler (SIG_HANDLER);
137 /// Dump the state of an object.
138 void dump () const;
140 /// Declare the dynamic allocation hooks.
141 ACE_ALLOC_HOOK_DECLARE;
143 protected:
144 /// Pointer to the object that handles all the delegated operations.
145 T *op_handler_;
147 // = Handle input, output, and exception events.
148 IO_HANDLER input_handler_;
149 IO_HANDLER output_handler_;
150 IO_HANDLER except_handler_;
152 /// Handle timeout events.
153 TO_HANDLER to_handler_;
155 /// Handle close events.
156 CL_HANDLER cl_handler_;
158 /// Handle signal events.
159 SIG_HANDLER sig_handler_;
161 /// Keeps track of whether we need to delete the handler in the
162 /// destructor.
163 int delete_handler_;
165 // = Get/set underlying handle.
166 SET_HANDLE set_handle_;
167 GET_HANDLE get_handle_;
170 ACE_END_VERSIONED_NAMESPACE_DECL
172 #if defined (__ACE_INLINE__)
173 #include "ace/Event_Handler_T.inl"
174 #endif /* __ACE_INLINE__ */
176 #include "ace/Event_Handler_T.cpp"
178 #include /**/ "ace/post.h"
179 #endif /* ACE_EVENT_HANDLER_H */