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

tty.H

Go to the documentation of this file.
00001 
00002 /* -------------------------------------------------------------------------
00003              Public TTY include file
00004    ------------------------------------------------------------------------- */
00005 
00006 #ifndef TTY_HAS_BEEN_INCLUDED
00007 #define TTY_HAS_BEEN_INCLUDED
00008 
00009 #include "std/support.H"
00010 
00011 #include <fcntl.h>
00012 
00013 #include "std/platform.H" //#include <windows.h>
00014 
00015 #ifdef WIN32
00016 typedef unsigned int speed_t;
00017 #define B0 -1
00018 #define B50 -2
00019 #define B75 -3
00020 #define B110 CBR_110
00021 #define B134 -4
00022 #define B150 -5
00023 #define B200 -6
00024 #define B300 CBR_300
00025 #define B600 CBR_600
00026 #define B1200 CBR_1200
00027 #define B1800 -7
00028 #define B2400 CBR_2400
00029 #define B4800 CBR_4800
00030 #define B9600 CBR_9600
00031 #define B19200 CBR_19200
00032 #define B38400 CBR_38400
00033 #define CS5 5
00034 #define CS6 6
00035 #define CS7 7
00036 #define CS8 8
00037 #endif
00038 
00039 class FD_EVENT {
00040    protected :
00041     int    _fd;
00042    public :
00043                  FD_EVENT():_fd(-1)  { }
00044         virtual ~FD_EVENT() { }
00045     virtual void sample   () = 0;
00046     virtual void reset    ()  {}
00047     virtual void except   () { cerr << "What to do with an exception?" << endl;}
00048             int  fd       () { return _fd; }
00049 };
00050 
00051 
00052 class FD_TIMEOUT {
00053    public:
00054    virtual ~FD_TIMEOUT() {}
00055    virtual void timeout() = 0;
00056 };
00057 
00058 class FD_MANAGER {
00059    protected:
00060      ARRAY<FD_TIMEOUT *> _timeouts;
00061      static FD_MANAGER  *_mgr;
00062    public : 
00063                          FD_MANAGER() {}
00064      virtual            ~FD_MANAGER() {}
00065 
00066      virtual void add (FD_EVENT *fd)          = 0;
00067      virtual void rem (FD_EVENT *fd)          = 0;
00068      virtual void loop(int infinite=1)        = 0;
00069      virtual void add_timeout(FD_TIMEOUT *t) { _timeouts.add_uniquely(t); }
00070      virtual void rem_timeout(FD_TIMEOUT *t) { _timeouts -= t; }
00071 
00072      virtual ARRAY<FD_TIMEOUT*> timeouts()             { return _timeouts; }
00073      static  FD_MANAGER        *mgr()                  { return _mgr; }
00074      static  void               set_mgr(FD_MANAGER *m) { _mgr = m; }
00075 };
00076 
00077 class TTYfd : public FD_EVENT {
00078   protected:
00079    enum             { MAX_REC_SIZE = 128 };
00080    char                    _dev[256];
00081    char                    _synch_buf[MAX_REC_SIZE];
00082    int                     _synch_pos;
00083 #ifndef WIN32
00084    struct termios          _ios_saved;
00085    struct termios          _ios_current;
00086 #else
00087    DCB                     _dcb_saved;
00088    DCB                     _dcb_current;
00089    COMMTIMEOUTS            _ct_saved;
00090    COMMTIMEOUTS            _ct_current;
00091 #endif
00092    static int              _timeout;
00093    FD_MANAGER             *_manager;
00094 
00095   public:
00096    enum TTYparity {
00097      TTY_ODD,
00098      TTY_EVEN,
00099      TTY_NONE
00100    };
00101                 TTYfd(FD_MANAGER *m, const char *dev, const char *name);
00102    virtual     ~TTYfd()         { deactivate(); }
00103 
00104    virtual void sample          ()   { }
00105    virtual int  activate        ();
00106    virtual int  deactivate      ();
00107 
00108    int          open            ();
00109    int          close           ();
00110    int          not_configured  (int, int);
00111    int          clear           ();
00112    int          send_break      (int  duration);
00113    void         print_flags     ();
00114    int          set_speed       (long  speed);
00115    int          set_stopbits    (int   num);
00116    int          set_charsize    (short size);
00117    int          set_parity      (TTYparity parity);
00118    int          set_min_and_time(int min_num_chars,
00119                                  int min_delay_between_chars_or_total_time);
00120    int          set_flags();
00121    int          get_flags();
00122    int          read_synchronized(char sentinel, int sentinel_bit, int which, 
00123                                                     int record_size, char *buf);
00124    int          read_synchronized(char sentinel,    int record_size, char *buf);
00125    int          read_synchronized(int sentinel_bit, int record_size, char *buf);
00126    int          read_all        (char *buf, int maxbytes);
00127    int          nread           (char *buf, int readnum, int timeout_millisecs);
00128    int          drain           ();
00129    int          write           (const char *buf, int writenum,
00130                                  int timeout_millisecs);
00131    int          setup           ();
00132 };
00133 
00134 #endif /* TTY_HAS_BEEN_INCLUDED */

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