EventHandler.h
Go to the documentation of this file.
00001 /* 00002 * Copyright 2006-2009 Savarese Software Research Corporation 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.savarese.com/software/ApacheLicense-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00022 #ifndef __SSRC_WISP_SERVICE_EVENT_HANDLER_H 00023 #define __SSRC_WISP_SERVICE_EVENT_HANDLER_H 00024 00025 #include <ssrc/wisp/utility/TimeValue.h> 00026 00027 __BEGIN_NS_SSRC_WISP_SERVICE 00028 00029 using NS_SSRC_WISP_UTILITY::TimeValue; 00030 using NS_SSRC_WISP_UTILITY::InfiniteTimeValue; 00031 00032 // Forward declaration of EventInfo. 00033 class EventInfo; 00034 00035 // Currently implemented so you need one EventHandler instance per 00036 // descriptor. It is possible to implement this so that you can use 00037 // the same EventHandler instance for multiple descriptors (passing 00038 // the file descriptor to the handler via EventInfo), but it's only 00039 // a benefit for EventHandlers that need to share state between 00040 // descriptors or that consume a lot of memory. Right now it's 00041 // not a win because we still have to allocate structures that store 00042 // timeout info and point to handlers, so why not just use the handler? 00043 class EventHandler { 00044 friend class EventLoop; 00045 friend class EventLoopState; 00046 00047 bool _handled_timeout; // scratch variable; 00048 bool _once; 00049 #if defined(WISP_HAVE_NONPERSISTENT_EVENTS) || defined(WISP_HAVE_KQUEUE) 00050 int _events; // store original events of interest 00051 #endif 00052 TimeValue _timeout; 00053 TimeValue _expiration; 00054 00055 protected: 00056 00057 const TimeValue & timeout() const { 00058 return _timeout; 00059 } 00060 00061 const TimeValue & expiration() const { 00062 return _expiration; 00063 } 00064 00065 bool has_timeout() const { 00066 return (_timeout < InfiniteTimeValue); 00067 } 00068 00069 public: 00070 00071 static const int NoDescriptor = -1; 00072 00073 virtual ~EventHandler() { } 00074 00075 virtual int event_descriptor() const { 00076 return NoDescriptor; 00077 } 00078 00079 #if defined(WISP_HAVE_NONPERSISTENT_EVENTS) || defined(WISP_HAVE_KQUEUE) 00080 int events() { return _events; } 00081 #endif 00082 00083 virtual void handle_read(const EventInfo & info) { } 00084 00085 virtual void handle_write(const EventInfo & info) { } 00086 00087 virtual void handle_timeout(const EventInfo & info) { } 00088 00089 //virtual void handle_signal(const EventInfo & info) { } 00090 00091 virtual void handle_error(const EventInfo & info) { } 00092 00093 virtual void handle_hangup(const EventInfo & info) { } 00094 }; 00095 00096 __END_NS_SSRC_WISP_SERVICE 00097 00098 #endif
Copyright © 2006-2010 Savarese Software Research Corporation. All rights reserved.
Copyright © 2011 Savarese Software Research Corporation. All rights reserved