fix8  version 1.4.0
Open Source C++ FIX Framework
FIX8::tty_save_state Class Reference

#include <f8utils.hpp>

Public Member Functions

 tty_save_state (int fd)
 
tty_save_stateoperator= (const tty_save_state &from)
 
void unset_raw_mode ()
 
void set_raw_mode ()
 

Private Attributes

bool _raw_mode = false
 
int _fd
 
termio _tty_state
 

Detailed Description

Definition at line 1168 of file f8utils.hpp.

Constructor & Destructor Documentation

FIX8::tty_save_state::tty_save_state ( int  fd)
inlineexplicit

Definition at line 1181 of file f8utils.hpp.

1181 : _fd(fd) {}

Member Function Documentation

tty_save_state& FIX8::tty_save_state::operator= ( const tty_save_state from)
inline

Definition at line 1183 of file f8utils.hpp.

References _fd, _raw_mode, and _tty_state.

1184  {
1185  if (&from != this)
1186  {
1187  _raw_mode = from._raw_mode;
1188  _fd = from._fd;
1189 #ifndef _MSC_VER
1190  _tty_state = from._tty_state;
1191 #endif
1192  }
1193  return *this;
1194  }
void FIX8::tty_save_state::set_raw_mode ( )
inline

Definition at line 1213 of file f8utils.hpp.

References FIX8::Str_error().

Referenced by MyMenu::get_string(), FIX8::ConsoleMenu::GetString(), and main().

1214  {
1215  if (!_raw_mode)
1216  {
1217 #ifndef _MSC_VER
1218 #ifdef __APPLE__
1219  if (ioctl(_fd, TIOCGETA, &_tty_state) < 0)
1220 #else
1221  if (ioctl(_fd, TCGETA, &_tty_state) < 0)
1222 #endif
1223  {
1224  std::cerr << Str_error(errno, "Cannot get ioctl") << std::endl;
1225  return;
1226  }
1227 #ifdef __APPLE__
1228  termios tty_state(_tty_state);
1229 #else
1230  termio tty_state(_tty_state);
1231 #endif
1232  tty_state.c_lflag = 0;
1233  tty_state.c_cc[VTIME] = 0;
1234  tty_state.c_cc[VMIN] = 1;
1235 #ifdef __APPLE__
1236  if (ioctl(_fd, TIOCSETA, &tty_state) < 0)
1237 #else
1238  if (ioctl(_fd, TCSETA, &tty_state) < 0)
1239 #endif
1240  std::cerr << Str_error(errno, "Cannot reset ioctl") << std::endl;
1241  else
1242 #endif
1243  _raw_mode = true;
1244  }
1245  }
F8API std::string Str_error(const int err, const char *str=0)
Definition: f8utils.cpp:165
void FIX8::tty_save_state::unset_raw_mode ( )
inline

Definition at line 1196 of file f8utils.hpp.

References FIX8::Str_error().

Referenced by MyMenu::get_string(), FIX8::ConsoleMenu::GetString(), and main().

1197  {
1198  if (_raw_mode)
1199  {
1200 #ifndef _MSC_VER
1201 #ifdef __APPLE__
1202  if (ioctl(_fd, TIOCSETA, &_tty_state) < 0)
1203 #else
1204  if (ioctl(_fd, TCSETA, &_tty_state) < 0)
1205 #endif
1206  std::cerr << Str_error(errno, "Cannot reset ioctl") << std::endl;
1207  else
1208 #endif
1209  _raw_mode = false;
1210  }
1211  }
F8API std::string Str_error(const int err, const char *str=0)
Definition: f8utils.cpp:165

Member Data Documentation

int FIX8::tty_save_state::_fd
private

Definition at line 1171 of file f8utils.hpp.

Referenced by operator=().

bool FIX8::tty_save_state::_raw_mode = false
private

Definition at line 1170 of file f8utils.hpp.

Referenced by operator=().

termio FIX8::tty_save_state::_tty_state
private

Definition at line 1176 of file f8utils.hpp.

Referenced by operator=().


The documentation for this class was generated from the following file: