conexus/tty.h

00001 /***************************************************************************
00002  *   Copyright (C) 2001 by Rick L. Vinyard, Jr.                            *
00003  *   rvinyard@cs.nmsu.edu                                                  *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU Lesser General Public License as        *
00007  *   published by the Free Software Foundation version 2.1.                *
00008  *                                                                         *
00009  *   This program is distributed in the hope that it will be useful,       *
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00012  *   GNU General Public License for more details.                          *
00013  *                                                                         *
00014  *   You should have received a copy of the GNU Lesser General Public      *
00015  *   License along with this library; if not, write to the                 *
00016  *   Free Software Foundation, Inc.,                                       *
00017  *   51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA              *
00018  ***************************************************************************/
00019 #ifndef CONEXUSTTY_H
00020 #define CONEXUSTTY_H
00021 
00022 #include <conexus/serial.h>
00023 
00024 #include <termios.h>
00025 #include <unistd.h>
00026 
00034 namespace Conexus
00035 {
00036 
00045   class TTY : public Serial
00046   {
00047     protected:
00048 
00060       TTY( const std::string& device = std::string(), long unsigned mode = SERIAL_READ | SERIAL_WRITE );
00061 
00062     public:
00063 
00064       typedef ConexusPointer<TTY> pointer;
00065 
00066       static TTY::pointer create( const std::string& device = std::string(), long unsigned mode = SERIAL_READ | SERIAL_WRITE );
00067 
00068       virtual ~TTY();
00069 
00073       void drain();
00074 
00078       void flush_input();
00079 
00083       void flush_output();
00084 
00089       void flush();
00090 
00094       void suspend_output();
00095 
00099       void restart_output();
00100 
00104       void suspend_input();
00105 
00109       void restart_input();
00110 
00148       void set_input_speed( unsigned speed, SetOption option = SET_NOW );
00149 
00151       void set_output_speed( unsigned speed, SetOption option = SET_NOW );
00152 
00154       void set_speed( unsigned speed, SetOption option = SET_NOW );
00155 
00157       unsigned input_speed();
00158 
00160       unsigned output_speed();
00161 
00163       void set_parity( Parity parity, ParityError error = PARITY_ERROR_IGNORE, SetOption option = SET_NOW );
00164 
00166       Parity parity();
00167 
00169       ParityError parity_error();
00170 
00172       unsigned byte_size();
00173 
00183       void set_byte_size( unsigned size, SetOption option = SET_NOW );
00184 
00186       unsigned stop_bits();
00187 
00189       void set_stop_bits( unsigned size, SetOption option = SET_NOW );
00190 
00192       FlowControl flow_control();
00193 
00198       void set_flow_control( FlowControl flowcontrol, SetOption option = SET_NOW );
00199 
00201       bool carrier_detect_enabled();
00202 
00211       void set_carrier_detect( bool enable = true, SetOption option = SET_NOW );
00212 
00217       bool receiver_enabled();
00218 
00223       void set_receiver_enabled( bool enable = true, SetOption option = SET_NOW );
00224 
00225       virtual void open() throw ( open_exception );
00226 
00228       virtual void open( const std::string name, long unsigned mode = SERIAL_UNCHANGED ) throw ( open_exception );
00229 
00231       virtual void close( bool force = false ) throw ( close_exception );
00232 
00236       void set_input_modes( tcflag_t iflag, SetOption option = SET_NOW );
00237 
00241       void set_output_modes( tcflag_t oflag, SetOption option = SET_NOW );
00242 
00246       void set_control_modes( tcflag_t cflag, SetOption option = SET_NOW );
00247 
00251       void set_local_modes( tcflag_t lflag, SetOption option = SET_NOW );
00252 
00256       void set_control_characters( int index, cc_t value, SetOption option = SET_NOW );
00257 
00261       struct termios attributes();
00262 
00266       void inject( char data );
00267 
00271       void inject( const char* buffer, size_t bufsize );
00272 
00276       void inject( const std::string& buffer );
00277 
00279       bool reset_on_close();
00280 
00282       void set_reset_on_close( bool reset = true );
00283 
00284       sigc::signal<void> signal_input_speed();
00285       sigc::signal<void> signal_output_speed();
00286       sigc::signal<void> signal_parity();
00287       sigc::signal<void> signal_byte_size();
00288       sigc::signal<void> signal_stop_bits();
00289       sigc::signal<void> signal_flow_control();
00290       sigc::signal<void> signal_carrier_detect();
00291       sigc::signal<void> signal_receiver();
00292 
00293       virtual ssize_t input_available();
00294 
00295     protected:
00296       struct termios m_termios, m_origtermios;
00297       bool m_reset_on_close;
00298 
00299       sigc::signal<void> m_signal_input_speed;
00300       sigc::signal<void> m_signal_output_speed;
00301       sigc::signal<void> m_signal_parity;
00302       sigc::signal<void> m_signal_byte_size;
00303       sigc::signal<void> m_signal_stop_bits;
00304       sigc::signal<void> m_signal_flow_control;
00305       sigc::signal<void> m_signal_carrier_detect;
00306       sigc::signal<void> m_signal_receiver;
00307 
00308       void tcsetattr( SetOption option );
00309 
00310       speed_t unsigned2speed( unsigned speed );
00311       unsigned speed2unsigned( speed_t speed );
00312 
00313   };
00314 
00315 }
00316 
00317 #endif

Generated on Tue Mar 13 19:54:48 2007 by  doxygen 1.5.1