tty.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef CONEXUSTTY_H
00020 #define CONEXUSTTY_H
00021
00022 #include <conexus/serial.h>
00023 #include <conexus/tty_interface.h>
00024
00025 #include <termios.h>
00026 #include <unistd.h>
00027
00033 namespace Conexus
00034 {
00035
00045 class TTY : public Serial, public virtual TTYInterface
00046 {
00047 protected:
00048
00060 TTY( const std::string& device = std::string(), ReadWrite rwmode = READ_WRITE );
00061
00062 public:
00063
00064 typedef ConexusPointer<TTY> pointer;
00065
00066 CONEXUS_ENDPOINT_GENERIC_CREATE();
00067
00068 static TTY::pointer create( const std::string& device = std::string(), ReadWrite rwmode = READ_WRITE );
00069
00070 virtual ~TTY();
00071
00075 virtual void drain();
00076
00080 virtual void flush_input();
00081
00085 virtual void flush_output();
00086
00091 virtual void flush();
00092
00096 virtual void suspend_output();
00097
00101 virtual void restart_output();
00102
00106 virtual void suspend_input();
00107
00111 virtual void restart_input();
00112
00150 void set_input_speed( unsigned speed, SetOption option = SET_NOW );
00151
00153 void set_output_speed( unsigned speed, SetOption option = SET_NOW );
00154
00156 void set_speed( unsigned speed, SetOption option = SET_NOW );
00157
00159 unsigned input_speed();
00160
00162 unsigned output_speed();
00163
00165 void set_parity( Parity parity, ParityError error = PARITY_ERROR_IGNORE, SetOption option = SET_NOW );
00166
00168 Parity parity();
00169
00171 ParityError parity_error();
00172
00174 unsigned byte_size();
00175
00185 void set_byte_size( unsigned size, SetOption option = SET_NOW );
00186
00188 unsigned stop_bits();
00189
00191 void set_stop_bits( unsigned size, SetOption option = SET_NOW );
00192
00194 FlowControl flow_control();
00195
00200 void set_flow_control( FlowControl flowcontrol, SetOption option = SET_NOW );
00201
00203 bool is_carrier_detect_enabled();
00204
00213 void enable_carrier_detect( bool enable = true, SetOption option = SET_NOW );
00214
00219 bool is_receiver_enabled();
00220
00225 void enable_receiver( bool enable = true, SetOption option = SET_NOW );
00226
00227 virtual void open() throw ( open_exception );
00228
00230 virtual void open( const std::string& name, ReadWrite mode = READ_WRITE_UNCHANGED ) throw ( open_exception );
00231
00233 virtual void close( bool force = false ) throw ( close_exception );
00234
00238 void set_input_modes( tcflag_t iflag, SetOption option = SET_NOW );
00239
00243 void set_output_modes( tcflag_t oflag, SetOption option = SET_NOW );
00244
00248 void set_control_modes( tcflag_t cflag, SetOption option = SET_NOW );
00249
00253 void set_local_modes( tcflag_t lflag, SetOption option = SET_NOW );
00254
00258 void set_control_characters( int index, cc_t value, SetOption option = SET_NOW );
00259
00263 struct termios attributes();
00264
00268 void inject( char data );
00269
00273 void inject( const char* buffer, size_t bufsize );
00274
00278 void inject( const std::string& buffer );
00279
00281 bool is_reset_on_close_enabled();
00282
00284 void enable_reset_on_close( bool reset = true );
00285
00286 sigc::signal<void>& signal_input_speed_changed();
00287 sigc::signal<void>& signal_output_speed_changed();
00288 sigc::signal<void>& signal_parity_changed();
00289 sigc::signal<void>& signal_byte_size_changed();
00290 sigc::signal<void>& signal_stop_bits_changed();
00291 sigc::signal<void>& signal_flow_control_changed();
00292 sigc::signal<void>& signal_carrier_detect_changed();
00293 sigc::signal<void>& signal_receiver_changed();
00294
00295 virtual size_t input_available() throw();
00296
00297 protected:
00298 struct termios m_termios, m_origtermios;
00299 bool m_reset_on_close;
00300
00301 sigc::signal<void> m_signal_input_speed_changed;
00302 sigc::signal<void> m_signal_output_speed_changed;
00303 sigc::signal<void> m_signal_parity_changed;
00304 sigc::signal<void> m_signal_byte_size_changed;
00305 sigc::signal<void> m_signal_stop_bits_changed;
00306 sigc::signal<void> m_signal_flow_control_changed;
00307 sigc::signal<void> m_signal_carrier_detect_changed;
00308 sigc::signal<void> m_signal_receiver_changed;
00309
00310 void tcsetattr( SetOption option );
00311
00312 speed_t unsigned2speed( unsigned speed );
00313 unsigned speed2unsigned( speed_t speed );
00314
00315 };
00316
00317 }
00318
00319 #endif