Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

tty_win.H

Go to the documentation of this file.
00001 #ifndef TTY_WIN_HAS_BEEN_INCLUDED
00002 #define TTY_WIN_HAS_BEEN_INCLUDED
00003 
00004 #include "dev/tty.H"
00005 
00006 
00007 class WIN_MANAGER : public FD_MANAGER {
00008   public:
00009       class tty_to_id {
00010          public :
00011           FD_EVENT    *_fd;
00012           tty_to_id() : _fd(0) { }
00013           tty_to_id(FD_EVENT *fd) : _fd(fd) { }
00014      int ready() {
00015              COMSTAT stat;
00016              DWORD eflags;
00017              if (ClearCommError((HANDLE)(_fd->fd()), &eflags, &stat)) {
00018                 return (stat.cbInQue > 0);
00019              } else if (_fd->fd() == fileno(stdin)) {
00020                 return 0;
00021 //                return num_bytes_to_read(fileno(stdin)) > 0;
00022              } else {
00023                 fd_set fd;
00024                 struct timeval tm;
00025 
00026                 FD_ZERO(&fd);
00027                 FD_SET(_fd->fd(), &fd);
00028                 tm.tv_usec = 0;
00029                 tm.tv_sec = 0;
00030                 if (select(_fd->fd()+1, &fd, NULL, NULL, &tm) != SOCKET_ERROR)
00031                    return FD_ISSET(_fd->fd(), &fd);
00032              }
00033              return 0;
00034      }
00035           int operator == (const tty_to_id &i)   { return _fd == i._fd; }
00036       };
00037 
00038   protected :
00039    ARRAY<tty_to_id> _ids;
00040 
00041   public :
00042    WIN_MANAGER() { }
00043 
00044    virtual void loop() {
00045       while (1) {
00046    for (int i=0; i<_ids.num(); i++)
00047      if (_ids[i].ready())
00048        ((FD_EVENT *)_ids[i]._fd)->sample();
00049       }
00050    }
00051 
00052    virtual void add(FD_EVENT *fd) { 
00053       _ids += tty_to_id(fd);
00054    }
00055 
00056    virtual void rem(FD_EVENT *fd) {
00057        int ind = _ids.get_index(tty_to_id(fd));
00058        if (ind != BAD_IND) {
00059           _ids -= tty_to_id(fd);
00060        }
00061    }
00062    virtual FD_TIMEOUT  *timeout()             { return FD_MANAGER::_timeout; }
00063    virtual void         timeout(FD_TIMEOUT *) {
00064       cerr << "WIN_MANAGER::timeout - Timeouts not implemented" << endl;
00065    }
00066   
00067 };
00068 
00069 #endif

Generated on Mon Sep 18 11:39:34 2006 for jot by  doxygen 1.4.4