- } else if (result == 0) {
- /* do nothing. reserved for future purposes */
- } else {
- /* we have input */
- if (FD_ISSET(fd, &readset)) {
- /* get fd settings */
- if ((iof = fcntl(fd, F_GETFL, 0)) != -1) {
- /* set fd non blocking */
- fcntl(fd, F_SETFL, iof | O_NONBLOCK);
- /* read input */
- if (read(fd, &ev, sizeof(ev)) < 0) {
- if (num_warnings % 10000 == 0) {
- /* if device is not available anymore - dead or disconnected */
- fprintf(stderr, "Failed to read event from Jog Shuttle FILE DESCRIPTOR (repeated %d times)\n", num_warnings + 1);
- }
- /* exit if device is not available or the error occurs to long */
- if (errno == ENODEV) {
- perror("Failed to read from Jog Shuttle FILE DESCRIPTOR. Stop thread");
- /* stop thread */
- stop_me = true;
- } else if (num_warnings > 1000000) {
- perror("Failed to read from Jog Shuttle FILE DESCRIPTOR. Limit reached. Stop thread");
- /* stop thread */
- stop_me = true;
- }
- num_warnings++;
- }
- /* restore settings */
- if (iof != -1) {
- fcntl(fd, F_SETFL, iof);
- }
- /* process event */
- handle_event(ev);
- } else {
- fprintf(stderr, "Can't set Jog Shuttle FILE DESCRIPTOR to O_NONBLOCK and stop thread\n");
- stop_me = true;
- }
+ // continue processing
+ continue;
+ } else if (result < 0) {
+ /* stop thread */
+ stop_me = true;
+ kDebug() << strerror(errno) << "\n";
+ } else if (result > 0) {
+ // we have input
+ if (FD_ISSET(mc.fd, &readset)) {
+ struct media_ctrl_event mev;
+ mev.type = MEDIA_CTRL_EVENT_NONE;
+ // read input
+ media_ctrl_read_event(&mc, &mev);
+ // process event
+ handle_event(mev);