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><a href="../../../nn/Overview.html">nn</a>::<a href="../../../nn/applet/Overview.html">applet</a>::<a href="../../../nn/applet/CTR/Overview.html">CTR</a>::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 <a href="../../../nn_types/uptr.html">uptr</a> 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"> 43None. 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><FONT color="red">The name of this callback implies that this callback is called after it is certain that sleep is canceled. This is not the case. </FONT> This callback is intended simply to inform ongoing processes that the system has been opened. 50</P><P> 51If this callback is called while the local process is deferring reply to the sleep request (see <B>Note 1</B>) and you then want to reject the sleep request, use the <a href="../../../nn/applet/CTR/ReplySleepQuery.html"><CODE>nn::applet::CTR::ReplySleepQuery</CODE></a> function to return <CODE>nn::applet::CTR::REPLY_REJECT</CODE>. If you simply wish to be informed that the system was opened, you do not need to do anything. The applet manager will continue to wait for replies to the sleep query. 52</P><P> 53This callback is intended for uses such as quickly detecting that the system has been opened and canceling 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. 54</P><PRE> 55Example 56bool isShellOpened; 57nn::os::LightEvent awakeEvent; 58// Sleep cancel callback 59void mySleepCanceledCallback(uptr arg) 60{ 61NN_UNUSED_VAR(arg); 62if ( applet::IsActive() ) 63 { 64isShellOpened = true; // System opened 65applet::ReplySleepQuery( applet::REPLY_REJECT ); 66 } 67} 68// Sleep query callback 69void mySleepQueryCallback(uptr arg) 70{ 71NN_UNUSED_VAR(arg); 72if ( applet::IsActive() ) 73 { 74isShellOpened = false; 75awakeEvent.ClearSignal(); 76return applet::REPLY_LATER; 77 } 78else 79 { 80return applet::REPLY_ACCEPT; 81 } 82} 83// Wakeup callback 84void myAwakeCallback(uptr arg) 85{ 86NN_UNUSED_VAR(arg); 87awakeEvent.Signal(); // Wake up 88} 89// Main 90void nnMain() 91{ 92awakeEvent.Initialize(false); 93applet::SetSleepQueryCallback( mySleepQueryCallback, 0 ); 94applet::SetSleepCanceledCallback( mySleepCanceledCallback, 0 ); 95applet::SetAwakeCallback( myAwakeCallback, 0 ); 96applet::Enable(); 97while (1) 98 { 99_exec(); 100_draw(); 101if ( applet::IsExpectedToReplySleepQuery() ) 102 { 103for(int i=0; i<N; n++) // Heavy processing before going to sleep. For instance, when saving <CODE>N</CODE> items of data. 104 { 105_save( data[i] ); 106if ( isShellOpened ) // Interrupt since system is opened in the middle of all this 107 { 108break; 109 } 110 } 111// If system not opened, accept sleep query and wait to wake up 112if ( !isShellOpened ) 113 { 114applet::ReplySleepQuery( applet::REPLY_ACCEPT ); 115awakeEvent.Wait(); 116 } 117 } 118 } 119} 120</PRE><P> 121<B>Note 1:</B> 122</P><P> 123This callback is called whenever the system is opened while the applet manager is still waiting to receive all the replies from all the applications and applets. That means that coincidences of system status and timing can cause it to be called before applications have returned any replies at all, and likewise it might be called after applications have replied as long as some other applet has not yet returned a reply. 124</P></div> 125<h2>Revision History</h2> 126 <div class="section"> 127 <dl class="history"> 128 <dt>2010/11/29</dt> 129<dd>Initial version.<br /> 130 </dd> 131 </dl> 132 </div> 133 <hr><p>CONFIDENTIAL</p></body> 134</html> 135