/*---------------------------------------------------------------------------* Project: Horizon File: ndm_UserControl.cpp Copyright (C)2009 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: 36718 $ *---------------------------------------------------------------------------*/ #include #include #include #include #include #include #include #include #include "ndm_LibraryPrivate.h" NN_DBG_DECLARE_GET_RESULT_DESCRIPTION_STRING_IMPL_KEEPER(ndm) namespace { s32 s_InitializedCount = 0; nn::os::CriticalSection s_cs = nn::WithInitialize(); } namespace nn { namespace ndm { using namespace CTR; using namespace CTR::detail; Result Initialize(void) { nn::os::CriticalSection::ScopedLock locker(s_cs); Result result; NN_DBG_USE_GET_RESULT_DESCRIPTION_STRING_IMPL_KEEPER(ndm); if (s_InitializedCount == 0) { nn::srv::Initialize(); result = nn::srv::GetServiceHandle(&Interface::s_Session, PORT_NAME_USER); NN_UTIL_RETURN_IF_FAILED(result); } ++s_InitializedCount; return ResultSuccess(); } Result Finalize() { nn::os::CriticalSection::ScopedLock locker(s_cs); Result result; if (s_InitializedCount == 0) { NN_LOG_WARN("ndm library is not initialized."); return ResultNotInitialized(); } else if (s_InitializedCount == 1) { result = nn::svc::CloseHandle(Interface::s_Session); NN_UTIL_RETURN_IF_FAILED(result); CTR::detail::Interface::s_Session = Handle(); } --s_InitializedCount; return ResultSuccess(); } bool IsInitialized(void) { return s_InitializedCount > 0; } Result EnterExclusiveState(ExclusiveMode mode) { return Interface::EnterExclusiveState(static_cast(mode)); } Result QueryExclusiveMode(ExclusiveMode& mode) { s32 modeNumber; Result result = Interface::QueryExclusiveMode(&modeNumber); NN_UTIL_RETURN_IF_FAILED(result); mode = static_cast(modeNumber); return ResultSuccess(); } Result LeaveExclusiveState(void) { return Interface::LeaveExclusiveState(); } Result LockState(void) { return Interface::LockState(); } Result UnlockState(void) { return Interface::UnlockState(); } Result SuspendDaemons(bit32 mask) { return Interface::SuspendDaemons(mask); } Result ResumeDaemons(bit32 mask) { return Interface::ResumeDaemons(mask); } Result Suspend(DaemonName name) { if (name < 0 || name >= NUM_OF_DAEMONS) { return ResultInvalidEnumValue(); } return SuspendDaemons(1 << name); } Result Resume(DaemonName name) { if (name < 0 || name >= NUM_OF_DAEMONS) { return ResultInvalidEnumValue(); } return ResumeDaemons(1 << name); } Result SuspendScheduler(bool bAsync) { return Interface::SuspendScheduler(bAsync); } Result ResumeScheduler(void) { return Interface::ResumeScheduler(); } Result OverrideDefaultDaemons( bit32 mask ) { return Interface::OverrideDefaultDaemons(mask); } Result ResetDefaultDaemons( void ) { return Interface::ResetDefaultDaemons(); } } // end of namespace ndm } // end of namespace nn