From d81b58f320f9ace1d80cfca6889cbee98813cd83 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Thu, 23 May 2019 01:28:27 -0700 Subject: [PATCH] Address review comments --- src/core/CMakeLists.txt | 4 +- .../ns/{ns_language.cpp => language.cpp} | 71 ++++++++++--------- src/core/hle/service/ns/language.h | 45 ++++++++++++ src/core/hle/service/ns/ns.cpp | 29 ++++++-- src/core/hle/service/ns/ns.h | 14 +++- src/core/hle/service/ns/ns_language.h | 4 +- 6 files changed, 120 insertions(+), 47 deletions(-) rename src/core/hle/service/ns/{ns_language.cpp => language.cpp} (88%) create mode 100644 src/core/hle/service/ns/language.h diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 2105b7242..fbb1b91a3 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -327,10 +327,10 @@ add_library(core STATIC hle/service/npns/npns.cpp hle/service/npns/npns.h hle/service/ns/errors.h + hle/service/ns/language.cpp + hle/service/ns/language.h hle/service/ns/ns.cpp hle/service/ns/ns.h - hle/service/ns/ns_language.cpp - hle/service/ns/ns_language.h hle/service/ns/pl_u.cpp hle/service/ns/pl_u.h hle/service/nvdrv/devices/nvdevice.h diff --git a/src/core/hle/service/ns/ns_language.cpp b/src/core/hle/service/ns/language.cpp similarity index 88% rename from src/core/hle/service/ns/ns_language.cpp rename to src/core/hle/service/ns/language.cpp index fa95e75da..29c4a820c 100644 --- a/src/core/hle/service/ns/ns_language.cpp +++ b/src/core/hle/service/ns/language.cpp @@ -1,8 +1,9 @@ -// Copyright 2018 yuzu emulator team +// Copyright 2019 yuzu emulator team // Licensed under GPLv2 or any later version // Refer to the license.txt file included. -#include "core/hle/service/ns/ns_language.h" +#include "core/hle/service/ns/language.h" +#include "core/hle/service/set/set.h" namespace Service::NS { @@ -277,7 +278,7 @@ constexpr ApplicationLanguagePriorityList priority_list_simplified_chinese = {{ }}; const ApplicationLanguagePriorityList* GetApplicationLanguagePriorityList( - ApplicationLanguage lang) { + const ApplicationLanguage lang) { switch (lang) { case ApplicationLanguage::AmericanEnglish: return &priority_list_american_english; @@ -315,75 +316,75 @@ const ApplicationLanguagePriorityList* GetApplicationLanguagePriorityList( } std::optional ConvertToApplicationLanguage( - const Service::Set::LanguageCode language_code) { + const Set::LanguageCode language_code) { switch (language_code) { - case Service::Set::LanguageCode::EN_US: + case Set::LanguageCode::EN_US: return ApplicationLanguage::AmericanEnglish; - case Service::Set::LanguageCode::EN_GB: + case Set::LanguageCode::EN_GB: return ApplicationLanguage::BritishEnglish; - case Service::Set::LanguageCode::JA: + case Set::LanguageCode::JA: return ApplicationLanguage::Japanese; - case Service::Set::LanguageCode::FR: + case Set::LanguageCode::FR: return ApplicationLanguage::French; - case Service::Set::LanguageCode::DE: + case Set::LanguageCode::DE: return ApplicationLanguage::German; - case Service::Set::LanguageCode::ES_419: + case Set::LanguageCode::ES_419: return ApplicationLanguage::LatinAmericanSpanish; - case Service::Set::LanguageCode::ES: + case Set::LanguageCode::ES: return ApplicationLanguage::Spanish; - case Service::Set::LanguageCode::IT: + case Set::LanguageCode::IT: return ApplicationLanguage::Italian; - case Service::Set::LanguageCode::NL: + case Set::LanguageCode::NL: return ApplicationLanguage::Dutch; - case Service::Set::LanguageCode::FR_CA: + case Set::LanguageCode::FR_CA: return ApplicationLanguage::CanadianFrench; - case Service::Set::LanguageCode::PT: + case Set::LanguageCode::PT: return ApplicationLanguage::Portuguese; - case Service::Set::LanguageCode::RU: + case Set::LanguageCode::RU: return ApplicationLanguage::Russian; - case Service::Set::LanguageCode::KO: + case Set::LanguageCode::KO: return ApplicationLanguage::Korean; - case Service::Set::LanguageCode::ZH_HANT: + case Set::LanguageCode::ZH_HANT: return ApplicationLanguage::TraditionalChinese; - case Service::Set::LanguageCode::ZH_HANS: + case Set::LanguageCode::ZH_HANS: return ApplicationLanguage::SimplifiedChinese; default: return std::nullopt; } } -std::optional ConvertToLanguageCode(const ApplicationLanguage lang) { +std::optional ConvertToLanguageCode(const ApplicationLanguage lang) { switch (lang) { case ApplicationLanguage::AmericanEnglish: - return Service::Set::LanguageCode::EN_US; + return Set::LanguageCode::EN_US; case ApplicationLanguage::BritishEnglish: - return Service::Set::LanguageCode::EN_GB; + return Set::LanguageCode::EN_GB; case ApplicationLanguage::Japanese: - return Service::Set::LanguageCode::JA; + return Set::LanguageCode::JA; case ApplicationLanguage::French: - return Service::Set::LanguageCode::FR; + return Set::LanguageCode::FR; case ApplicationLanguage::German: - return Service::Set::LanguageCode::DE; + return Set::LanguageCode::DE; case ApplicationLanguage::LatinAmericanSpanish: - return Service::Set::LanguageCode::ES_419; + return Set::LanguageCode::ES_419; case ApplicationLanguage::Spanish: - return Service::Set::LanguageCode::ES; + return Set::LanguageCode::ES; case ApplicationLanguage::Italian: - return Service::Set::LanguageCode::IT; + return Set::LanguageCode::IT; case ApplicationLanguage::Dutch: - return Service::Set::LanguageCode::NL; + return Set::LanguageCode::NL; case ApplicationLanguage::CanadianFrench: - return Service::Set::LanguageCode::FR_CA; + return Set::LanguageCode::FR_CA; case ApplicationLanguage::Portuguese: - return Service::Set::LanguageCode::PT; + return Set::LanguageCode::PT; case ApplicationLanguage::Russian: - return Service::Set::LanguageCode::RU; + return Set::LanguageCode::RU; case ApplicationLanguage::Korean: - return Service::Set::LanguageCode::KO; + return Set::LanguageCode::KO; case ApplicationLanguage::TraditionalChinese: - return Service::Set::LanguageCode::ZH_HANT; + return Set::LanguageCode::ZH_HANT; case ApplicationLanguage::SimplifiedChinese: - return Service::Set::LanguageCode::ZH_HANS; + return Set::LanguageCode::ZH_HANS; default: return std::nullopt; } diff --git a/src/core/hle/service/ns/language.h b/src/core/hle/service/ns/language.h new file mode 100644 index 000000000..e9829f9d2 --- /dev/null +++ b/src/core/hle/service/ns/language.h @@ -0,0 +1,45 @@ +// Copyright 2019 yuzu emulator team +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include +#include +#include "common/common_types.h" + +namespace Service::Set { +enum class LanguageCode : u64; +} + +namespace Service::NS { +/// This is nn::ns::detail::ApplicationLanguage +enum class ApplicationLanguage : u8 { + AmericanEnglish = 0, + BritishEnglish, + Japanese, + French, + German, + LatinAmericanSpanish, + Spanish, + Italian, + Dutch, + CanadianFrench, + Portuguese, + Russian, + Korean, + TraditionalChinese, + SimplifiedChinese, + Count +}; +using ApplicationLanguagePriorityList = + const std::array(ApplicationLanguage::Count)>; + +constexpr u32 GetSupportedLanguageFlag(const ApplicationLanguage lang) { + return 1U << static_cast(lang); +} + +const ApplicationLanguagePriorityList* GetApplicationLanguagePriorityList(ApplicationLanguage lang); +std::optional ConvertToApplicationLanguage(Set::LanguageCode language_code); +std::optional ConvertToLanguageCode(ApplicationLanguage lang); +} // namespace Service::NS \ No newline at end of file diff --git a/src/core/hle/service/ns/ns.cpp b/src/core/hle/service/ns/ns.cpp index fa49b4293..e892b50f3 100644 --- a/src/core/hle/service/ns/ns.cpp +++ b/src/core/hle/service/ns/ns.cpp @@ -9,8 +9,9 @@ #include "core/hle/kernel/hle_ipc.h" #include "core/hle/service/ns/errors.h" #include "core/hle/service/ns/ns.h" -#include "core/hle/service/ns/ns_language.h" +#include "core/hle/service/ns/language.h" #include "core/hle/service/ns/pl_u.h" +#include "core/hle/service/set/set.h" #include "core/settings.h" namespace Service::NS { @@ -25,6 +26,8 @@ IAccountProxyInterface::IAccountProxyInterface() : ServiceFramework{"IAccountPro RegisterHandlers(functions); } +IAccountProxyInterface::~IAccountProxyInterface() = default; + IApplicationManagerInterface::IApplicationManagerInterface() : ServiceFramework{"IApplicationManagerInterface"} { // clang-format off @@ -246,6 +249,8 @@ IApplicationManagerInterface::IApplicationManagerInterface() RegisterHandlers(functions); } +IApplicationManagerInterface::~IApplicationManagerInterface() = default; + void IApplicationManagerInterface::GetApplicationControlData(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto flag = rp.PopRaw(); @@ -325,7 +330,7 @@ ResultVal IApplicationManagerInterface::GetApplicationDesiredLanguage( // Get language code from settings const auto language_code = - Service::Set::GetLanguageCodeFromIndex(Settings::values.language_index); + Set::GetLanguageCodeFromIndex(Settings::values.language_index); // Convert to application language, get priority list const auto application_language = ConvertToApplicationLanguage(language_code); @@ -342,7 +347,7 @@ ResultVal IApplicationManagerInterface::GetApplicationDesiredLanguage( const auto supported_flag = GetSupportedLanguageFlag(lang); if (supported_languages == 0 || (supported_languages & supported_flag) == supported_languages) { - return ResultVal::WithCode(RESULT_SUCCESS, static_cast(lang)); + return MakeResult(static_cast(lang)); } } @@ -373,7 +378,7 @@ ResultVal IApplicationManagerInterface::ConvertApplicationLanguageToLanguag return ERR_APPLICATION_LANGUAGE_NOT_FOUND; } - return ResultVal::WithCode(RESULT_SUCCESS, static_cast(*language_code)); + return MakeResult(static_cast(*language_code)); } IApplicationVersionInterface::IApplicationVersionInterface() @@ -395,6 +400,8 @@ IApplicationVersionInterface::IApplicationVersionInterface() RegisterHandlers(functions); } +IApplicationVersionInterface::~IApplicationVersionInterface() = default; + IContentManagerInterface::IContentManagerInterface() : ServiceFramework{"IContentManagerInterface"} { // clang-format off @@ -413,6 +420,8 @@ IContentManagerInterface::IContentManagerInterface() RegisterHandlers(functions); } +IContentManagerInterface::~IContentManagerInterface() = default; + IDocumentInterface::IDocumentInterface() : ServiceFramework{"IDocumentInterface"} { // clang-format off static const FunctionInfo functions[] = { @@ -425,6 +434,8 @@ IDocumentInterface::IDocumentInterface() : ServiceFramework{"IDocumentInterface" RegisterHandlers(functions); } +IDocumentInterface::~IDocumentInterface() = default; + IDownloadTaskInterface::IDownloadTaskInterface() : ServiceFramework{"IDownloadTaskInterface"} { // clang-format off static const FunctionInfo functions[] = { @@ -443,6 +454,8 @@ IDownloadTaskInterface::IDownloadTaskInterface() : ServiceFramework{"IDownloadTa RegisterHandlers(functions); } +IDownloadTaskInterface::~IDownloadTaskInterface() = default; + IECommerceInterface::IECommerceInterface() : ServiceFramework{"IECommerceInterface"} { // clang-format off static const FunctionInfo functions[] = { @@ -458,6 +471,8 @@ IECommerceInterface::IECommerceInterface() : ServiceFramework{"IECommerceInterfa RegisterHandlers(functions); } +IECommerceInterface::~IECommerceInterface() = default; + IFactoryResetInterface::IFactoryResetInterface::IFactoryResetInterface() : ServiceFramework{"IFactoryResetInterface"} { // clang-format off @@ -471,6 +486,8 @@ IFactoryResetInterface::IFactoryResetInterface::IFactoryResetInterface() RegisterHandlers(functions); } +IFactoryResetInterface::~IFactoryResetInterface() = default; + NS::NS(const char* name) : ServiceFramework{name} { // clang-format off static const FunctionInfo functions[] = { @@ -488,7 +505,9 @@ NS::NS(const char* name) : ServiceFramework{name} { RegisterHandlers(functions); } -std::shared_ptr NS::GetApplicationManagerInterface() { +NS::~NS() = default; + +std::shared_ptr NS::GetApplicationManagerInterface() const { return GetInterface(); } diff --git a/src/core/hle/service/ns/ns.h b/src/core/hle/service/ns/ns.h index 155dd6831..0f4bab4cb 100644 --- a/src/core/hle/service/ns/ns.h +++ b/src/core/hle/service/ns/ns.h @@ -5,18 +5,19 @@ #pragma once #include "core/hle/service/service.h" -#include "core/hle/service/set/set.h" namespace Service::NS { class IAccountProxyInterface final : public ServiceFramework { public: explicit IAccountProxyInterface(); + ~IAccountProxyInterface(); }; class IApplicationManagerInterface final : public ServiceFramework { public: explicit IApplicationManagerInterface(); + ~IApplicationManagerInterface(); ResultVal GetApplicationDesiredLanguage(u32 supported_languages); ResultVal ConvertApplicationLanguageToLanguageCode(u8 application_language); @@ -30,38 +31,45 @@ private: class IApplicationVersionInterface final : public ServiceFramework { public: explicit IApplicationVersionInterface(); + ~IApplicationVersionInterface(); }; class IContentManagerInterface final : public ServiceFramework { public: explicit IContentManagerInterface(); + ~IContentManagerInterface(); }; class IDocumentInterface final : public ServiceFramework { public: explicit IDocumentInterface(); + ~IDocumentInterface(); }; class IDownloadTaskInterface final : public ServiceFramework { public: explicit IDownloadTaskInterface(); + ~IDownloadTaskInterface(); }; class IECommerceInterface final : public ServiceFramework { public: explicit IECommerceInterface(); + ~IECommerceInterface(); }; class IFactoryResetInterface final : public ServiceFramework { public: explicit IFactoryResetInterface(); + ~IFactoryResetInterface(); }; class NS final : public ServiceFramework { public: explicit NS(const char* name); + ~NS(); - std::shared_ptr GetApplicationManagerInterface(); + std::shared_ptr GetApplicationManagerInterface() const; private: template @@ -74,7 +82,7 @@ private: } template - std::shared_ptr GetInterface() { + std::shared_ptr GetInterface() const { static_assert(std::is_base_of_v, "Not a base of ServiceFrameworkBase"); diff --git a/src/core/hle/service/ns/ns_language.h b/src/core/hle/service/ns/ns_language.h index 55d7b0bd2..59ac85a19 100644 --- a/src/core/hle/service/ns/ns_language.h +++ b/src/core/hle/service/ns/ns_language.h @@ -1,4 +1,4 @@ -// Copyright 2018 yuzu emulator team +// Copyright 2019 yuzu emulator team // Licensed under GPLv2 or any later version // Refer to the license.txt file included. @@ -32,7 +32,7 @@ using ApplicationLanguagePriorityList = const std::array(ApplicationLanguage::Count)>; constexpr u32 GetSupportedLanguageFlag(const ApplicationLanguage lang) { - return 1u << static_cast(lang); + return 1U << static_cast(lang); } const ApplicationLanguagePriorityList* GetApplicationLanguagePriorityList(ApplicationLanguage lang);