debian/libconexus-dev/usr/include/conexus-0.5/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     public:
00048       typedef ConexusPointer<TTY> pointer;
00049 
00061       TTY(const std::string& device=std::string(), long unsigned mode=SERIAL_READ|SERIAL_WRITE);
00062 
00063       static TTY::pointer create(const std::string& device=std::string(), long unsigned mode=SERIAL_READ|SERIAL_WRITE);
00064 
00065       virtual ~TTY();
00066 
00070       typedef enum SetOption {
00072         SET_NOW=TCSANOW,
00073 
00079         SET_FLUSH=TCSAFLUSH,
00080 
00085         SET_DRAIN=TCSADRAIN
00086       } SetOption;
00087 
00088       typedef enum Parity {
00089         PARITY_NONE, 
00090         PARITY_ODD,  
00091         PARITY_EVEN, 
00092       };
00093 
00094       typedef enum ParityError {
00095         PARITY_ERROR_DISCARD, 
00096         PARITY_ERROR_MARK,    
00097         PARITY_ERROR_ZERO,    
00098         PARITY_ERROR_IGNORE,  
00099       };
00100 
00101       typedef enum FlowControl {
00102         FLOW_NONE, 
00103         FLOW_HARDWARE, 
00104         FLOW_SOFTWARE, 
00105         FLOW_CUSTOM, 
00106       };
00107 
00111       void drain();
00112 
00116       void flush_input();
00117 
00121       void flush_output();
00122 
00127       void flush();
00128 
00132       void suspend_output();
00133 
00137       void restart_output();
00138 
00142       void suspend_input();
00143 
00147       void restart_input();
00148 
00186       void set_input_speed(unsigned speed, SetOption option=SET_NOW );
00187 
00189       void set_output_speed(unsigned speed, SetOption option=SET_NOW );
00190 
00192       void set_speed(unsigned speed, SetOption option=SET_NOW );
00193 
00195       unsigned input_speed();
00196 
00198       unsigned output_speed();
00199 
00201       void set_parity(Parity parity, ParityError error=PARITY_ERROR_IGNORE, SetOption option=SET_NOW );
00202 
00204       Parity parity();
00205 
00207       ParityError parity_error();
00208 
00210       unsigned byte_size();
00211 
00221       void set_byte_size( unsigned size, SetOption option=SET_NOW );
00222 
00224       unsigned stop_bits();
00225 
00227       void set_stop_bits( unsigned size, SetOption option=SET_NOW );
00228 
00230       FlowControl flow_control();
00231 
00236       void set_flow_control(FlowControl flowcontrol, SetOption option=SET_NOW);
00237 
00239       bool carrier_detect_enabled();
00240 
00249       void set_carrier_detect(bool enable=true, SetOption option=SET_NOW);
00250 
00255       bool receiver_enabled();
00256 
00261       void set_receiver_enabled(bool enable=true, SetOption option=SET_NOW);
00262 
00263       virtual void open() throw (open_exception);
00264 
00266       virtual void open(const std::string name, long unsigned mode=SERIAL_UNCHANGED) throw (open_exception);
00267 
00269       virtual void close(bool force=false) throw (close_exception);
00270 
00274       void set_input_modes(tcflag_t iflag, SetOption option=SET_NOW);
00275 
00279       void set_output_modes(tcflag_t oflag, SetOption option=SET_NOW);
00280 
00284       void set_control_modes(tcflag_t cflag, SetOption option=SET_NOW);
00285 
00289       void set_local_modes(tcflag_t lflag, SetOption option=SET_NOW);
00290 
00294       void set_control_characters(int index, cc_t value, SetOption option=SET_NOW);
00295 
00299       struct termios attributes();
00300 
00304       void inject(char data);
00305 
00309       void inject(const char* buffer, size_t bufsize);
00310 
00314       void inject(const std::string& buffer);
00315 
00317       bool reset_on_close();
00318 
00320       void set_reset_on_close(bool reset=true);
00321 
00322       sigc::signal<void> signal_input_speed();
00323       sigc::signal<void> signal_output_speed();
00324       sigc::signal<void> signal_parity();
00325       sigc::signal<void> signal_byte_size();
00326       sigc::signal<void> signal_stop_bits();
00327       sigc::signal<void> signal_flow_control();
00328       sigc::signal<void> signal_carrier_detect();
00329       sigc::signal<void> signal_receiver();
00330 
00331       virtual ssize_t input_available();
00332 
00333       virtual const std::string& object_type() { static std::string s("Conexus::TTY"); return s; }
00334 
00335       protected:
00336       struct termios m_termios, m_origtermios;
00337       bool m_reset_on_close;
00338 
00339       sigc::signal<void> m_signal_input_speed;
00340       sigc::signal<void> m_signal_output_speed;
00341       sigc::signal<void> m_signal_parity;
00342       sigc::signal<void> m_signal_byte_size;
00343       sigc::signal<void> m_signal_stop_bits;
00344       sigc::signal<void> m_signal_flow_control;
00345       sigc::signal<void> m_signal_carrier_detect;
00346       sigc::signal<void> m_signal_receiver;
00347 
00348       void tcsetattr(SetOption option);
00349 
00350       speed_t unsigned2speed(unsigned speed);
00351       unsigned speed2unsigned(speed_t speed);
00352 
00353     };
00354 
00355 }
00356 
00357 #endif

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