diff options
author | Klaus Schmidinger <vdr@tvdr.de> | 2000-09-17 08:23:46 +0200 |
---|---|---|
committer | Klaus Schmidinger <vdr@tvdr.de> | 2000-09-17 08:23:46 +0200 |
commit | 4716cfb5a1ebae09a8a277b8943d3a885dcf1365 (patch) | |
tree | 59394b5784b6ba8cfb83bb5b526f655401bc6253 /remote.c | |
parent | 7fbf9e6c49430ca2de4683dc7319aa32d247a0f6 (diff) | |
download | vdr-4716cfb5a1ebae09a8a277b8943d3a885dcf1365.tar.gz vdr-4716cfb5a1ebae09a8a277b8943d3a885dcf1365.tar.bz2 |
Implemented centralized 'wait for input'
Diffstat (limited to 'remote.c')
-rw-r--r-- | remote.c | 36 |
1 files changed, 14 insertions, 22 deletions
@@ -6,7 +6,7 @@ * * Ported to LIRC by Carsten Koch <Carsten.Koch@icem.de> 2000-06-16. * - * $Id: remote.c 1.11 2000/07/29 16:23:47 kls Exp $ + * $Id: remote.c 1.12 2000/09/16 16:42:30 kls Exp $ */ #include "remote.h" @@ -49,6 +49,7 @@ cRcIoBase::~cRcIoBase() cRcIoKBD::cRcIoKBD(void) { + f.Open(0); // stdin } cRcIoKBD::~cRcIoKBD() @@ -70,12 +71,7 @@ void cRcIoKBD::Flush(int WaitSeconds) bool cRcIoKBD::InputAvailable(bool Wait) { - timeout(Wait ? 1000 : 10); - int ch = getch(); - if (ch == ERR) - return false; - ungetch(ch); - return true; + return f.Ready(Wait); } bool cRcIoKBD::GetCommand(unsigned int *Command, unsigned short *) @@ -98,7 +94,7 @@ cRcIoRCU::cRcIoRCU(char *DeviceName) code = 0; address = 0xFFFF; lastNumber = 0; - if ((f = open(DeviceName, O_RDWR | O_NONBLOCK)) >= 0) { + if (f.Open(DeviceName, O_RDWR | O_NONBLOCK)) { struct termios t; if (tcgetattr(f, &t) == 0) { cfsetspeed(&t, B9600); @@ -107,17 +103,14 @@ cRcIoRCU::cRcIoRCU(char *DeviceName) return; } LOG_ERROR_STR(DeviceName); - close(f); + f.Close(); } else LOG_ERROR_STR(DeviceName); - f = -1; } cRcIoRCU::~cRcIoRCU() { - if (f >= 0) - close(f); } int cRcIoRCU::ReceiveByte(bool Wait) @@ -135,7 +128,7 @@ int cRcIoRCU::ReceiveByte(bool Wait) bool cRcIoRCU::SendByteHandshake(unsigned char c) { - if (f >= 0) { + if (f.IsOpen()) { int w = write(f, &c, 1); if (w == 1) { for (int reply = ReceiveByte(); reply >= 0;) { @@ -193,7 +186,7 @@ void cRcIoRCU::Flush(int WaitSeconds) bool cRcIoRCU::InputAvailable(bool Wait) { - return DataAvailable(f, Wait); + return f.Ready(Wait); } bool cRcIoRCU::GetCommand(unsigned int *Command, unsigned short *Address) @@ -349,22 +342,21 @@ cRcIoLIRC::cRcIoLIRC(char *DeviceName) struct sockaddr_un addr; addr.sun_family = AF_UNIX; strcpy(addr.sun_path, DeviceName); - f = socket(AF_UNIX, SOCK_STREAM, 0); - if (f >= 0) { - if (connect(f, (struct sockaddr *)&addr, sizeof(addr)) >= 0) + int sock = socket(AF_UNIX, SOCK_STREAM, 0); + if (sock >= 0) { + if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) >= 0) { + f.Open(sock); return; + } LOG_ERROR_STR(DeviceName); - close(f); + close(sock); } else LOG_ERROR_STR(DeviceName); - f = -1; } cRcIoLIRC::~cRcIoLIRC() { - if (f >= 0) - close(f); } const char *cRcIoLIRC::ReceiveString(void) @@ -406,7 +398,7 @@ void cRcIoLIRC::Flush(int WaitSeconds) bool cRcIoLIRC::InputAvailable(bool Wait) { - return DataAvailable(f, Wait); + return f.Ready(Wait); } bool cRcIoLIRC::GetCommand(unsigned int *Command, unsigned short *) |