1 /*---------------------------------------------------------------------------*
2   Project:  Horizon
3   File:     ndm_Setup.cpp
4 
5   Copyright (C)2009 Nintendo Co., Ltd.  All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain
8   proprietary information of Nintendo of America Inc. and/or Nintendo
9   Company Ltd., and are protected by Federal copyright law. They may
10   not be disclosed to third parties or copied or duplicated in any form,
11   in whole or in part, without the prior written consent of Nintendo.
12 
13   $Rev: 36759 $
14  *---------------------------------------------------------------------------*/
15 
16 #include <nn/config.h>
17 #include <nn/ndm.h>
18 #include <nn/ndm/ndm_UserControlPrivate.h>
19 #include <nn/os.h>
20 #include <nn/applet.h>
21 
22 namespace nn {
23 namespace applet {
24 namespace CTR {
25     // Don't do anything unnecessary when libnn_applet.a has not been linked...
IsInitialized(void)26     __declspec(noinline) NN_WEAK_SYMBOL bool IsInitialized(void)
27     {
28         return false;
29     }
GetAppletType(void)30     __declspec(noinline) NN_WEAK_SYMBOL AppletAttr GetAppletType(void)
31     {
32         return nn::applet::TYPE_APP;
33     }
34 }}}
35 
36 namespace nn {
37 namespace ndm {
38 
39 #ifndef NN_SWITCH_DISABLE_DEBUG_PRINT_FOR_SDK
40 //#define NN_NDM_TIMECHECK
41 #endif
42 
SetupDaemonsDefault(void)43 void SetupDaemonsDefault(void)
44 {
45 #ifdef NN_NDM_TIMECHECK
46     nn::os::Tick tickStart = nn::os::Tick::GetSystemCurrent();
47 #endif
48 
49     // The applet does nothing. Processing is only handled by the application.
50     if (nn::applet::IsInitialized()
51         && nn::applet::GetAppletType() == nn::applet::TYPE_APP)
52     {
53         NN_LOG_INFO("Overriding default daemons...");
54 
55         Result result = nn::ndm::Initialize();
56         NN_UTIL_PANIC_IF_FAILED(result);
57 
58         /////////////////////////////////////////////////////
59         // Set the default policy for this SDK version     //
60         /////////////////////////////////////////////////////
61 
62         // BOSS is disabled by default because the handling by SDK 1.x disables it mid-process.
63         // Because processing will remain stopped even if Resume and Suspend are called from this state, temporarily restore everything to being enabled.
64         // NOTE: This operation, too, is rolled back when the application exits.
65         result = nn::ndm::OverrideDefaultDaemons(MASK_ALL_DAEMONS);
66         if (result.IsFailure())
67         {
68             NN_TLOG_("Failed to override default daemons. (SDK version mismatch?)\n");
69             nn::dbg::PrintResult(result);
70         }
71 
72         // Suspend with this application's privileges so that we can start again later via Resume.
73         result = nn::ndm::SuspendDaemons(~MASK_DEFAULT_ENABLED_DAEMONS & MASK_ALL_DAEMONS);
74         if (result.IsFailure())
75         {
76             NN_TLOG_("Failed to suspend boss daemon.\n");
77             nn::dbg::PrintResult(result);
78         }
79     }
80 
81 #ifdef NN_NDM_TIMECHECK
82     NN_TLOG_("All network daemons are disabled by default at this time. (took %lldms)\n", (nn::os::Tick::GetSystemCurrent() - tickStart).ToTimeSpan().GetMilliSeconds());
83 #endif
84 }
85 
86 } // end of namespace ndm
87 } // end of namespace nn
88