Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

tty.H

Go to the documentation of this file.
00001 /*
00002  * Copyright 1997, Brown University, Providence, RI.
00003  * 
00004  *                         All Rights Reserved
00005  * 
00006  * Permission to use, copy, modify, and distribute this software and its
00007  * documentation for any purpose other than its incorporation into a
00008  * commercial product is hereby granted without fee, provided that the
00009  * above copyright notice appear in all copies and that both that
00010  * copyright notice and this permission notice appear in supporting
00011  * documentation, and that the name of Brown University not be used in
00012  * advertising or publicity pertaining to distribution of the software
00013  * without specific, written prior permission.
00014  * 
00015  * BROWN UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
00016  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR ANY
00017  * PARTICULAR PURPOSE.  IN NO EVENT SHALL BROWN UNIVERSITY BE LIABLE FOR
00018  * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
00019  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
00020  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
00021  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
00022  */
00023 
00024 /* -------------------------------------------------------------------------
00025                Public TTY include file
00026    ------------------------------------------------------------------------- */
00027 
00028 #ifndef TTY_HAS_BEEN_INCLUDED
00029 #define TTY_HAS_BEEN_INCLUDED
00030 
00031 #include "std/dllimpexp.H"
00032 #include "std/config.H"
00033 #include "std/list.H"
00034 
00035 class FD_EVENT {
00036    protected :
00037     int                       _fd;
00038     friend class FD_MANAGER;
00039 
00040    public :
00041                  FD_EVENT():_fd(-1)  { }
00042         virtual ~FD_EVENT() { }
00043     virtual void sample   () = 0;
00044     virtual void except   () { cerr << "What to do with an exception?" << endl;}
00045             int  fd       () { return _fd; }
00046 };
00047 
00048 
00049 class FD_TIMEOUT {
00050    public:
00051       virtual void timeout() = 0;
00052 };
00053 class DllImpExp FD_MANAGER {
00054    protected:
00055      ARRAY<FD_TIMEOUT *>        _timeouts;
00056      static FD_MANAGER         *_mgr;
00057      static ARRAY<FD_EVENT *>  *_pending_events;
00058      static ARRAY<FD_TIMEOUT *>*_pending_timeouts;
00059      static ARRAY<FD_EVENT *>  &pending_events()   { if (!_pending_events)
00060                                                       _pending_events = 
00061                                                          new ARRAY<FD_EVENT *>;
00062                                                      return *_pending_events; }
00063      static ARRAY<FD_TIMEOUT *>&pending_timeouts() { if (!_pending_timeouts)
00064                                                       _pending_timeouts = 
00065                                                         new ARRAY<FD_TIMEOUT *>;
00066                                                      return *_pending_timeouts;}
00067      virtual void               add(FD_EVENT *fd)          = 0;
00068      virtual void               rem(FD_EVENT *fd)          = 0;
00069      virtual void               add(FD_TIMEOUT *t) { _timeouts += t; }
00070      virtual void               rem(FD_TIMEOUT *t) { _timeouts -= t; }
00071    public : 
00072                          FD_MANAGER() { }
00073      virtual            ~FD_MANAGER() { }
00074 
00075      virtual void               loop(int infinite=1)        = 0;
00076      virtual ARRAY<FD_TIMEOUT*> timeouts()                 { return _timeouts; }
00077      static  FD_MANAGER        *mgr();
00078      static  void               set_mgr(FD_MANAGER *m)     { _mgr = m; 
00079                                   int i;
00080                                   for (i=0; i<pending_events().num();i++)
00081                                      m->add(pending_events()[i]);
00082                                   pending_events().clear();
00083                                   for (i=0; i<pending_timeouts().num();i++)
00084                                      m->add(pending_timeouts()[i]);
00085                                   pending_timeouts().clear();
00086                                 }
00087      static  void rem_event(FD_EVENT *f) {
00088         if (_mgr) {
00089            _mgr->rem(f);
00090         } else {
00091            pending_events() -= f;
00092         }
00093      }
00094      static  void add_event(FD_EVENT *f) {
00095         if (_mgr) {
00096            _mgr->add(f);
00097         } else {
00098            pending_events() += f;
00099         }
00100      }
00101      static  void add_timeout(FD_TIMEOUT *to) {
00102         if (_mgr) {
00103            _mgr->add(to);
00104         } else {
00105            pending_timeouts() += to;
00106         }
00107      }
00108      static  void rem_timeout(FD_TIMEOUT *to) {
00109         if (_mgr) {
00110            _mgr->rem(to);
00111         } else {
00112            pending_timeouts() -= to;
00113         }
00114      }
00115 };
00116 
00117 
00118 class TTYfd_privates;
00119 class DllImpExp TTYfd : public FD_EVENT {
00120   protected:
00121    enum             { MAX_REC_SIZE = 128 };
00122 
00123    char                    _dev[256];
00124    char                    _synch_buf[MAX_REC_SIZE];
00125    int                     _synch_pos;
00126 
00127    TTYfd_privates         &_privates;
00128 
00129   public:
00130    enum TTYparity {
00131      TTY_ODD,
00132      TTY_EVEN,
00133      TTY_NONE
00134    };
00135                 TTYfd(const char *dev, const char *name);
00136                 TTYfd();
00137    virtual     ~TTYfd()         { deactivate(); }
00138 
00139    virtual void sample          ()   { }
00140    virtual bool activate        ();
00141    virtual bool deactivate      ();
00142 
00143    int          open            ();
00144    int          close           ();
00145    int          not_configured  (int, int);
00146    int          clear           ();
00147    int          send_break      (int  duration);
00148    void         print_flags     ();
00149    int          set_speed       (long  speed);
00150    int          set_stopbits    (int   num);
00151    int          set_charsize    (short size);
00152    int          set_parity      (TTYparity parity);
00153    int          set_min_and_time(int min_num_chars,
00154                                  int min_delay_between_chars_or_total_time);
00155    int          set_flags();
00156    int          get_flags();
00157    int          read_synchronized(char sentinel, int sentinel_bit, int which, 
00158                                                     int record_size, char *buf);
00159    int          read_synchronized(char sentinel,    int record_size, char *buf);
00160    int          read_synchronized(int sentinel_bit, int record_size, char *buf);
00161    int          read_all        (char *buf, int maxbytes);
00162    int          nread           (char *buf, int readnum, int timeout_millisecs);
00163    int          drain           ();
00164    int          write           (const char *buf, int writenum,
00165                                  int timeout_millisecs);
00166    int          setup           ();
00167 };
00168 
00169 #endif /* TTY_HAS_BEEN_INCLUDED */

Generated on Mon Sep 15 16:25:57 2003 for gluebase by doxygen1.2.18