| Wisp 1.2.0 C++ Unit Test Coverage |
|
|
|
|
|
Branch data Line data Source code
1 : : /*
2 : : * Copyright 2006-2009 Savarese Software Research Corporation
3 : : *
4 : : * Licensed under the Apache License, Version 2.0 (the "License");
5 : : * you may not use this file except in compliance with the License.
6 : : * You may obtain a copy of the License at
7 : : *
8 : : * http://www.savarese.com/software/ApacheLicense-2.0
9 : : *
10 : : * Unless required by applicable law or agreed to in writing, software
11 : : * distributed under the License is distributed on an "AS IS" BASIS,
12 : : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 : : * See the License for the specific language governing permissions and
14 : : * limitations under the License.
15 : : */
16 : :
17 : : /**
18 : : * @file
19 : : * This header defines the EventHandler class.
20 : : */
21 : :
22 : : #ifndef __SSRC_WISP_SERVICE_EVENT_HANDLER_H
23 : : #define __SSRC_WISP_SERVICE_EVENT_HANDLER_H
24 : :
25 : : #include <ssrc/wisp/utility/TimeValue.h>
26 : :
27 : : __BEGIN_NS_SSRC_WISP_SERVICE
28 : :
29 : : using NS_SSRC_WISP_UTILITY::TimeValue;
30 : : using NS_SSRC_WISP_UTILITY::InfiniteTimeValue;
31 : :
32 : : // Forward declaration of EventInfo.
33 : : class EventInfo;
34 : :
35 : : // Currently implemented so you need one EventHandler instance per
36 : : // descriptor. It is possible to implement this so that you can use
37 : : // the same EventHandler instance for multiple descriptors (passing
38 : : // the file descriptor to the handler via EventInfo), but it's only
39 : : // a benefit for EventHandlers that need to share state between
40 : : // descriptors or that consume a lot of memory. Right now it's
41 : : // not a win because we still have to allocate structures that store
42 : : // timeout info and point to handlers, so why not just use the handler?
43 : 3 : class EventHandler {
44 : : friend class EventLoop;
45 : : friend class EventLoopState;
46 : :
47 : : bool _handled_timeout; // scratch variable;
48 : : bool _once;
49 : : #if defined(WISP_HAVE_NONPERSISTENT_EVENTS) || defined(WISP_HAVE_KQUEUE)
50 : : int _events; // store original events of interest
51 : : #endif
52 : : TimeValue _timeout;
53 : : TimeValue _expiration;
54 : :
55 : : protected:
56 : :
57 : 0 : const TimeValue & timeout() const {
58 : 0 : return _timeout;
59 : : }
60 : :
61 : 32 : const TimeValue & expiration() const {
62 : 32 : return _expiration;
63 : : }
64 : :
65 : 8 : bool has_timeout() const {
66 : 8 : return (_timeout < InfiniteTimeValue);
67 : : }
68 : :
69 : : public:
70 : :
71 : : static const int NoDescriptor = -1;
72 : :
73 [ - + ]: 3 : virtual ~EventHandler() { }
74 : :
75 : 0 : virtual int event_descriptor() const {
76 : 0 : return NoDescriptor;
77 : : }
78 : :
79 : : #if defined(WISP_HAVE_NONPERSISTENT_EVENTS) || defined(WISP_HAVE_KQUEUE)
80 : : int events() { return _events; }
81 : : #endif
82 : :
83 : 0 : virtual void handle_read(const EventInfo & info) { }
84 : :
85 : 0 : virtual void handle_write(const EventInfo & info) { }
86 : :
87 : 0 : virtual void handle_timeout(const EventInfo & info) { }
88 : :
89 : : //virtual void handle_signal(const EventInfo & info) { }
90 : :
91 : 0 : virtual void handle_error(const EventInfo & info) { }
92 : :
93 : 0 : virtual void handle_hangup(const EventInfo & info) { }
94 : : };
95 : :
96 : : __END_NS_SSRC_WISP_SERVICE
97 : :
98 : : #endif
|
Copyright © 2010 Savarese Software Research Corporation. All rights reserved