| 467 | } |
| 468 | |
| 469 | void aptEventHandler(void *arg) |
| 470 | { |
| 471 | while (!aptEventHandlerThreadQuit) |
| 472 | { |
| 473 | s32 id = 0; |
| 474 | svcWaitSynchronizationN(&id, aptEvents, 2, 0, U64_MAX); |
| 475 | |
| 476 | if (aptEventHandlerThreadQuit) |
| 477 | break; |
| 478 | |
| 479 | // If the receive event is still signaled, sleep for a bit and retry |
| 480 | if (LightEvent_TryWait(&aptReceiveEvent)) |
| 481 | { |
| 482 | _aptDebug(222, 0); |
| 483 | svcSleepThread(10000000); // 10ms |
| 484 | svcSignalEvent(aptEvents[id]); |
| 485 | continue; |
| 486 | } |
| 487 | |
| 488 | // This is done by official sw, even though APT events are oneshot... |
| 489 | svcClearEvent(aptEvents[id]); |
| 490 | |
| 491 | // Relay receive events to our light event |
| 492 | if (id == 1) |
| 493 | { |
| 494 | NS_APPID sender; |
| 495 | APT_Command cmd; |
| 496 | Result res = APT_GlanceParameter(envGetAptAppId(), aptParameters, sizeof(aptParameters), &sender, &cmd, NULL, NULL); |
| 497 | if (R_FAILED(res)) |
| 498 | continue; // Official sw panics here - we instead swallow the (non-)event. |
| 499 | |
| 500 | _aptDebug(2, cmd); _aptDebug(22, sender); |
| 501 | |
| 502 | // NOTE: Official software handles the following parameter types here: |
| 503 | // - APTCMD_MESSAGE (cancelled afterwards) (we handle it in aptReceiveParameter instead) |
| 504 | // - APTCMD_REQUEST (cancelled afterwards) (only sent to and handled by libapplets?) |
| 505 | // - APTCMD_DSP_SLEEP (*NOT* cancelled afterwards) |
| 506 | // - APTCMD_DSP_WAKEUP (*NOT* cancelled afterwards) |
| 507 | |
| 508 | // We will handle the following: |
| 509 | switch (cmd) |
| 510 | { |
| 511 | case APTCMD_DSP_SLEEP: |
| 512 | // Handle DSP sleep requests |
| 513 | aptDspSleep(); |
| 514 | break; |
| 515 | case APTCMD_DSP_WAKEUP: |
| 516 | // Handle DSP wakeup requests |
| 517 | aptFlags &= ~FLAG_DSPWAKEUP; |
| 518 | aptDspWakeup(); |
| 519 | break; |
| 520 | case APTCMD_WAKEUP_PAUSE: |
| 521 | // Handle spurious APTCMD_WAKEUP_PAUSE parameters |
| 522 | // (see aptInit for more details on the hax 2.x spurious wakeup problem) |
| 523 | if (aptFlags & FLAG_SPURIOUS) |
| 524 | { |
| 525 | APT_CancelParameter(APPID_NONE, envGetAptAppId(), NULL); |
| 526 | aptFlags &= ~FLAG_SPURIOUS; |
nothing calls this directly
no test coverage detected