void CmaEvent::process() { qDebug("Starting event_thread: 0x%016" PRIxPTR, (uintptr_t)QThread::currentThreadId()); while(true) { sema.acquire(); if(!isActive()) { break; } mutex.lock(); processEvent(); mutex.unlock(); } qDebug("Finishing event_thread"); emit finishedEventLoop(); }
void CmaClient::enterEventLoop(vita_device_t *device) { vita_event_t event; qDebug("Starting event loop"); CmaEvent eventLoop (device); QThread thread; thread.setObjectName("event_thread"); eventLoop.moveToThread(&thread); connect(&thread, SIGNAL(started()), &eventLoop, SLOT(process())); connect(&eventLoop, SIGNAL(refreshDatabase()), this, SIGNAL(refreshDatabase()), Qt::DirectConnection); connect(&eventLoop, SIGNAL(finishedEventLoop()), &thread, SLOT(quit()), Qt::DirectConnection); thread.start(); while(isActive()) { if(VitaMTP_Read_Event(device, &event) < 0) { qWarning("Error reading event from Vita."); break; } // do not create a event for this since there aren't more events to read if(event.Code == PTP_EC_VITA_RequestTerminate) { qDebug("Terminating event thread"); break; // this one shuold be processed inmediately } else if(event.Code == PTP_EC_VITA_RequestCancelTask) { eventLoop.vitaEventCancelTask(&event, event.Param1); qDebug("Ended event, code: 0x%x, id: %d", event.Code, event.Param1); continue; } // the events are processed synchronously except for cancel/terminate qDebug("Sending new event"); eventLoop.setEvent(event); } eventLoop.stop(); thread.wait(); qDebug("Finishing event loop"); }