nn::applet::CTR::IsExpectedToCloseApplication Function
bool IsExpectedToCloseApplication(
void
);
None.
true indicates that the application should be closed and false indicates that the application does not need to be closed. Determines whether an application should be closed.
A return value of true indicates that the shutdown process has started because there was a close request or for some other reason. In this case, close the application immediately.
A return value of false indicates that the application does not need to be closed. In this case, do nothing.
WaitForStarting. Again, also check after execution of the nn::applet::CTR::Enable function.
Do this before calling any of the other check functions in the APPLET library (nn::applet::CTR::IsExpectedToProcessHomeButton, nn::applet::CTR::IsExpectedToProcessPowerButton, and nn::applet::CTR::IsExpectedToReplySleepQuery) once control has returned from the waiting state.
Example
nnMain()
{
...
while(1)
{
_exec();
_draw();
// Checking for close after each frame
if ( applet::IsExpectedToCloseApplication() )
{
_application_finalize();
applet::PrepareToCloseApplication();
applet::CloseApplication();
// Execution does not reach this point
}
// Launch library applet after pressing the A Button
if ( _pushed_A_button() )
{
_start_library_applet();
// Wait for return from library applet
applet::WaitForStarting();
// Check for close after control returns from awaiting
if ( applet::IsExpectedToCloseApplication() )
{
_application_finalize();
applet::PrepareToCloseApplication();
applet::CloseApplication();
// Execution does not reach this point
}
}
...
If the card is removed, the system displays that fact on the screen, but the application still has not terminated at this point.
If the HOME Button is pressed on the screen indicating card removal detected, control returns to the application and an exit notification is then sent to the application. This exit notification is handled by this function in the usual manner.
However, because there may be times at which this function cannot be called due to the application status when the card was removed, the system is designed to close the application forcibly after a set period of time even if the application does not exit on its own.
In addition, when control returns to the application from the card removal screen, both the upper and lower screens go black (LCD off status). This results in a state where rendering by the GPU is impossible and execution is blocked if the nngxWaitCmdlistDone function is blocked. In other words, depending on the exact timing the card was removed and how the application is implemented, execution may be blocked by the nngxWaitCmdlistDone function before exit notification arrives, meaning control may never reach termination by this function.
It was originally assumed that determination functions, such as this one, and actual transition operation functions would be called in sequence from the same thread, but it is possible to have a mechanism where they are respectively called from separate threads. In such cases, however, sufficient care is needed such that there is nothing following the transition target operation during the working of the determination thread.
Enable function.CONFIDENTIAL