+void ShuttleThread::run()
+{
+ kDebug() << "------- STARTING SHUTTLE: " << m_device;
+ struct media_ctrl mc;
+
+ // open device
+ media_ctrl_open2(&mc, m_device.toUtf8().data());
+
+ // on failure return
+ if (mc.fd < 0) {
+ perror("Can't open Jog Shuttle FILE DESCRIPTOR");
+ return;
+ }
+
+ // init
+ int result;
+ fd_set readset;
+ struct timeval timeout;
+
+ /* enter thread loop */
+ while (!stop_me) {
+ /* reset the read set */
+ FD_ZERO(&readset);
+ FD_SET(mc.fd, &readset);
+
+ // reinit the timeout structure
+ timeout.tv_sec = 0;
+ timeout.tv_usec = 400000; /* 400 ms */
+
+ // do select in blocked mode and wake up after timeout
+ // for stop_me evaluation
+ result = select(mc.fd + 1, &readset, NULL, NULL, &timeout);
+
+ /* see if there was an error or timeout else process event */
+ if (result < 0 && errno == EINTR) {
+ // EINTR event catched. This is not a problem - continue processing
+ kDebug() << strerror(errno) << "\n";
+ // 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);
+ }
+ } else if (result == 0) {
+ // on timeout. let it here for debug
+ }
+ }
+
+ kDebug() << "------- STOPPING SHUTTLE: ";
+ /* close the handle and return thread */
+ media_ctrl_close(&mc);
+}