libassa
3.5.1
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
assa
EventHandler.h
Go to the documentation of this file.
1
// -*- c++ -*-
2
//------------------------------------------------------------------------------
3
// EventHandler.h
4
//------------------------------------------------------------------------------
5
// Copyright (C) 1997-2002,2005 Vladislav Grinchenko
6
//
7
// This library is free software; you can redistribute it and/or
8
// modify it under the terms of the GNU Library General Public
9
// License as published by the Free Software Foundation; either
10
// version 2 of the License, or (at your option) any later version.
11
//---------------------------------------------------------------------------
12
#ifndef _EventHandler_h
13
#define _EventHandler_h
14
15
#include "
assa/Assure.h
"
16
17
namespace
ASSA {
18
27
typedef
unsigned
long
TimerId
;
28
34
enum
EventType
35
{
36
READ_EVENT
= 0x01,
39
WRITE_EVENT
= 0x02,
42
EXCEPT_EVENT
= 0x04,
44
TIMEOUT_EVENT
= 0x10,
45
SIGNAL_EVENT
= 0x20,
46
RWE_EVENTS
= 0x07,
47
ALL_EVENTS
= 0x37
48
};
49
50
inline
51
bool
isReadEvent
(
EventType
e_)
52
{
53
return
(e_ &
READ_EVENT
) ==
READ_EVENT
;
54
}
55
56
inline
57
bool
isWriteEvent
(
EventType
e_)
58
{
59
return
(e_ &
WRITE_EVENT
) ==
WRITE_EVENT
;
60
}
61
62
inline
63
bool
isExceptEvent
(
EventType
e_)
64
{
65
return
(e_ &
EXCEPT_EVENT
) ==
EXCEPT_EVENT
;
66
}
67
68
inline
69
bool
isTimeoutEvent
(
EventType
e_)
70
{
71
return
(e_ &
TIMEOUT_EVENT
) ==
TIMEOUT_EVENT
;
72
}
73
74
inline
75
bool
isSignalEvent
(
EventType
e_)
76
{
77
return
(e_ &
SIGNAL_EVENT
) ==
SIGNAL_EVENT
;
78
}
79
80
inline
81
bool
isRWEEvents
(
EventType
e_)
82
{
83
return
isReadEvent
(e_) &&
isWriteEvent
(e_) &&
isExceptEvent
(e_);
84
}
85
86
inline
87
bool
isAllEvents
(
EventType
e_)
88
{
89
return
isReadEvent
(e_) &&
isWriteEvent
(e_) &&
isExceptEvent
(e_) &&
90
isSignalEvent
(e_) &&
isTimeoutEvent
(e_) ;
91
}
92
102
class
EventHandler
103
{
104
public
:
106
EventHandler
();
107
109
virtual
~EventHandler
() {
/* no-op */
}
110
115
virtual
int
handle_read
(
int
fd);
116
120
virtual
int
handle_write
(
int
fd);
121
125
virtual
int
handle_except
(
int
fd);
126
130
virtual
int
handle_timeout
(
TimerId
tid);
131
135
virtual
int
handle_signal
(
int
signum_);
136
143
virtual
int
handle_close
(
int
fd);
144
148
virtual
void
resetState
(
void
);
149
153
void
set_id
(
const
std::string& id_) {
m_id
= id_; }
154
157
std::string
get_id
()
const
{
return
m_id
; }
158
159
protected
:
160
std::string
m_id
;
161
};
162
163
inline
164
EventHandler::
165
EventHandler
() : m_id (
"EventHandler"
)
166
{
167
trace_with_mask
(
"EventHandler::EventHandler"
,
REACTTRACE
);
168
}
169
170
inline
int
171
EventHandler::
172
handle_read
(
int
/* fd */
)
173
{
174
trace_with_mask
(
"EventHandler::handle_read"
,
REACTTRACE
);
175
return
-1;
176
}
177
178
inline
int
179
EventHandler::
180
handle_write
(
int
/* fd */
)
181
{
182
trace_with_mask
(
"EventHandler::handle_write"
,
REACTTRACE
);
183
return
-1;
184
}
185
186
inline
int
187
EventHandler::
188
handle_except
(
int
/* fd */
)
189
{
190
trace_with_mask
(
"EventHandler::handle_except"
,
REACTTRACE
);
191
return
-1;
192
}
193
194
inline
int
195
EventHandler::
196
handle_timeout
(
TimerId
/* timer_id */
)
197
{
198
trace_with_mask
(
"EventHandler::handle_timeout"
,
REACTTRACE
);
199
return
-1;
200
}
201
202
inline
int
203
EventHandler::
204
handle_signal
(
int
/* signum_ */
)
205
{
206
trace_with_mask
(
"EventHandler::handle_signal"
,
REACTTRACE
);
207
return
-1;
208
}
209
210
inline
int
211
EventHandler::
212
handle_close
(
int
/* fd */
)
213
{
214
trace_with_mask
(
"EventHandler::handle_close"
,
REACTTRACE
);
215
return
-1;
216
}
217
218
inline
void
219
EventHandler::
220
resetState
(
void
)
221
{
222
trace_with_mask
(
"EventHandler::reset"
,
REACTTRACE
);
223
}
224
236
typedef
int (
EventHandler
::*
EH_IO_Callback
) (int);
237
238
}
// end namespace ASSA
239
240
#endif // _EventHandler_h
Generated on Wed Jun 13 2012 09:30:36 for libassa by
1.8.1