mirror of
https://github.com/rvtr/ctr_Repair.git
synced 2025-10-31 13:51:08 -04:00
git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_Repair@305 385bec56-5757-e545-9c3a-d8741f4650f1
111 lines
3.9 KiB
C++
111 lines
3.9 KiB
C++
/*---------------------------------------------------------------------------*
|
|
Project: Horizon
|
|
File: sleep.cpp
|
|
|
|
Copyright (C)2010 Nintendo Co., Ltd. All rights reserved.
|
|
|
|
These coded instructions, statements, and computer programs contain
|
|
proprietary information of Nintendo of America Inc. and/or Nintendo
|
|
Company Ltd., and are protected by Federal copyright law. They may
|
|
not be disclosed to third parties or copied or duplicated in any form,
|
|
in whole or in part, without the prior written consent of Nintendo.
|
|
|
|
$Rev$
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
#include <nn/applet.h>
|
|
|
|
#include "sleep.h"
|
|
|
|
//extern nn::os::CriticalSection g_SleepCS;
|
|
extern nn::os::LightEvent g_TransitionEvent;
|
|
extern nn::os::LightEvent g_AwakeEvent;
|
|
|
|
volatile bool SleepHandler::s_IsAfterWakeUp = false;
|
|
|
|
/*------------------------------------------------------------------------*/
|
|
void SleepHandler::Initialize( void )
|
|
{
|
|
nn::applet::SetSleepQueryCallback(SleepQueryCallback, 0);
|
|
nn::applet::SetAwakeCallback(AwakeCallback, 0);
|
|
// nn::applet::SetSleepCancelCallback(NULL, 0); // CancelCallback は使わないことを推奨します
|
|
}
|
|
|
|
/*------------------------------------------------------------------------*/
|
|
void SleepHandler::Finalize( void )
|
|
{
|
|
nn::applet::SetSleepQueryCallback(NULL, 0);
|
|
nn::applet::SetAwakeCallback(NULL, 0);
|
|
|
|
nn::applet::DisableSleep();
|
|
}
|
|
|
|
/*------------------------------------------------------------------------*
|
|
システムスリープの指示が来ているかどうかを返します。
|
|
*------------------------------------------------------------------------*/
|
|
bool SleepHandler::IsSleepRequested( void )
|
|
{
|
|
if ( nn::applet::IsExpectedToReplySleepQuery() )
|
|
return true;
|
|
|
|
return false;
|
|
}
|
|
|
|
/*------------------------------------------------------------------------*
|
|
本体スリープ状態に移行させるための処理を行います。
|
|
グラフィックスなどの処理がスリープに入っても問題ない
|
|
適切なタイミングで呼び出す必要があります。
|
|
*------------------------------------------------------------------------*/
|
|
void SleepHandler::SleepSystem( void )
|
|
{
|
|
// SleepHandler::IsSleepRequested() == true における呼び出しが前提
|
|
|
|
// 何らかの理由で SleepQuery に対して REJECT を返す場合は、ここで判定して
|
|
// REJECT を返し、この関数を抜ける
|
|
|
|
// ファイルシステム処理中はスリープをしない
|
|
//if ( g_SleepCS.TryEnter() )
|
|
{
|
|
// スリープ前処理
|
|
|
|
nn::applet::ReplySleepQuery(nn::applet::REPLY_ACCEPT);
|
|
|
|
g_AwakeEvent.Wait();
|
|
|
|
// スリープ復帰時の処理
|
|
|
|
// g_SleepCS.Leave();
|
|
}
|
|
}
|
|
|
|
/*------------------------------------------------------------------------*
|
|
スリープ問い合わせ時に呼ばれるコールバック
|
|
*------------------------------------------------------------------------*/
|
|
AppletQueryReply SleepHandler::SleepQueryCallback( uptr arg )
|
|
{
|
|
NN_UNUSED_VAR(arg);
|
|
g_AwakeEvent.ClearSignal();
|
|
|
|
if ( !nn::applet::IsActive() )
|
|
{
|
|
// Inactive なとき、メインスレッドは applet::WaitForStarting() で停止状態であり、
|
|
// 他のスレッドも停止状態になっているはず(アプリケーション側の実装依存)
|
|
return nn::applet::REPLY_ACCEPT;
|
|
}
|
|
else
|
|
{
|
|
return nn::applet::REPLY_LATER;
|
|
}
|
|
}
|
|
|
|
/*------------------------------------------------------------------------*
|
|
スリープ復帰時に呼ばれるコールバック
|
|
*------------------------------------------------------------------------*/
|
|
void SleepHandler::AwakeCallback( uptr arg )
|
|
{
|
|
NN_UNUSED_VAR(arg);
|
|
g_AwakeEvent.Signal();
|
|
|
|
s_IsAfterWakeUp = true;
|
|
}
|