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
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