static void on_input_source_disconnected (ply_renderer_input_source_t *input_source) { ply_trace ("input source disconnected, reopening"); open_input_source (input_source->backend, input_source); }
main() { int fd1, fd2; /* input sources 1 and 2 */ fd_set readfs; /* file descriptor set */ int maxfd; /* maximum file desciptor used */ int loop=1; /* loop while TRUE */ int res; struct timeval Timeout; /* open_input_source opens a device, sets the port correctly, and returns a file descriptor */ fd1 = open_input_source("/dev/ttyS1"); /* COM2 */ if (fd1<0) exit(0); fd2 = open_input_source("/dev/ttyS2"); /* COM3 */ if (fd2<0) exit(0); maxfd = max (fd1, fd2)+1; /* maximum bit entry (fd) to test */ /* loop for input */ while (loop) { // set timeout value within input loop Timeout.tv_usec = 0; // milliseconds Timeout.tv_sec = 3; // seconds FD_SET(fd1, &readfs); /* set testing for source 1 */ FD_SET(fd2, &readfs); /* set testing for source 2 */ /* block until input becomes available */ res = select(maxfd, &readfs, NULL, NULL, &Timeout); //number of file descriptors with input = 0, //timeout occurred. if (res == 0) { printf("Timeout occured\n"); exit(1); } if (FD_ISSET(fd1, &readfs)) /* input from source 1 available */ handle_input_from_source(fd1); if (FD_ISSET(fd2, &readfs)) /* input from source 2 available */ handle_input_from_source(fd2); } close(fd1); close(fd2); }