MCPcopy Create free account
hub / github.com/codestation/qcma / enterEventLoop

Method enterEventLoop

common/cmaclient.cpp:221–264  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

219}
220
221void CmaClient::enterEventLoop(vita_device_t *device)
222{
223 vita_event_t obj_event;
224
225 qDebug("Starting event loop");
226
227 CmaEvent eventLoop(m_db, device);
228 QThread obj_thread;
229 obj_thread.setObjectName("event_thread");
230
231 eventLoop.moveToThread(&obj_thread);
232 connect(&obj_thread, &QThread::started, &eventLoop, &CmaEvent::process);
233 connect(&eventLoop, &CmaEvent::refreshDatabase, this, &CmaClient::refreshDatabase, Qt::DirectConnection);
234 connect(&eventLoop, &CmaEvent::finishedEventLoop, &obj_thread, &QThread::quit, Qt::DirectConnection);
235 connect(&eventLoop, &CmaEvent::messageSent, this, &CmaClient::messageSent, Qt::DirectConnection);
236 obj_thread.start();
237
238 while(isActive()) {
239 if(VitaMTP_Read_Event(device, &obj_event) < 0) {
240 qWarning("Error reading event from Vita.");
241 break;
242 }
243
244 // do not create a event for this since there aren't more events to read
245 if(obj_event.Code == PTP_EC_VITA_RequestTerminate) {
246 qDebug("Terminating event thread");
247 break;
248
249 // this one shuold be processed inmediately
250 } else if(obj_event.Code == PTP_EC_VITA_RequestCancelTask) {
251 eventLoop.vitaEventCancelTask(&obj_event, obj_event.Param1);
252 qDebug("Ended event, code: 0x%x, id: %d", obj_event.Code, obj_event.Param1);
253 continue;
254 }
255
256 // the events are processed synchronously except for cancel/terminate
257 qDebug("Sending new event");
258 eventLoop.setEvent(obj_event);
259 }
260
261 eventLoop.stop();
262 obj_thread.wait();
263 qDebug("Finishing event loop");
264}
265
266int CmaClient::stop()
267{

Callers

nothing calls this directly

Calls 4

vitaEventCancelTaskMethod · 0.80
setEventMethod · 0.80
startMethod · 0.45
stopMethod · 0.45

Tested by

no test coverage detected