/*---------------------------------------------------------------------------* Project: Horizon File: sleep.cpp Copyright (C)2009-2012 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: 46365 $ *---------------------------------------------------------------------------*/ #include #include "sleep.h" /*------------------------------------------------------------------------* Processing concerning console sleep *------------------------------------------------------------------------*/ nn::os::LightEvent SleepHandler::s_AwakeEvent; bool SleepHandler::s_IsInitialized = false; /*------------------------------------------------------------------------*/ void SleepHandler::Initialize( void ) { s_AwakeEvent.Initialize(false); nn::applet::SetSleepQueryCallback(SleepQueryCallback, 0); nn::applet::SetAwakeCallback(AwakeCallback, 0); nn::applet::Enable(); s_IsInitialized = true; } /*------------------------------------------------------------------------*/ void SleepHandler::Finalize( void ) { nn::applet::DisableSleep(); s_AwakeEvent.Finalize(); nn::applet::SetSleepQueryCallback(NULL, 0); nn::applet::SetAwakeCallback(NULL, 0); s_IsInitialized = false; } /*------------------------------------------------------------------------* Returns a value indicating whether there was an instruction to enter Sleep Mode. *------------------------------------------------------------------------*/ bool SleepHandler::IsSleepRequested( void ) { NN_TASSERT_(s_IsInitialized); if ( nn::applet::IsExpectedToReplySleepQuery() ) return true; return false; } /*------------------------------------------------------------------------* Handles processing to cause a transition to Sleep Mode. This must be called at an appropriate time so that there are no problems with graphics or other processing even if the system enters Sleep Mode. *------------------------------------------------------------------------*/ void SleepHandler::SleepSystem( void ) { // Do nothing and return if an instruction has not been received. if ( !IsSleepRequested() ) { return; } nn::applet::ReplySleepQuery(nn::applet::REPLY_ACCEPT); s_AwakeEvent.Wait(); } /*------------------------------------------------------------------------* Callback called when there is a sleep query *------------------------------------------------------------------------*/ AppletQueryReply SleepHandler::SleepQueryCallback( uptr arg ) { NN_UNUSED_VAR(arg); s_AwakeEvent.ClearSignal(); if ( !nn::applet::IsActive() ) { return nn::applet::REPLY_ACCEPT; } if ( s_IsInitialized ) { return nn::applet::REPLY_LATER; } else { return nn::applet::REPLY_REJECT; } } /*------------------------------------------------------------------------* Callback called when recovering from sleep *------------------------------------------------------------------------*/ void SleepHandler::AwakeCallback( uptr arg ) { NN_UNUSED_VAR(arg); s_AwakeEvent.Signal(); }