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

SerialStreamBuf.h

Go to the documentation of this file.
00001 /*
00002  * Time-stamp: <00/08/08 01:24:02 pagey>
00003  *
00004  * $Id: SerialStreamBuf.h,v 1.1 2000/08/08 08:33:36 pagey Exp $ 
00005  *
00006  *
00007  */
00008 #ifndef SerialStreamBuf_h
00009 #define SerialStreamBuf_h
00010 
00011 #include <termios.h>
00012 #include <unistd.h>
00013 #include <iosfwd>
00014 #include <streambuf>
00015 /* We need to figure out if we are using STLPORT implementation of the
00016    C++ Standard Template Library. If so, we need to start using the
00017    __STLPORT_STD namespace.
00018 
00019 */
00020 #ifdef __STLPORT_STD
00021 using namespace __STLPORT_STD ;
00022 #define LIBSERIAL_STD __STLPORT_STD 
00023 #else
00024 #define LIBSERIAL_STD std
00025 #endif
00026 
00027 extern "C++" {
00028   namespace LibSerial {
00045     class SerialStreamBuf : public LIBSERIAL_STD::streambuf {
00046     public:
00050 
00052 
00063       enum BaudRateEnum {
00064         BAUD_50    = B50,         
00065         BAUD_75    = B75,         
00066         BAUD_110   = B110,        
00067         BAUD_134   = B134,        
00068         BAUD_150   = B150,        
00069         BAUD_200   = B200,        
00070         BAUD_300   = B300,        
00071         BAUD_600   = B600,        
00072         BAUD_1200  = B1200,       
00073         BAUD_1800  = B1800,       
00074         BAUD_2400  = B2400,       
00075         BAUD_4800  = B4800,       
00076         BAUD_9600  = B9600,       
00077         BAUD_19200 = B19200,      
00078         BAUD_38400 = B38400,      
00079         BAUD_INVALID              
00080       } ;
00081 
00086       enum CharSizeEnum {
00087         CHAR_SIZE_5 = CS5, 
00088         CHAR_SIZE_6 = CS6, 
00089         CHAR_SIZE_7 = CS7, 
00090         CHAR_SIZE_8 = CS8, 
00091         CHAR_SIZE_INVALID  
00092       } ;
00093 
00098       enum ParityEnum {
00099         PARITY_EVEN,     
00100         PARITY_ODD,      
00101         PARITY_NONE,     
00102         PARITY_INVALID   
00103       } ;      
00104 
00109       enum FlowControlEnum {
00110         FLOW_CONTROL_HARD,   
00111         FLOW_CONTROL_SOFT,   
00112         FLOW_CONTROL_INVALID 
00113       } ;
00115 
00116       /* ----------------------------------------------------------------------
00117        * Public Static Members
00118        * ----------------------------------------------------------------------
00119        */
00127       static const BaudRateEnum DEFAULT_BAUD ;
00128 
00133       static const CharSizeEnum DEFAULT_CHAR_SIZE ;
00134 
00138       static const short DEFAULT_NO_OF_STOP_BITS ;
00139 
00143       static const ParityEnum DEFAULT_PARITY ;
00144       
00148       static const FlowControlEnum DEFAULT_FLOW_CONTROL ;
00150 
00151 
00155 
00157 
00164       SerialStreamBuf() ;
00165 
00169       ~SerialStreamBuf() ;
00171 
00180       bool is_open() const ;
00181 
00229       SerialStreamBuf* open( const string filename, 
00230                              ios_base::openmode mode = 
00231                              ios_base::in | ios_base::out ) ;
00232 
00253       SerialStreamBuf* close() ;
00254 
00259       int SetParametersToDefault() ;
00260 
00266       const BaudRateEnum SetBaudRate(const BaudRateEnum baud_rate) ;
00267 
00273       const BaudRateEnum BaudRate() const ;
00274 
00280       const CharSizeEnum SetCharSize(const CharSizeEnum char_size) ;
00281 
00286       const CharSizeEnum CharSize() const ;
00287 
00294       short SetNumOfStopBits(short stop_bits) ;
00295 
00301       short NumOfStopBits() const ; 
00302 
00308       const ParityEnum SetParity(const ParityEnum parity) ;
00309 
00315       const ParityEnum Parity() const ;
00316 
00320       const FlowControlEnum SetFlowControl(const FlowControlEnum flow_c) ;
00321 
00325       const FlowControlEnum FlowControl() const ;
00327 
00331 
00333 
00334       /* ----------------------------------------------------------------------
00335        * Friends
00336        * ----------------------------------------------------------------------
00337        */
00338     protected:
00339       /* ----------------------------------------------------------------------
00340        * Protected Data Members
00341        * ----------------------------------------------------------------------
00342        */
00343       /* ----------------------------------------------------------------------
00344        * Protected Methods
00345        * ----------------------------------------------------------------------
00346        */
00356       virtual streambuf* setbuf(char_type *, streamsize) ;
00357 
00367       virtual int sync() ;
00368 
00378       virtual int showmanyc() ;
00379 
00386       virtual streamsize xsgetn(char_type *s, streamsize n) ;
00387 
00395       virtual int_type   underflow() ;
00396 
00404       virtual int_type   uflow() ;
00405 
00412       virtual int_type pbackfail(int_type c = traits_type::eof()) ;
00413 
00420       virtual streamsize xsputn(const char_type* s, streamsize n) ;
00421 
00427       virtual int_type   overflow(int_type c) ;
00428 
00429     private:
00430       /* ----------------------------------------------------------------------
00431        * Private Data Members
00432        * ----------------------------------------------------------------------
00433        */
00439       char mPutbackChar ;
00440 
00444       bool mPutbackAvailable ;
00445       
00449       int mFileDescriptor ;
00450       /* ----------------------------------------------------------------------
00451        * Private Methods
00452        * ----------------------------------------------------------------------
00453        */
00460       int InitializeSerialPort() ;
00461     } ; // class SerialStreamBuf
00462 
00463     inline 
00464     SerialStreamBuf::SerialStreamBuf() :
00465       mPutbackChar(0),
00466       mPutbackAvailable(false),
00467       mFileDescriptor(-1) {
00468       /* empty */
00469     }
00470 
00471     inline 
00472     SerialStreamBuf::~SerialStreamBuf() {
00473       if( this->is_open() ) {
00474         this->close() ;
00475       }
00476     }
00477 
00478     inline
00479     bool
00480     SerialStreamBuf::is_open() const {
00481       return (-1 != mFileDescriptor) ;
00482     }
00483     
00484 
00485   } ; // namespace LibSerial
00486 } // extern "C++"
00487 #endif // #ifndef SerialStreamBuf_h

Generated at Tue Aug 8 01:37:55 2000 for libgpib by doxygen1.1.4 written by Dimitri van Heesch, © 1997-2000