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>Parameters</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
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
70// Sleep query callback
71void mySleepQueryCallback(uptr arg)
72{
73  NN_UNUSED_VAR(arg);
74  if ( applet::IsActive() )
75  {
76    isShellOpened = false;
77    awakeEvent.ClearSignal();
78    return applet::REPLY_LATER;
79  }
80  else
81  {
82    return applet::REPLY_ACCEPT;
83  }
84}
85
86// Wakeup callback
87void myAwakeCallback(uptr arg)
88{
89  NN_UNUSED_VAR(arg);
90  awakeEvent.Signal();   // Wake up
91}
92
93// Main
94void nnMain()
95{
96   awakeEvent.Initialize(false);
97   applet::SetSleepQueryCallback( mySleepQueryCallback, 0 );
98   applet::SetSleepCanceledCallback( mySleepCanceledCallback, 0 );
99   applet::SetAwakeCallback( myAwakeCallback, 0 );
100   applet::Enable();
101
102
103   while(1)
104   {
105      _exec();
106      _draw();
107
108      if ( applet::IsExpectedToReplySleepQuery() )
109      {
110          for(int i=0; i<N; n++) // Heavy processing before going to sleep. For instance, when saving <CODE>N</CODE> items of data.
111          {
112            _save( data[i] );
113            if ( isShellOpened ) // Interrupt since system is opened in the middle of all this
114            {
115              break;
116            }
117          }
118
119          // If system not opened, accept sleep query and wait to wake up
120          if ( ! isShellOpened )
121          {
122            applet::ReplySleepQuery( applet::REPLY_ACCEPT );
123            awakeEvent.Wait();
124          }
125      }
126   }
127}
128</PRE><P>
129<B>Note 1:</B>
130</P><P>
131This 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.
132</P></div>
133<h2>Revision History</h2>
134    <div class="section">
135      <dl class="history">
136        <dt>2010/11/29</dt>
137<dd>Initial version.<br />
138        </dd>
139      </dl>
140    </div>
141  <hr><p>CONFIDENTIAL</p></body>
142</html>
143