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 boost::shared_ptr<TTY> pointer;
00049       
00061       TTY(const std::string& device=std::string());
00062 
00063       static TTY::pointer create(const std::string& device=std::string());
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 
00266       virtual Data read(size_t s = 0) throw (read_error);
00267 
00268       virtual void open() throw (open_error);
00269 
00271       virtual void open(const std::string name, int s=READ|WRITE) throw (open_error);
00272 
00274       virtual void close(bool force=false) throw (close_error);
00275 
00279       void set_input_modes(tcflag_t iflag, SetOption option=SET_NOW);
00280 
00284       void set_output_modes(tcflag_t oflag, SetOption option=SET_NOW);
00285 
00289       void set_control_modes(tcflag_t cflag, SetOption option=SET_NOW);
00290 
00294       void set_local_modes(tcflag_t lflag, SetOption option=SET_NOW);
00295 
00299       void set_control_characters(int index, cc_t value, SetOption option=SET_NOW);
00300 
00304       struct termios attributes();
00305       
00309       void inject(char data);
00310       
00314       void inject(const char* buffer, size_t bufsize);
00315 
00319       void inject(const std::string& buffer);
00320 
00322       bool reset_on_close();
00323       
00325       void set_reset_on_close(bool reset=true);
00326       
00327       sigc::signal<void> signal_input_speed();
00328       sigc::signal<void> signal_output_speed();
00329       sigc::signal<void> signal_parity();
00330       sigc::signal<void> signal_byte_size();
00331       sigc::signal<void> signal_stop_bits();
00332       sigc::signal<void> signal_flow_control();
00333       sigc::signal<void> signal_carrier_detect();
00334       sigc::signal<void> signal_receiver();
00335 
00336       virtual const std::string& object_type() { static std::string s("Conexus::TTY"); return s; }
00337 
00338       protected:
00339       struct termios m_termios, m_origtermios;
00340       bool m_reset_on_close;
00341 
00342       sigc::signal<void> m_signal_input_speed;
00343       sigc::signal<void> m_signal_output_speed;
00344       sigc::signal<void> m_signal_parity;
00345       sigc::signal<void> m_signal_byte_size;
00346       sigc::signal<void> m_signal_stop_bits;
00347       sigc::signal<void> m_signal_flow_control;
00348       sigc::signal<void> m_signal_carrier_detect;
00349       sigc::signal<void> m_signal_receiver;
00350 
00351       void tcsetattr(SetOption option);
00352 
00353       speed_t unsigned2speed(unsigned speed);
00354       unsigned speed2unsigned(speed_t speed);
00355 
00356     };
00357 
00358 }
00359 
00360 #endif

Generated on Sat Aug 26 17:34:53 2006 by  doxygen 1.4.6