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