SetSleepQueryCallback

nn::applet::CTR::SetSleepQueryCallback Function

Syntax

void SetSleepQueryCallback(
     AppletSleepQueryCallback callback,
     uptr arg = 0
);

Parameters

Name Description
in callback Callback.
in arg Callback arguments.

Return Values

None.

Description

Sets the sleep query callback.

When something happens to cause a transition to Sleep Mode during normal operation (such as the system being closed), the applet manager queries all applications and applets if it is okay to transition to Sleep Mode. The system does not transition to Sleep Mode if just one application or applet sends a "reject" reply. This equates to a cancellation of the sleep request, causing the AWAKE callback set by nn::applet::CTR::SetAwakeCallback to be called.

Specify nn::applet::CTR::REPLY_ACCEPT to accept the sleep request, nn::applet::CTR::REPLY_REJECT to reject it, and nn::applet::CTR::REPLY_LATER to defer it.

When deferring, handle any required processing, then call nn::applet::CTR::ReplySleepQuery to immediately return either nn::applet::CTR::REPLY_ACCEPT or nn::applet::CTR::REPLY_REJECT.

If no callback is set, the query is treated as if REPLY_REJECT were returned. In real-world situations you almost always need to take into account considerations such as the saving of data and the timing of screen rendering, so it is fair to assume that a sleep request will never be immediately accepted.

If the applet itself is not active, such as when another applet or menu has control or when waiting via nn::applet::CTR::WaitForStarting, always return nn::applet::CTR::REPLY_ACCEPT to sleep queries. This handling method is intended to allow the active applet to determine whether to transition to sleep mode. Of course, this method does not apply to any applications whose specifications do not allow sleep even while another applet has control.

Example

// Sleep query callback
void mySleepQueryCallback(uptr arg)
{
  NN_UNUSED_VAR(arg);

  if ( applet::IsActive() )
  {
    return applet::REPLY_LATER;
  }
  else
  {
    return applet::REPLY_ACCEPT;
  }
}

For a query callback to be called, this function must first set the callback and then the nn::applet::CTR::Enable function must be called. The callback is called regardless of whether sleep is permitted.

Revision History

2010/12/23
Explained that the callback is called regardless of whether sleep is permitted.
2010/11/10
Initial version.

CONFIDENTIAL