nn::applet::CTR::IsExpectedToCloseApplication Function

Syntax

bool IsExpectedToCloseApplication(
     void
);

Parameters

None.

Return Values

true indicates that the application should be closed and false indicates that the application does not need to be closed.

Description

Determines whether to close an application.

A return value of true indicates that the shutdown process has started because there was a close request or for another 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.

Call this function periodically (usually every frame). You must also check immediately after returning from a function that is waiting on the WaitForStarting function.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) after 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 doesn't reach this point.
     }

     // Launch library applet after A Button press
     if ( _pushed_A_button() )
     {
        _start_library_applet();

        // Wait for return from library applet
        applet::WaitForStarting();

        // Check for close after control returns
        if ( applet::IsExpectedToCloseApplication() )
        {
          _application_finalize();
          applet::PrepareToCloseApplication();
          applet::CloseApplication();
          // Execution doesn't 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 sent to the application. The exit notification is handled by this function in the usual manner.

However, because there may be times at which this function cannot be called because of 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.

We have assumed that determination functions such as this one and the function for actually making the transition will be called successively in the same thread, but it is possible depending on the implementation to call them in different threads. However, be very careful that the determination thread does not continue executing after execution control is passed.

Revision History

2012/11/09
Added a note about calling the determination function and transition functions in different threads.
2011/07/06
Added information about functionality when a card is removed.
2010/12/31
Noted that this must also be called after the Enable function.
2010/12/10
Removed a clause about closing an application because the POWER Button was used.
2010/11/30
Initial version.

CONFIDENTIAL