1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2<html xml:lang="en-US" lang="en-US" xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 5 <meta http-equiv="Content-Style-Type" content="text/css" /> 6 <link rel="stylesheet" href="../../../css/manpage.css" type="text/css" /> 7 <title>SetSleepCanceledCallback</title> 8 </head> 9 <body> 10 <h1><CODE>nn::applet::CTR::SetSleepCanceledCallback</CODE> Function</h1> 11 <h2>Syntax</h2> 12 <div class="section"> 13 <pre class="definition"> 14void SetSleepCanceledCallback( 15 <a href="../../../nn/applet/CTR/AppletSleepCanceledCallback.html">AppletSleepCanceledCallback</a> callback, 16 uptr arg = 0 17); 18</pre> 19 </div> 20 <h2>Arguments</h2> 21 <div class="section"> 22 <table class="arguments"> 23 <thead> 24 <tr> 25 <td width="15" /> 26 <th>Name</th> 27 <td>Description</td> 28 </tr> 29 </thead> 30 <tr> 31 <td>in</td> 32 <th>callback</th> 33 <td>Callback.</td> 34 </tr> 35 <tr> 36 <td>in</td> 37 <th>arg</th> 38 <td>Callback arguments.</td> 39 </tr> </table> 40 </div> 41 <h2>Return Values</h2> 42 <div class="section"> 43 None. 44 </div> 45 <h2>Description</h2> 46 <div class="section"> 47 <p>Sets the sleep cancel callback.</p><!-- write here --><P> 48This callback is called when the system is opened while the current applet manager is sending a sleep query to the applet or application. 49</P><P> 50The function is called when deferring a reply to a sleep query. If cancelling the transition to sleep mode, use <a href="../../../nn/applet/CTR/ReplySleepQuery.html"><CODE>nn::applet::CTR::ReplySleepQuery</CODE></a> to return <CODE>nn::applet::CTR::REPLY_REJECT</CODE>. 51</P><P> 52Given the name of the callback function, it appears as if it always cancels the transition to sleep mode when called, but the applet manager will simply continue to wait for a reply to the sleep query if the callback does nothing. 53</P><P> 54This callback is intended for uses such as quickly detecting that the system has been opened and cancelling the transition to sleep mode when it might otherwise take a while to fully transition, with the screens remaining dark for several seconds if the user opens the system in the middle of the transition. 55</P><PRE> 56Example 57bool isShellOpened; 58nn::os::LightEvent awakeEvent; 59// Sleep cancel callback 60void mySleepCanceledCallback(uptr arg) 61{ 62 NN_UNUSED_VAR(arg); 63 if ( applet::IsActive() ) 64 { 65 isShellOpened = true; // System opened 66 applet::ReplySleepQuery( applet::REPLY_REJECT ); 67 } 68} 69// Sleep query callback 70void mySleepQueryCallback(uptr arg) 71{ 72 NN_UNUSED_VAR(arg); 73 if ( applet::IsActive() ) 74 { 75 isShellOpened = false; 76 awakeEvent.ClearSignal(); 77 return applet::REPLY_LATER; 78 } 79 else 80 { 81 return applet::REPLY_ACCEPT; 82 } 83} 84// Wakeup callback 85void myAwakeCallback(uptr arg) 86{ 87 NN_UNUSED_VAR(arg); 88 awakeEvent.Signal(); // Wake up 89} 90// Main 91void nnMain() 92{ 93 awakeEvent.Initialize(false); 94 applet::SetSleepQueryCallback( mySleepQueryCallback, 0 ); 95 applet::SetSleepCanceledCallback( mySleepCanceledCallback, 0 ); 96 applet::SetAwakeCallback( myAwakeCallback, 0 ); 97 applet::Enable(); 98 while(1) 99 { 100 _exec(); 101 _draw(); 102 if ( applet::IsExpectedToReplySleepQuery() ) 103 { 104 for(int i=0; i<N; n++) // Heavy processing before going to sleep. For instance, when saving <CODE>N</CODE> items of data. 105 { 106 _save( data[i] ); 107 if ( isShellOpened ) // Interrupt since system is opened in the middle of all this 108 { 109 break; 110 } 111 } 112 // If system not opened, accept sleep query and wait to wake up 113 if ( ! isShellOpened ) 114 { 115 applet::ReplySleepQuery( applet::REPLY_ACCEPT ); 116 awakeEvent.Wait(); 117 } 118 } 119 } 120} 121</PRE></div> 122 <h2>Revision History</h2> 123 <div class="section"> 124 <dl class="history"> 125 <dt>2010/11/29</dt> 126 <dd>Initial version.<br /> 127 </dd> 128 </dl> 129 </div> 130 <hr><p>CONFIDENTIAL</p></body> 131</html> 132