Savarese Software Research Corporation
EventHandler.h
Go to the documentation of this file.
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 
21 #ifndef __SSRC_WISP_SERVICE_EVENT_HANDLER_H
22 #define __SSRC_WISP_SERVICE_EVENT_HANDLER_H
23 
25 
27 
28 using NS_SSRC_WISP_UTILITY::TimeValue;
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 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  const TimeValue & timeout() const {
57  return _timeout;
58  }
59 
60  const TimeValue & expiration() const {
61  return _expiration;
62  }
63 
64  bool has_timeout() const {
65  return (_timeout < InfiniteTimeValue);
66  }
67 
68 public:
69 
70  static const int NoDescriptor = -1;
71 
72  virtual ~EventHandler() = default;
73 
74  virtual int event_descriptor() const {
75  return NoDescriptor;
76  }
77 
78 #if defined(WISP_HAVE_NONPERSISTENT_EVENTS) || defined(WISP_HAVE_KQUEUE)
79  int events() { return _events; }
80 #endif
81 
82  virtual void handle_read(const EventInfo & info) { }
83 
84  virtual void handle_write(const EventInfo & info) { }
85 
86  virtual void handle_timeout(const EventInfo & info) { }
87 
88  //virtual void handle_signal(const EventInfo & info) { }
89 
90  virtual void handle_error(const EventInfo & info) { }
91 
92  virtual void handle_hangup(const EventInfo & info) { }
93 };
94 
96 
97 #endif

Savarese Software Research Corporation
Copyright © 2006-2012 Savarese Software Research Corporation. All rights reserved.