diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 43d377913..1339cb182 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -773,6 +773,8 @@ add_library(core STATIC hle/service/ns/read_only_application_control_data_interface.h hle/service/ns/read_only_application_record_interface.cpp hle/service/ns/read_only_application_record_interface.h + hle/service/ns/service_getter_interface.cpp + hle/service/ns/service_getter_interface.h hle/service/ns/system_update_control.cpp hle/service/ns/system_update_control.h hle/service/ns/system_update_interface.cpp diff --git a/src/core/hle/service/am/service/application_functions.cpp b/src/core/hle/service/am/service/application_functions.cpp index a40789c01..cb53b07e0 100644 --- a/src/core/hle/service/am/service/application_functions.cpp +++ b/src/core/hle/service/am/service/application_functions.cpp @@ -17,7 +17,7 @@ #include "core/hle/service/filesystem/save_data_controller.h" #include "core/hle/service/glue/glue_manager.h" #include "core/hle/service/ns/application_manager_interface.h" -#include "core/hle/service/ns/ns.h" +#include "core/hle/service/ns/service_getter_interface.h" #include "core/hle/service/sm/sm.h" namespace Service::AM { @@ -164,8 +164,10 @@ Result IApplicationFunctions::GetDesiredLanguage(Out out_language_code) { // Call IApplicationManagerInterface implementation. auto& service_manager = system.ServiceManager(); - auto ns_am2 = service_manager.GetService("ns:am2"); - auto app_man = ns_am2->GetApplicationManagerInterface(); + auto ns_am2 = service_manager.GetService("ns:am2"); + + std::shared_ptr app_man; + R_TRY(ns_am2->GetApplicationManagerInterface(&app_man)); // Get desired application language NS::ApplicationLanguage desired_language{}; diff --git a/src/core/hle/service/am/service/library_applet_self_accessor.cpp b/src/core/hle/service/am/service/library_applet_self_accessor.cpp index 932e354e0..963e67487 100644 --- a/src/core/hle/service/am/service/library_applet_self_accessor.cpp +++ b/src/core/hle/service/am/service/library_applet_self_accessor.cpp @@ -15,7 +15,7 @@ #include "core/hle/service/filesystem/filesystem.h" #include "core/hle/service/glue/glue_manager.h" #include "core/hle/service/ns/application_manager_interface.h" -#include "core/hle/service/ns/ns.h" +#include "core/hle/service/ns/service_getter_interface.h" #include "core/hle/service/sm/sm.h" namespace Service::AM { @@ -257,8 +257,10 @@ Result ILibraryAppletSelfAccessor::GetMainAppletApplicationDesiredLanguage( // Call IApplicationManagerInterface implementation. auto& service_manager = system.ServiceManager(); - auto ns_am2 = service_manager.GetService("ns:am2"); - auto app_man = ns_am2->GetApplicationManagerInterface(); + auto ns_am2 = service_manager.GetService("ns:am2"); + + std::shared_ptr app_man; + R_TRY(ns_am2->GetApplicationManagerInterface(&app_man)); // Get desired application language NS::ApplicationLanguage desired_language{}; diff --git a/src/core/hle/service/ns/ns.cpp b/src/core/hle/service/ns/ns.cpp index 9937e7bb7..96fa221b0 100644 --- a/src/core/hle/service/ns/ns.cpp +++ b/src/core/hle/service/ns/ns.cpp @@ -1,101 +1,32 @@ // 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/service_getter_interface.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, "GetDynamicRightsInterface"}, - {7989, &NS::PushInterface, "GetReadOnlyApplicationControlDataInterface"}, - {7991, &NS::PushInterface, "GetReadOnlyApplicationRecordInterface"}, - {7992, &NS::PushInterface, "GetECommerceInterface"}, - {7993, &NS::PushInterface, "GetApplicationVersionInterface"}, - {7994, &NS::PushInterface, "GetFactoryResetInterface"}, - {7995, &NS::PushInterface, "GetAccountProxyInterface"}, - {7996, &NS::PushIApplicationManagerInterface, "GetApplicationManagerInterface"}, - {7997, &NS::PushInterface, "GetDownloadTaskInterface"}, - {7998, &NS::PushInterface, "GetContentManagementInterface"}, - {7999, &NS::PushInterface, "GetDocumentInterface"}, - }; - // clang-format on - - RegisterHandlers(functions); -} - -NS::~NS() = default; - -std::shared_ptr NS::GetApplicationManagerInterface() const { - return GetInterface(system); -} - -template -void NS::PushInterface(HLERequestContext& ctx) { - LOG_DEBUG(Service_NS, "called"); - - IPC::ResponseBuilder rb{ctx, 2, 0, 1}; - rb.Push(ResultSuccess); - rb.PushIpcInterface(system); -} - -void NS::PushIApplicationManagerInterface(HLERequestContext& ctx) { - LOG_DEBUG(Service_NS, "called"); - - IPC::ResponseBuilder rb{ctx, 2, 0, 1}; - rb.Push(ResultSuccess); - rb.PushIpcInterface(system); -} - -template -std::shared_ptr NS::GetInterface(Args&&... args) const { - static_assert(std::is_base_of_v, - "Not a base of ServiceFrameworkBase"); - - return std::make_shared(std::forward(args)...); -} - void LoopProcess(Core::System& system) { auto server_manager = std::make_unique(system); - server_manager->RegisterNamedService("ns:am2", std::make_shared("ns:am2", system)); - server_manager->RegisterNamedService("ns:ec", std::make_shared("ns:ec", system)); - server_manager->RegisterNamedService("ns:rid", std::make_shared("ns:rid", system)); - server_manager->RegisterNamedService("ns:rt", std::make_shared("ns:rt", system)); - server_manager->RegisterNamedService("ns:web", std::make_shared("ns:web", system)); - server_manager->RegisterNamedService("ns:ro", std::make_shared("ns:ro", system)); + server_manager->RegisterNamedService( + "ns:am2", std::make_shared(system, "ns:am2")); + server_manager->RegisterNamedService( + "ns:ec", std::make_shared(system, "ns:ec")); + server_manager->RegisterNamedService( + "ns:rid", std::make_shared(system, "ns:rid")); + server_manager->RegisterNamedService( + "ns:rt", std::make_shared(system, "ns:rt")); + server_manager->RegisterNamedService( + "ns:web", std::make_shared(system, "ns:web")); + server_manager->RegisterNamedService( + "ns:ro", std::make_shared(system, "ns:ro")); server_manager->RegisterNamedService("ns:dev", std::make_shared(system)); server_manager->RegisterNamedService("ns:su", std::make_shared(system)); diff --git a/src/core/hle/service/ns/ns.h b/src/core/hle/service/ns/ns.h index ef5c575da..f79b4ae3d 100644 --- a/src/core/hle/service/ns/ns.h +++ b/src/core/hle/service/ns/ns.h @@ -3,33 +3,12 @@ #pragma once -#include "core/hle/service/service.h" - namespace Core { class System; } namespace Service::NS { -class IApplicationManagerInterface; - -class NS final : public ServiceFramework { -public: - explicit NS(const char* name, Core::System& system_); - ~NS() override; - - std::shared_ptr GetApplicationManagerInterface() const; - -private: - template - void PushInterface(HLERequestContext& ctx); - - void PushIApplicationManagerInterface(HLERequestContext& ctx); - - template - std::shared_ptr GetInterface(Args&&... args) const; -}; - void LoopProcess(Core::System& system); } // namespace Service::NS diff --git a/src/core/hle/service/ns/service_getter_interface.cpp b/src/core/hle/service/ns/service_getter_interface.cpp new file mode 100644 index 000000000..1a3dd7166 --- /dev/null +++ b/src/core/hle/service/ns/service_getter_interface.cpp @@ -0,0 +1,120 @@ +// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "core/hle/service/cmif_serialization.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/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/read_only_application_control_data_interface.h" +#include "core/hle/service/ns/read_only_application_record_interface.h" +#include "core/hle/service/ns/service_getter_interface.h" + +namespace Service::NS { + +IServiceGetterInterface::IServiceGetterInterface(Core::System& system_, const char* name) + : ServiceFramework{system_, name} { + // clang-format off + static const FunctionInfo functions[] = { + {7988, D<&IServiceGetterInterface::GetDynamicRightsInterface>, "GetDynamicRightsInterface"}, + {7989, D<&IServiceGetterInterface::GetReadOnlyApplicationControlDataInterface>, "GetReadOnlyApplicationControlDataInterface"}, + {7991, D<&IServiceGetterInterface::GetReadOnlyApplicationRecordInterface>, "GetReadOnlyApplicationRecordInterface"}, + {7992, D<&IServiceGetterInterface::GetECommerceInterface>, "GetECommerceInterface"}, + {7993, D<&IServiceGetterInterface::GetApplicationVersionInterface>, "GetApplicationVersionInterface"}, + {7994, D<&IServiceGetterInterface::GetFactoryResetInterface>, "GetFactoryResetInterface"}, + {7995, D<&IServiceGetterInterface::GetAccountProxyInterface>, "GetAccountProxyInterface"}, + {7996, D<&IServiceGetterInterface::GetApplicationManagerInterface>, "GetApplicationManagerInterface"}, + {7997, D<&IServiceGetterInterface::GetDownloadTaskInterface>, "GetDownloadTaskInterface"}, + {7998, D<&IServiceGetterInterface::GetContentManagementInterface>, "GetContentManagementInterface"}, + {7999, D<&IServiceGetterInterface::GetDocumentInterface>, "GetDocumentInterface"}, + }; + // clang-format on + + RegisterHandlers(functions); +} + +IServiceGetterInterface::~IServiceGetterInterface() = default; + +Result IServiceGetterInterface::GetDynamicRightsInterface( + Out> out_interface) { + LOG_DEBUG(Service_NS, "called"); + *out_interface = std::make_shared(system); + R_SUCCEED(); +} + +Result IServiceGetterInterface::GetReadOnlyApplicationControlDataInterface( + Out> out_interface) { + LOG_DEBUG(Service_NS, "called"); + *out_interface = std::make_shared(system); + R_SUCCEED(); +} + +Result IServiceGetterInterface::GetReadOnlyApplicationRecordInterface( + Out> out_interface) { + LOG_DEBUG(Service_NS, "called"); + *out_interface = std::make_shared(system); + R_SUCCEED(); +} + +Result IServiceGetterInterface::GetECommerceInterface( + Out> out_interface) { + LOG_DEBUG(Service_NS, "called"); + *out_interface = std::make_shared(system); + R_SUCCEED(); +} + +Result IServiceGetterInterface::GetApplicationVersionInterface( + Out> out_interface) { + LOG_DEBUG(Service_NS, "called"); + *out_interface = std::make_shared(system); + R_SUCCEED(); +} + +Result IServiceGetterInterface::GetFactoryResetInterface( + Out> out_interface) { + LOG_DEBUG(Service_NS, "called"); + *out_interface = std::make_shared(system); + R_SUCCEED(); +} + +Result IServiceGetterInterface::GetAccountProxyInterface( + Out> out_interface) { + LOG_DEBUG(Service_NS, "called"); + *out_interface = std::make_shared(system); + R_SUCCEED(); +} + +Result IServiceGetterInterface::GetApplicationManagerInterface( + Out> out_interface) { + LOG_DEBUG(Service_NS, "called"); + *out_interface = std::make_shared(system); + R_SUCCEED(); +} + +Result IServiceGetterInterface::GetDownloadTaskInterface( + Out> out_interface) { + LOG_DEBUG(Service_NS, "called"); + *out_interface = std::make_shared(system); + R_SUCCEED(); +} + +Result IServiceGetterInterface::GetContentManagementInterface( + Out> out_interface) { + LOG_DEBUG(Service_NS, "called"); + *out_interface = std::make_shared(system); + R_SUCCEED(); +} + +Result IServiceGetterInterface::GetDocumentInterface( + Out> out_interface) { + LOG_DEBUG(Service_NS, "called"); + *out_interface = std::make_shared(system); + R_SUCCEED(); +} + +} // namespace Service::NS diff --git a/src/core/hle/service/ns/service_getter_interface.h b/src/core/hle/service/ns/service_getter_interface.h new file mode 100644 index 000000000..bbc18d444 --- /dev/null +++ b/src/core/hle/service/ns/service_getter_interface.h @@ -0,0 +1,47 @@ +// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "core/hle/service/cmif_types.h" +#include "core/hle/service/service.h" + +namespace Service::NS { + +class IDynamicRightsInterface; +class IReadOnlyApplicationControlDataInterface; +class IReadOnlyApplicationRecordInterface; +class IECommerceInterface; +class IApplicationVersionInterface; +class IFactoryResetInterface; +class IAccountProxyInterface; +class IApplicationManagerInterface; +class IDownloadTaskInterface; +class IContentManagementInterface; +class IDocumentInterface; + +class IServiceGetterInterface : public ServiceFramework { +public: + explicit IServiceGetterInterface(Core::System& system_, const char* name); + ~IServiceGetterInterface() override; + +public: + Result GetDynamicRightsInterface(Out> out_interface); + Result GetReadOnlyApplicationControlDataInterface( + Out> out_interface); + Result GetReadOnlyApplicationRecordInterface( + Out> out_interface); + Result GetECommerceInterface(Out> out_interface); + Result GetApplicationVersionInterface( + Out> out_interface); + Result GetFactoryResetInterface(Out> out_interface); + Result GetAccountProxyInterface(Out> out_interface); + Result GetApplicationManagerInterface( + Out> out_interface); + Result GetDownloadTaskInterface(Out> out_interface); + Result GetContentManagementInterface( + Out> out_interface); + Result GetDocumentInterface(Out> out_interface); +}; + +} // namespace Service::NS