aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/hle/service/ns/ns.cpp
blob: 9937e7bb7bcfdd7607e39f18ef95d6b221a19d2b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#include "common/logging/log.h"
#include "common/settings.h"
#include "core/arm/debug.h"
#include "core/core.h"
#include "core/file_sys/control_metadata.h"
#include "core/file_sys/patch_manager.h"
#include "core/file_sys/vfs/vfs.h"
#include "core/hle/service/filesystem/filesystem.h"
#include "core/hle/service/glue/glue_manager.h"
#include "core/hle/service/ipc_helpers.h"
#include "core/hle/service/ns/account_proxy_interface.h"
#include "core/hle/service/ns/application_manager_interface.h"
#include "core/hle/service/ns/application_version_interface.h"
#include "core/hle/service/ns/content_management_interface.h"
#include "core/hle/service/ns/develop_interface.h"
#include "core/hle/service/ns/document_interface.h"
#include "core/hle/service/ns/download_task_interface.h"
#include "core/hle/service/ns/dynamic_rights_interface.h"
#include "core/hle/service/ns/ecommerce_interface.h"
#include "core/hle/service/ns/factory_reset_interface.h"
#include "core/hle/service/ns/language.h"
#include "core/hle/service/ns/ns.h"
#include "core/hle/service/ns/ns_results.h"
#include "core/hle/service/ns/pdm_qry.h"
#include "core/hle/service/ns/platform_service_manager.h"
#include "core/hle/service/ns/read_only_application_control_data_interface.h"
#include "core/hle/service/ns/read_only_application_record_interface.h"
#include "core/hle/service/ns/system_update_control.h"
#include "core/hle/service/ns/system_update_interface.h"
#include "core/hle/service/ns/vulnerability_manager_interface.h"
#include "core/hle/service/server_manager.h"
#include "core/hle/service/set/settings_server.h"

namespace Service::NS {

NS::NS(const char* name, Core::System& system_) : ServiceFramework{system_, name} {
    // clang-format off
    static const FunctionInfo functions[] = {
        {7988, &NS::PushInterface<IDynamicRightsInterface>, "GetDynamicRightsInterface"},
        {7989, &NS::PushInterface<IReadOnlyApplicationControlDataInterface>, "GetReadOnlyApplicationControlDataInterface"},
        {7991, &NS::PushInterface<IReadOnlyApplicationRecordInterface>, "GetReadOnlyApplicationRecordInterface"},
        {7992, &NS::PushInterface<IECommerceInterface>, "GetECommerceInterface"},
        {7993, &NS::PushInterface<IApplicationVersionInterface>, "GetApplicationVersionInterface"},
        {7994, &NS::PushInterface<IFactoryResetInterface>, "GetFactoryResetInterface"},
        {7995, &NS::PushInterface<IAccountProxyInterface>, "GetAccountProxyInterface"},
        {7996, &NS::PushIApplicationManagerInterface, "GetApplicationManagerInterface"},
        {7997, &NS::PushInterface<IDownloadTaskInterface>, "GetDownloadTaskInterface"},
        {7998, &NS::PushInterface<IContentManagementInterface>, "GetContentManagementInterface"},
        {7999, &NS::PushInterface<IDocumentInterface>, "GetDocumentInterface"},
    };
    // clang-format on

    RegisterHandlers(functions);
}

NS::~NS() = default;

std::shared_ptr<IApplicationManagerInterface> NS::GetApplicationManagerInterface() const {
    return GetInterface<IApplicationManagerInterface>(system);
}

template <typename T, typename... Args>
void NS::PushInterface(HLERequestContext& ctx) {
    LOG_DEBUG(Service_NS, "called");

    IPC::ResponseBuilder rb{ctx, 2, 0, 1};
    rb.Push(ResultSuccess);
    rb.PushIpcInterface<T>(system);
}

void NS::PushIApplicationManagerInterface(HLERequestContext& ctx) {
    LOG_DEBUG(Service_NS, "called");

    IPC::ResponseBuilder rb{ctx, 2, 0, 1};
    rb.Push(ResultSuccess);
    rb.PushIpcInterface<IApplicationManagerInterface>(system);
}

template <typename T, typename... Args>
std::shared_ptr<T> NS::GetInterface(Args&&... args) const {
    static_assert(std::is_base_of_v<SessionRequestHandler, T>,
                  "Not a base of ServiceFrameworkBase");

    return std::make_shared<T>(std::forward<Args>(args)...);
}

void LoopProcess(Core::System& system) {
    auto server_manager = std::make_unique<ServerManager>(system);

    server_manager->RegisterNamedService("ns:am2", std::make_shared<NS>("ns:am2", system));
    server_manager->RegisterNamedService("ns:ec", std::make_shared<NS>("ns:ec", system));
    server_manager->RegisterNamedService("ns:rid", std::make_shared<NS>("ns:rid", system));
    server_manager->RegisterNamedService("ns:rt", std::make_shared<NS>("ns:rt", system));
    server_manager->RegisterNamedService("ns:web", std::make_shared<NS>("ns:web", system));
    server_manager->RegisterNamedService("ns:ro", std::make_shared<NS>("ns:ro", system));

    server_manager->RegisterNamedService("ns:dev", std::make_shared<IDevelopInterface>(system));
    server_manager->RegisterNamedService("ns:su", std::make_shared<ISystemUpdateInterface>(system));
    server_manager->RegisterNamedService("ns:vm",
                                         std::make_shared<IVulnerabilityManagerInterface>(system));
    server_manager->RegisterNamedService("pdm:qry", std::make_shared<PDM_QRY>(system));

    server_manager->RegisterNamedService("pl:s",
                                         std::make_shared<IPlatformServiceManager>(system, "pl:s"));
    server_manager->RegisterNamedService("pl:u",
                                         std::make_shared<IPlatformServiceManager>(system, "pl:u"));
    ServerManager::RunServer(std::move(server_manager));
}

} // namespace Service::NS