/* $Id: Events.h,v 1.5 1996/09/28 22:29:20 swetland Exp $
**
** Header for EventHandler and EventLoop
**
** Copyright 1996, Brian J. Swetland <swetland@uiuc.edu> and ACM@UIUC.
** Free for non-commercial use.  Share and Enjoy!
*/
#ifndef _EVENTS_H
#define _EVENTS_H

#include <sys/types.h>
#ifdef _AIX
#include <sys/select.h>
#endif

class EventHandler
{
  public:
    virtual int HandleEvent(int fd) = 0;
};

struct EventNode {
    EventNode *next;
    EventHandler *eh;
    int fd;
};

class EventLoop
{
    fd_set readset;
    int last_fd;
    
    EventNode *first; 
    int idle_timeout;
    EventHandler *idle_handler;
    
    int done;
    
  public:
    EventLoop();
    void AddHandler(EventHandler *eh, int fd);
    void RemoveHandler(EventHandler *eh);
    void SetIdleHandler(EventHandler *eh, int idletime);
    void RemoveIdleHandler(void);
    void Exit(void);
    void Run(void);
};

#endif _EVENTS_H

