diff options
author | Olli Savia <ops@iki.fi> | 2005-10-12 19:35:04 +0000 |
---|---|---|
committer | Olli Savia <ops@iki.fi> | 2005-10-12 19:35:04 +0000 |
commit | 7534e2e7ad8d22b7c6b3c0301cf553aa1e40720d (patch) | |
tree | 45c65c038e7aad9b3c5784e7edc10e8c02357006 | |
parent | 4940fa2c41f392fe311b3758e4b3ed4f709fd2fb (diff) | |
download | ATCD-7534e2e7ad8d22b7c6b3c0301cf553aa1e40720d.tar.gz |
ChangeLogTag: Wed Oct 12 22:32:33 2005 Olli Savia <ops@iki.fi>
-rw-r--r-- | ChangeLog | 21 | ||||
-rw-r--r-- | NEWS | 6 | ||||
-rw-r--r-- | ace/TTY_IO.cpp | 431 | ||||
-rw-r--r-- | ace/TTY_IO.h | 96 |
4 files changed, 286 insertions, 268 deletions
diff --git a/ChangeLog b/ChangeLog index 9823f0997d4..21aba0be16d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,11 +1,20 @@ +Wed Oct 12 22:32:33 2005 Olli Savia <ops@iki.fi> + + * ace/TTY_IO.h: + * ace/TTY_IO.cpp: + TTY_IO class overhaul. See NEWS for more information. + + * NEWS: + Added TTY_IO changes. + Wed Oct 12 12:02:46 2005 Ossama Othman <ossama@dre.vanderbilt.edu> - * tests/Based_Pointer_Test.cpp: - * tests/dll_test_parent_lib.mpb: - * tests/tests.mpc: + * tests/Based_Pointer_Test.cpp: + * tests/dll_test_parent_lib.mpb: + * tests/tests.mpc: - Fixed project dependencies for tests with an accompanying shared - library. + Fixed project dependencies for tests with an accompanying shared + library. Wed Oct 12 12:39:12 UTC 2005 Johnny Willemsen <jwillemsen@remedy.nl> @@ -96,7 +105,7 @@ Tue Oct 11 06:53:12 UTC 2005 Johnny Willemsen <jwillemsen@remedy.nl> * ACE-INSTALL.html: Updated Remedy IT support platforms and added Borland C++ Builder 2006 as new support platform. This is now - publicly announced by Borland. + publicly announced by Borland. Mon Oct 10 15:45:17 2005 William Otte <wotte@dre.vanderbilt.edu> @@ -13,6 +13,12 @@ USER VISIBLE CHANGES BETWEEN ACE-5.4.7 and ACE-5.4.8 . Improved 64bit portability +. TTY_IO overhaul + - Improved documentation. + - It is now possible to request infinite timeout in portable manner. + This can be achived by setting negative value to readtimeoutmsec. + - Various bugs fixed and portability issues resolved. + USER VISIBLE CHANGES BETWEEN ACE-5.4.6 and ACE-5.4.7 ==================================================== diff --git a/ace/TTY_IO.cpp b/ace/TTY_IO.cpp index f4a3ef8b84d..3537b268e8e 100644 --- a/ace/TTY_IO.cpp +++ b/ace/TTY_IO.cpp @@ -1,11 +1,16 @@ // $Id$ #include "ace/TTY_IO.h" -#include "ace/OS_NS_string.h" -#include "ace/OS_NS_strings.h" #include "ace/os_include/os_termios.h" -#include "ace/os_include/os_stropts.h" #include "ace/OS_NS_errno.h" +#include "ace/OS_NS_strings.h" + +static const char* const ACE_TTY_IO_ODD = ACE_LIB_TEXT("odd"); +static const char* const ACE_TTY_IO_EVEN = ACE_LIB_TEXT("even"); +#if defined (ACE_WIN32) +static const char* const ACE_TTY_IO_MARK = ACE_LIB_TEXT("mark"); +static const char* const ACE_TTY_IO_SPACE = ACE_LIB_TEXT("space"); +#endif /* ACE_WIN32 */ ACE_RCSID (ace, TTY_IO, @@ -18,45 +23,35 @@ ACE_TTY_IO::Serial_Params::Serial_Params (void) // Interface for reading/writing serial device parameters -int -ACE_TTY_IO::control (Control_Mode cmd, - Serial_Params *arg) const +int ACE_TTY_IO::control (Control_Mode cmd, Serial_Params *arg) const { #if defined (ACE_HAS_TERM_IOCTLS) -#if defined(TCGETS) + +#if defined (TCGETS) struct termios devpar; -#elif defined(TCGETA) +#elif defined (TCGETA) struct termio devpar; #else errno = ENOSYS; return -1; #endif - u_long c_iflag; - u_long c_oflag; - u_long c_cflag; - u_long c_lflag; - // u_long c_line; - u_char ivmin_cc4; - u_char ivtime_cc5; - - c_iflag=0; - c_oflag=0; - c_cflag=0; - c_lflag=0; - // c_line=0; // Get default device parameters. #if defined (TCGETS) - if (this->ACE_IO_SAP::control (TCGETS, (void *) &devpar) == -1) + if (this->ACE_IO_SAP::control (TCGETS, static_cast<void*>(&devpar)) == -1) #elif defined (TCGETA) - if (this->ACE_IO_SAP::control (TCGETA, (void *) &devpar) == -1) + if (this->ACE_IO_SAP::control (TCGETA, static_cast<void*>(&devpar)) == -1) #else - errno = ENOSYS; + errno = ENOSYS; #endif /* TCGETS */ - return -1; + return -1; - u_int newbaudrate = 0; +#if defined (ACE_USES_NEW_TERMIOS_STRUCT) + speed_t newbaudrate = 0; +#else + unsigned int newbaudrate = 0; +#endif /* ACE_USES_NEW_TERMIOS_STRUCT */ switch (cmd) { @@ -64,25 +59,25 @@ ACE_TTY_IO::control (Control_Mode cmd, switch (arg->baudrate) { #if defined (B0) - case 0: newbaudrate = B0; break; + case 0: newbaudrate = B0; break; #endif /* B0 */ #if defined (B50) - case 50: newbaudrate = B50; break; + case 50: newbaudrate = B50; break; #endif /* B50 */ #if defined (B75) - case 75: newbaudrate = B75; break; + case 75: newbaudrate = B75; break; #endif /* B75 */ #if defined (B110) - case 110: newbaudrate = B110; break; + case 110: newbaudrate = B110; break; #endif /* B110 */ #if defined (B134) - case 134: newbaudrate = B134; break; + case 134: newbaudrate = B134; break; #endif /* B134 */ #if defined (B150) - case 150: newbaudrate = B150; break; + case 150: newbaudrate = B150; break; #endif /* B150 */ #if defined (B200) - case 200: newbaudrate = B200; break; + case 200: newbaudrate = B200; break; #endif /* B200 */ #if defined (B300) case 300: newbaudrate = B300; break; @@ -94,7 +89,7 @@ ACE_TTY_IO::control (Control_Mode cmd, case 1200: newbaudrate = B1200; break; #endif /* B1200 */ #if defined (B1800) - case 1800: newbaudrate = B1800; break; + case 1800: newbaudrate = B1800; break; #endif /* B1800 */ #if defined (B2400) case 2400: newbaudrate = B2400; break; @@ -112,94 +107,98 @@ ACE_TTY_IO::control (Control_Mode cmd, case 38400: newbaudrate = B38400; break; #endif /* B38400 */ #if defined (B56000) - case 56000: newbaudrate = B56000; break; + case 56000: newbaudrate = B56000; break; #endif /* B56000 */ #if defined (B57600) case 57600: newbaudrate = B57600; break; #endif /* B57600 */ #if defined (B76800) - case 76800: newbaudrate = B76800; break; + case 76800: newbaudrate = B76800; break; #endif /* B76800 */ #if defined (B115200) case 115200: newbaudrate = B115200; break; #endif /* B115200 */ #if defined (B128000) - case 128000: newbaudrate = B128000; break; + case 128000: newbaudrate = B128000; break; #endif /* B128000 */ #if defined (B153600) - case 153600: newbaudrate = B153600; break; + case 153600: newbaudrate = B153600; break; #endif /* B153600 */ #if defined (B230400) - case 230400: newbaudrate = B230400; break; + case 230400: newbaudrate = B230400; break; #endif /* B230400 */ #if defined (B307200) - case 307200: newbaudrate = B307200; break; + case 307200: newbaudrate = B307200; break; #endif /* B307200 */ #if defined (B256000) - case 256000: newbaudrate = B256000; break; + case 256000: newbaudrate = B256000; break; #endif /* B256000 */ #if defined (B460800) - case 460800: newbaudrate = B460800; break; + case 460800: newbaudrate = B460800; break; #endif /* B460800 */ #if defined (B500000) - case 500000: newbaudrate = B500000; break; + case 500000: newbaudrate = B500000; break; #endif /* B500000 */ #if defined (B576000) - case 576000: newbaudrate = B576000; break; + case 576000: newbaudrate = B576000; break; #endif /* B576000 */ #if defined (B921600) - case 921600: newbaudrate = B921600; break; + case 921600: newbaudrate = B921600; break; #endif /* B921600 */ #if defined (B1000000) - case 1000000: newbaudrate = B1000000; break; + case 1000000: newbaudrate = B1000000; break; #endif /* B1000000 */ #if defined (B1152000) - case 1152000: newbaudrate = B1152000; break; + case 1152000: newbaudrate = B1152000; break; #endif /* B1152000 */ #if defined (B1500000) - case 1500000: newbaudrate = B1500000; break; + case 1500000: newbaudrate = B1500000; break; #endif /* B1500000 */ #if defined (B2000000) - case 2000000: newbaudrate = B2000000; break; + case 2000000: newbaudrate = B2000000; break; #endif /* B2000000 */ #if defined (B2500000) - case 2500000: newbaudrate = B2500000; break; + case 2500000: newbaudrate = B2500000; break; #endif /* B2500000 */ #if defined (B3000000) - case 3000000: newbaudrate = B3000000; break; + case 3000000: newbaudrate = B3000000; break; #endif /* B3000000 */ #if defined (B3500000) - case 3500000: newbaudrate = B3500000; break; + case 3500000: newbaudrate = B3500000; break; #endif /* B3500000 */ #if defined (B4000000) - case 4000000: newbaudrate = B4000000; break; + case 4000000: newbaudrate = B4000000; break; #endif /* B4000000 */ default: return -1; } -#if defined(ACE_USES_NEW_TERMIOS_STRUCT) - // @@ Can you really have different input and output baud - // rates?! +#if defined (ACE_USES_NEW_TERMIOS_STRUCT) + // Can you really have different input and output baud rates?! devpar.c_ispeed = newbaudrate; devpar.c_ospeed = newbaudrate; #else - c_cflag |= newbaudrate; + devpar.c_cflag &= ~CBAUD; +# if defined (CBAUDEX) + devpar.c_cflag &= ~CBAUDEX; +# endif /* CBAUDEX */ + devpar.c_cflag |= newbaudrate; #endif /* ACE_USES_NEW_TERMIOS_STRUCT */ + devpar.c_cflag &= ~CSIZE; switch (arg->databits) { - case 5: - c_cflag |= CS5; + case 5: + devpar.c_cflag |= CS5; break; - case 6: - c_cflag |= CS6; + case 6: + devpar.c_cflag |= CS6; break; - case 7: - c_cflag |= CS7; + case 7: + devpar.c_cflag |= CS7; break; - case 8: - c_cflag |= CS8; + case 8: + devpar.c_cflag |= CS8; break; default: return -1; @@ -207,96 +206,132 @@ ACE_TTY_IO::control (Control_Mode cmd, switch (arg->stopbits) { - case 1: + case 1: + devpar.c_cflag &= ~CSTOPB; break; - case 2: - c_cflag |= CSTOPB; + case 2: + devpar.c_cflag |= CSTOPB; break; default: return -1; } - if (arg->parityenb) + + if (arg->parityenb && arg->paritymode) + { + devpar.c_cflag |= PARENB; + if (ACE_OS::strcasecmp (arg->paritymode, ACE_TTY_IO_ODD) == 0) + devpar.c_cflag |= PARODD; + else if (ACE_OS::strcasecmp (arg->paritymode, ACE_TTY_IO_EVEN) == 0) + devpar.c_cflag &= ~PARODD; + else + return -1; + } + else { - c_cflag |= PARENB; - if (ACE_OS::strcasecmp (arg->paritymode, "odd") == 0) - c_cflag |= PARODD; + devpar.c_cflag &= ~PARENB; } -#if defined (CRTSCTS) - // 6/22/00 MLS add rtsenb to if statement - if ((arg->ctsenb)||(arg->rtsenb)) /* enable CTS/RTS protocoll */ - c_cflag |= CRTSCTS; -#endif /* CRTSCTS */ -#if defined (NEW_RTSCTS) - // 8/30/00 MLS add rtsenb to if statement to support new termios - if ((arg->ctsenb)||(arg->rtsenb)) /* enable CTS/RTS protocoll */ - c_cflag |= NEW_RTSCTS; -#endif /* CRTSCTS */ +#if defined (CNEW_RTSCTS) + if ((arg->ctsenb) || (arg->rtsenb)) // Enable RTS/CTS protocol + devpar.c_cflag |= CNEW_RTSCTS; + else + devpar.c_cflag &= ~CNEW_RTSCTS; +#elif defined (CRTSCTS) + if ((arg->ctsenb) || (arg->rtsenb)) // Enable RTS/CTS protocol + devpar.c_cflag |= CRTSCTS; + else + devpar.c_cflag &= ~CRTSCTS; +#endif /* NEW_RTSCTS || CRTSCTS */ + #if defined (CREAD) - if (arg->rcvenb) /* enable receiver */ - c_cflag |= CREAD; + // Enable/disable receiver + if (arg->rcvenb) + devpar.c_cflag |= CREAD; + else + devpar.c_cflag &= CREAD; #endif /* CREAD */ - #if defined (HUPCL) - // Cause DTR to be drop after port close MS 7/24/2000; - c_cflag |= HUPCL; + // Cause DTR to drop after port close. + devpar.c_cflag |= HUPCL; #endif /* HUPCL */ #if defined (CLOCAL) - // if device is not a modem set to local device MS 7/24/2000 - if(!arg->modem) - c_cflag |= CLOCAL; + // If device is not a modem set to local device. + if (arg->modem) + devpar.c_cflag &= ~CLOCAL; + else + devpar.c_cflag |= CLOCAL; #endif /* CLOCAL */ - c_oflag = 0; - c_iflag = IGNPAR | INPCK; + devpar.c_iflag = IGNPAR | INPCK; if (arg->databits < 8) - c_iflag |= ISTRIP; + devpar.c_iflag |= ISTRIP; + #if defined (IGNBRK) - // if device is not a modem set to ignore break points MS 7/24/2000 - if(!arg->modem) - c_iflag |= IGNBRK; + // If device is not a modem set to ignore break points + if(arg->modem) + devpar.c_iflag &= ~IGNBRK; + else + devpar.c_iflag |= IGNBRK; #endif /* IGNBRK */ - // 6/22/00 MLS add enable xon/xoff -#if defined (IXON) - if (arg->xinenb) /* enable XON/XOFF output*/ - c_iflag |= IXON; -#endif /* IXON */ + #if defined (IXOFF) - if (arg->xoutenb) /* enable XON/XOFF input*/ - c_iflag |= IXOFF; + // Enable/disable software flow control on input + if (arg->xinenb) + devpar.c_iflag |= IXOFF; + else + devpar.c_iflag &= IXOFF; #endif /* IXOFF */ - c_lflag = 0; - - ivmin_cc4 = (u_char) arg->readmincharacters; - ivtime_cc5= (u_char) (arg->readtimeoutmsec / 100); - devpar.c_iflag = c_iflag; - devpar.c_oflag = c_oflag; - devpar.c_cflag = c_cflag; - devpar.c_lflag = c_lflag; - devpar.c_cc[ACE_VMIN] = ivmin_cc4; - devpar.c_cc[ACE_VTIME] = ivtime_cc5; - -#if defined(TIOCMGET) - // ensure DTR is enabled + +#if defined (IXON) + // Enable/disable software flow control on output + if (arg->xoutenb) + devpar.c_iflag |= IXON; + else + devpar.c_iflag &= ~IXON; +#endif /* IXON */ + + if (arg->readtimeoutmsec < 0) + { + // Settings for infinite timeout. + devpar.c_cc[VTIME] = 0; + // In case of infinite timeout [VMIN] must be at least 1. + if (arg->readmincharacters > UCHAR_MAX) + devpar.c_cc[VMIN] = UCHAR_MAX; + else if (arg->readmincharacters < 1) + devpar.c_cc[VMIN] = 1; + else + devpar.c_cc[VMIN] = static_cast<unsigned char>(arg->readmincharacters); + } + else + { + devpar.c_cc[VTIME] = static_cast<unsigned char>(arg->readtimeoutmsec / 100); + + if (arg->readmincharacters > UCHAR_MAX) + devpar.c_cc[VMIN] = UCHAR_MAX; + else if (arg->readmincharacters < 1) + devpar.c_cc[VMIN] = 0; + else + devpar.c_cc[VMIN] = static_cast<unsigned char>(arg->readmincharacters); + } + +#if defined (TIOCMGET) int status; this->ACE_IO_SAP::control (TIOCMGET, &status); - if (arg->dtrdisable) - status &= ~TIOCM_DTR; - else - status |= TIOCM_DTR; + if (arg->dtrdisable) + status &= ~TIOCM_DTR; + else + status |= TIOCM_DTR; - this->ACE_IO_SAP::control (TIOCMSET,&status); + this->ACE_IO_SAP::control (TIOCMSET, &status); #endif /* definded (TIOCMGET) */ -#if defined(TCSETS) - return this->ACE_IO_SAP::control (TCSETS, - (void *) &devpar); -#elif defined(TCSETA) - return this->ACE_IO_SAP::control (TCSETA, - (void *) &devpar); +#if defined (TCSETS) + return this->ACE_IO_SAP::control (TCSETS, static_cast<void*>(&devpar)); +#elif defined (TCSETA) + return this->ACE_IO_SAP::control (TCSETA, static_cast<void*>(&devpar)); #else errno = ENOSYS; return -1; @@ -317,26 +352,9 @@ ACE_TTY_IO::control (Control_Mode cmd, ACE_OS::set_errno_to_last_error (); return -1; } -/*SadreevAA - switch (arg->baudrate) - { - case 300: dcb.BaudRate = CBR_300; break; - case 600: dcb.BaudRate = CBR_600; break; - case 1200: dcb.BaudRate = CBR_1200; break; - case 2400: dcb.BaudRate = CBR_2400; break; - case 4800: dcb.BaudRate = CBR_4800; break; - case 9600: dcb.BaudRate = CBR_9600; break; - case 19200: dcb.BaudRate = CBR_19200; break; - case 38400: dcb.BaudRate = CBR_38400; break; -// case 56000: dcb.BaudRate = CBR_56000; break; - case 57600: dcb.BaudRate = CBR_57600; break; - case 115200: dcb.BaudRate = CBR_115200; break; -// case 128000: dcb.BaudRate = CBR_128000; break; -// case 256000: dcb.BaudRate = CBR_256000; break; - default: return -1; - } -*/ + dcb.BaudRate = arg->baudrate; + switch (arg->databits) { case 4: @@ -344,7 +362,7 @@ ACE_TTY_IO::control (Control_Mode cmd, case 6: case 7: case 8: - dcb.ByteSize = u_char (arg->databits); + dcb.ByteSize = arg->databits; break; default: return -1; @@ -362,18 +380,16 @@ ACE_TTY_IO::control (Control_Mode cmd, return -1; } - - // 6/22/00 MLS enabled extra paths for win32 parity checking. - if (arg->parityenb) + if (arg->parityenb && arg->paritymode) { dcb.fParity = TRUE; - if (ACE_OS::strcasecmp (arg->paritymode, "odd") == 0) + if (ACE_OS::strcasecmp (arg->paritymode, ACE_TTY_IO_ODD) == 0) dcb.Parity = ODDPARITY; - else if (ACE_OS::strcasecmp (arg->paritymode, "even") == 0) + else if (ACE_OS::strcasecmp (arg->paritymode, ACE_TTY_IO_EVEN) == 0) dcb.Parity = EVENPARITY; - else if (ACE_OS::strcasecmp (arg->paritymode, "mark") == 0) + else if (ACE_OS::strcasecmp (arg->paritymode, ACE_TTY_IO_MARK) == 0) dcb.Parity = MARKPARITY; - else if (ACE_OS::strcasecmp (arg->paritymode, "space") == 0) + else if (ACE_OS::strcasecmp (arg->paritymode, ACE_TTY_IO_SPACE) == 0) dcb.Parity = SPACEPARITY; else dcb.Parity = NOPARITY; @@ -384,20 +400,8 @@ ACE_TTY_IO::control (Control_Mode cmd, dcb.Parity = NOPARITY; } - if (arg->ctsenb) // enable CTS protocol. - dcb.fOutxCtsFlow = TRUE; - else - dcb.fOutxCtsFlow = FALSE; - - // SadreevAA - if (arg->dsrenb) // enable DSR protocol. - dcb.fOutxDsrFlow = TRUE; - else - dcb.fOutxDsrFlow = FALSE; - - // 6/22/00 MLS add great flexibility for win32 - // pulled rts out of ctsenb - switch (arg->rtsenb) // enable RTS protocol. + // Enable/disable RTS protocol. + switch (arg->rtsenb) { case 1: dcb.fRtsControl = RTS_CONTROL_ENABLE; @@ -412,42 +416,53 @@ ACE_TTY_IO::control (Control_Mode cmd, dcb.fRtsControl = RTS_CONTROL_DISABLE; } - // 6/22/00 MLS add enable xon/xoff - if (arg->xinenb) // enable XON/XOFF for reception - dcb.fInX = TRUE; // Fixed by SadreevAA + // Enable/disable CTS protocol. + if (arg->ctsenb) + dcb.fOutxCtsFlow = TRUE; + else + dcb.fOutxCtsFlow = FALSE; + + // Enable/disable DSR protocol. + if (arg->dsrenb) + dcb.fOutxDsrFlow = TRUE; + else + dcb.fOutxDsrFlow = FALSE; + + // Disable/enable DTR protocol + if (arg->dtrdisable) + dcb.fDtrControl = DTR_CONTROL_DISABLE; + else + dcb.fDtrControl = DTR_CONTROL_ENABLE; + + // Enable/disable software flow control on input + if (arg->xinenb) + dcb.fInX = TRUE; else - dcb.fInX = FALSE; // Fixed by SadreevAA + dcb.fInX = FALSE; - if (arg->xoutenb) // enable XON/XOFF for transmission + // Enable/disable software flow control on output + if (arg->xoutenb) dcb.fOutX = TRUE; else dcb.fOutX = FALSE; - // always set limits unless set to -1 to use default - // 6/22/00 MLS add xon/xoff limits - if (arg->xonlim != -1) + // Always set limits unless set to negative to use default. + if (arg->xonlim >= 0) dcb.XonLim = arg->xonlim; - if (arg->xofflim != -1) - dcb.XoffLim = arg->xofflim; - - if (arg->dtrdisable) - dcb.fDtrControl = DTR_CONTROL_DISABLE; - else - dcb.fDtrControl = DTR_CONTROL_ENABLE; + if (arg->xofflim >= 0) + dcb.XoffLim = arg->xofflim; dcb.fAbortOnError = FALSE; dcb.fErrorChar = FALSE; dcb.fNull = FALSE; dcb.fBinary = TRUE; + if (!::SetCommState (this->get_handle (), &dcb)) { ACE_OS::set_errno_to_last_error (); return -1; } - // 2/13/97 BWF added drop out timer - // modified time out to operate correctly with when delay - // is requested or no delay is requestes COMMTIMEOUTS timeouts; if (!::GetCommTimeouts (this->get_handle(), &timeouts)) { @@ -455,43 +470,27 @@ ACE_TTY_IO::control (Control_Mode cmd, return -1; } - if (arg->readtimeoutmsec == 0) + if (arg->readtimeoutmsec < 0) + { + // Settings for infinite timeout. + timeouts.ReadIntervalTimeout = 0; + timeouts.ReadTotalTimeoutMultiplier = 0; + timeouts.ReadTotalTimeoutConstant = 0; + } + else if (arg->readtimeoutmsec == 0) { - // return immediately if no data in the input buffer - timeouts.ReadIntervalTimeout = MAXDWORD; + // Return immediately if no data in the input buffer. + timeouts.ReadIntervalTimeout = MAXDWORD; timeouts.ReadTotalTimeoutMultiplier = 0; timeouts.ReadTotalTimeoutConstant = 0; } else { - // Wait for specified time-out for char to arrive - // before returning. + // Wait for specified timeout for char to arrive before returning. timeouts.ReadIntervalTimeout = MAXDWORD; timeouts.ReadTotalTimeoutMultiplier = MAXDWORD; - - // ensure specified timeout is below MAXDWORD - - // We don't test arg->readtimeoutmsec against MAXDWORD - // directly to avoid a warning in the case DWORD is - // unsigned. Ensure specified timeout is below MAXDWORD use - // MAXDWORD as indicator for infinite timeout. - DWORD dw = arg->readtimeoutmsec; - if (dw < MAXDWORD) - { - // Wait for specified time-out for char to arrive before - // returning. - timeouts.ReadIntervalTimeout = MAXDWORD; - timeouts.ReadTotalTimeoutMultiplier = MAXDWORD; - timeouts.ReadTotalTimeoutConstant = dw; - } - else - { - // settings for infinite timeout - timeouts.ReadIntervalTimeout = 0; - timeouts.ReadTotalTimeoutMultiplier = 0; - timeouts.ReadTotalTimeoutConstant = 0; - } - } + timeouts.ReadTotalTimeoutConstant = arg->readtimeoutmsec; + } if (!::SetCommTimeouts (this->get_handle (), &timeouts)) { @@ -517,6 +516,6 @@ ACE_TTY_IO::control (Control_Mode cmd, #if defined (ACE_NEEDS_DEV_IO_CONVERSION) ACE_TTY_IO::operator ACE_DEV_IO &() { - return (ACE_DEV_IO &) *this; + return static_cast<ACE_DEV_IO &>(*this); } #endif /* ACE_NEEDS_DEV_IO_CONVERSION */ diff --git a/ace/TTY_IO.h b/ace/TTY_IO.h index 776a7ab04b7..8d77b35d88e 100644 --- a/ace/TTY_IO.h +++ b/ace/TTY_IO.h @@ -19,25 +19,13 @@ # pragma once #endif /* ACE_LACKS_PRAGMA_ONCE */ -#if !defined (VMIN) -#define ACE_VMIN 4 -#else -#define ACE_VMIN VMIN -#endif /* VMIN */ - -#if !defined (VTIME) -#define ACE_VTIME 5 -#else -#define ACE_VTIME VTIME -#endif /* VTIME */ - /** * @class ACE_TTY_IO * * @brief Class definitions for platform specific TTY features. * * This class represents an example interface for a specific - * device (a serial line) It extends the capability of the + * device (a serial line). It extends the capability of the * underlying DEV_IO class by adding a control method that takes * a special structure (Serial_Params) as argument to allow a * comfortable user interface (away from that annoying termios @@ -48,53 +36,69 @@ class ACE_Export ACE_TTY_IO : public ACE_DEV_IO public: enum Control_Mode { - /// Set control parameters. - SETPARAMS, - /// Get control parameters. - GETPARAMS + SETPARAMS, ///< Set control parameters. + GETPARAMS ///< Get control parameters. }; struct ACE_Export Serial_Params { Serial_Params (void); - // Common params + /// Specifies the baudrate at which the communnication port operates. int baudrate; - int parityenb; - const char *paritymode; - int databits; - int stopbits; - /// Minimum number of characters for non-canonical read + /// Specifies the minimum number of bytes in input buffer before XON char + /// is sent. Negative value indicates that default value should + /// be used (Win32). + int xonlim; + /// Specifies the maximum number of bytes in input buffer before XOFF char + /// is sent. Negative value indicates that default value should + /// be used (Win32). + int xofflim; + /// Specifies the minimum number of characters for non-canonical read. int readmincharacters; + /// Specifies the time to wait before returning from read. Negative value + /// means infinite timeout. int readtimeoutmsec; - /// CTS & RTS are the same under unix - int ctsenb; - /// enable & set rts mode (win32) + /// Enable/disable parity checking. + bool parityenb; + /// Specifies the parity mode. POSIX supports "even" and "odd" parity. + /// Additionally Win32 supports "mark" and "space" parity modes. + const char *paritymode; + /// Enable & set CTS mode. Note that RTS & CTS are enabled/disabled + /// together on some systems (RTS/CTS is enabled if either + /// <code>ctsenb</code> or <code>rtsenb</code> is set). + bool ctsenb; + /// Enable & set RTS mode. Note that RTS & CTS are enabled/disabled + /// together on some systems (RTS/CTS is enabled if either + /// <code>ctsenb</code> or <code>rtsenb</code> is set). + /// - 0 = Disable RTS. + /// - 1 = Enable RTS. + /// - 2 = Enable RTS flow-control handshaking (Win32). + /// - 3 = Specifies that RTS line will be high if bytes are available + /// for transmission. After transmission RTS will be low (Win32). int rtsenb; - /// enable xon/xoff reception - int xinenb; - /// enable xon/xoff transmission - int xoutenb; - - // Posix - unix variant - int modem; - int rcvenb; - - //Win32 - int dsrenb; // SadreevAA - - /// min bytes in input buffer before xon - int xonlim; - /// max bytes in input buffer before xoff - int xofflim; - - /// Controls whether DTR is disabled or not. + /// Enable/disable software flow control on input. + bool xinenb; + /// Enable/disable software flow control on output. + bool xoutenb; + /// Specifies if device is a modem (POSIX). If not set modem status + /// lines are ignored. + bool modem; + /// Enable/disable receiver (POSIX). + bool rcvenb; + /// Controls whether DSR is disabled or enabled (Win32). + bool dsrenb; + /// Controls whether DTR is disabled or enabled (Win32). int dtrdisable; + /// Data bits. Valid values 5, 6, 7 and 8 data bits. + /// Additionally Win32 supports 4 data bits. + unsigned char databits; + /// Stop bits. Valid values are 1 and 2. + unsigned char stopbits; }; /// Interface for reading/writing serial device parameters. - int control (Control_Mode cmd, - Serial_Params *arg) const; + int control (Control_Mode cmd, Serial_Params *arg) const; #if defined (ACE_NEEDS_DEV_IO_CONVERSION) /// This is necessary to pass ACE_TTY_IO as parameter to DEV_Connector. |