diff --git a/src/driver/rcinput.cpp b/src/driver/rcinput.cpp index c262a00d3..5c1e5d085 100644 --- a/src/driver/rcinput.cpp +++ b/src/driver/rcinput.cpp @@ -49,6 +49,7 @@ #endif /* KEYBOARD_INSTEAD_OF_REMOTE_CONTROL */ #include #include +#include #include #include @@ -74,6 +75,7 @@ typedef struct input_event t_input_event; static struct termio orig_termio; static bool saved_orig_termio = false; #endif /* KEYBOARD_INSTEAD_OF_REMOTE_CONTROL */ +static bool input_stopped = false; /********************************************************************************* * Constructor - opens rc-input device, selects rc-hardware and starts threads @@ -149,12 +151,18 @@ CRCInput::CRCInput() set_rc_hw(); } -void CRCInput::open() +/* if dev is given, open device with index , if not (re)open all */ +void CRCInput::open(int dev) { - close(); + if (dev == -1) + close(); for (int i = 0; i < NUMBER_OF_EVENT_DEVICES; i++) { + if (dev != -1) { + if (i != dev || fd_rc[i] != -1) + continue; + } if ((fd_rc[i] = ::open(RC_EVENT_DEVICE[i], O_RDWR)) == -1) perror(RC_EVENT_DEVICE[i]); else @@ -273,6 +281,7 @@ CRCInput::~CRCInput() **************************************************************************/ void CRCInput::stopInput() { + input_stopped = true; close(); } @@ -284,6 +293,7 @@ void CRCInput::restartInput() { close(); open(); + input_stopped = false; } int CRCInput::messageLoop( bool anyKeyCancels, int timeout ) @@ -519,6 +529,16 @@ void CRCInput::getMsg_us(neutrino_msg_t * msg, neutrino_msg_data_t * data, uint6 *data = 0; + /* reopen a missing input device + * TODO: real hot-plugging, e.g. of keyboards and triggering this loop... + * right now it is only run if some event is happening "by accident" */ + if (!input_stopped) { + for (int i = 0; i < NUMBER_OF_EVENT_DEVICES; i++) { + if (fd_rc[i] == -1) + open(i); + } + } + // wiederholung reinmachen - dass wirklich die ganze zeit bis timeout gewartet wird! gettimeofday( &tv, NULL ); getKeyBegin = (uint64_t) tv.tv_usec + (uint64_t)((uint64_t) tv.tv_sec * (uint64_t) 1000000); @@ -1160,9 +1180,14 @@ printf("[neutrino] CSectionsdClient::EVT_GOT_CN_EPG\n"); if ((fd_rc[i] != -1) && (FD_ISSET(fd_rc[i], &rfds))) { int ret; ret = read(fd_rc[i], &ev, sizeof(t_input_event)); - - if(ret != sizeof(t_input_event)) + if (ret != sizeof(t_input_event)) { + if (errno == ENODEV) { + /* hot-unplugged? */ + ::close(fd_rc[i]); + fd_rc[i] = -1; + } continue; + } if (ev.type == EV_SYN) continue; /* ignore... */ SHTDCNT::getInstance()->resetSleepTimer(); diff --git a/src/driver/rcinput.h b/src/driver/rcinput.h index d1e259295..f0c9978f0 100644 --- a/src/driver/rcinput.h +++ b/src/driver/rcinput.h @@ -151,7 +151,7 @@ class CRCInput __u16 rc_last_key; void set_dsp(); - void open(); + void open(int dev = -1); void close(); int translate(int code, int num); void calculateMaxFd(void);