/* * Copyright 2011 Steven Gribble * * This file is part of the UW CSE 333 course project sequence * (333proj). * * 333proj is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * 333proj is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with 333proj. If not, see . */ #ifndef _HW4_EVENTLOOPHANDLER_H_ #define _HW4_EVENTLOOPHANDLER_H_ namespace hw4 { // Forward declaration of this class, so that we don't need to include // EventLoop.h and have an #include loop. class EventLoop; // An EventLoopHandler is an abstract base class representing an event // handler. Customers subclass EventLoopHandler and register their // object instances with an EventLoop. When the handler is // unregistered, the event loop will call "delete" on the handler. class EventLoopHandler { public: virtual ~EventLoopHandler() { } // This "pure virtual" member function must be implemented // by subclasses. The EventLoop invokes this function on a // registered EventLoopHandler when an event fires on the registered // fd. The "eventfield" argument is a logical-or of bitmasks from // the EventLoop::eventtype enum. virtual void Handle(const int fd, const unsigned int eventfield, EventLoop *looper) = 0; // This "pure virtual" member function must also be implemented // by subclasses. It is invoked if the EventLoop is shutting // down (because somebody called 'Quit()' on it), but this // EventLoopHandler is still registered. After Quitting() returns, // the event loop will delete the handler. virtual void Quitting(const int fd) = 0; }; } // namespace hw4 #endif // _HW4_EVENTLOOPHANDLER_H_