diff --git a/libraries/libstratosphere/include/stratosphere/lr.hpp b/libraries/libstratosphere/include/stratosphere/lr.hpp index 51ea02934..18b439ebe 100644 --- a/libraries/libstratosphere/include/stratosphere/lr.hpp +++ b/libraries/libstratosphere/include/stratosphere/lr.hpp @@ -15,6 +15,14 @@ */ #pragma once -#include - -#include "lr/lr_types.hpp" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include diff --git a/stratosphere/ncm/source/lr_add_on_content_location_resolver.hpp b/libraries/libstratosphere/include/stratosphere/lr/lr_add_on_content_location_resolver.hpp similarity index 94% rename from stratosphere/ncm/source/lr_add_on_content_location_resolver.hpp rename to libraries/libstratosphere/include/stratosphere/lr/lr_add_on_content_location_resolver.hpp index 9af9bb910..3a05c2204 100644 --- a/stratosphere/ncm/source/lr_add_on_content_location_resolver.hpp +++ b/libraries/libstratosphere/include/stratosphere/lr/lr_add_on_content_location_resolver.hpp @@ -15,10 +15,8 @@ */ #pragma once -#include -#include - -#include "impl/lr_registered_data.hpp" +#include +#include namespace ams::lr { @@ -33,7 +31,7 @@ namespace ams::lr { UnregisterApplicationAddOnContent = 4, }; private: - impl::RegisteredStorages registered_storages; + RegisteredStorages registered_storages; public: AddOnContentLocationResolverInterface() : registered_storages(hos::GetVersion() < hos::Version_900 ? 0x800 : 0x2) { /* ... */ } diff --git a/stratosphere/ncm/source/lr_content_location_resolver.hpp b/libraries/libstratosphere/include/stratosphere/lr/lr_content_location_resolver.hpp similarity index 57% rename from stratosphere/ncm/source/lr_content_location_resolver.hpp rename to libraries/libstratosphere/include/stratosphere/lr/lr_content_location_resolver.hpp index 6f19cc85c..80266f7e5 100644 --- a/stratosphere/ncm/source/lr_content_location_resolver.hpp +++ b/libraries/libstratosphere/include/stratosphere/lr/lr_content_location_resolver.hpp @@ -15,12 +15,10 @@ */ #pragma once -#include -#include - -#include "lr_i_location_resolver_interface.hpp" -#include "ncm_i_content_meta_database.hpp" -#include "ncm_i_content_storage.hpp" +#include +#include +#include +#include namespace ams::lr { @@ -62,35 +60,6 @@ namespace ams::lr { virtual Result RedirectApplicationProgramPathForDebugDeprecated(const Path &path, ncm::ProgramId id) override; virtual Result RedirectApplicationProgramPathForDebug(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override; virtual Result EraseProgramRedirectionForDebug(ncm::ProgramId id) override; - public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(ResolveProgramPath), - MAKE_SERVICE_COMMAND_META(RedirectProgramPath), - MAKE_SERVICE_COMMAND_META(ResolveApplicationControlPath), - MAKE_SERVICE_COMMAND_META(ResolveApplicationHtmlDocumentPath), - MAKE_SERVICE_COMMAND_META(ResolveDataPath), - MAKE_SERVICE_COMMAND_META(RedirectApplicationControlPathDeprecated, hos::Version_100, hos::Version_810), - MAKE_SERVICE_COMMAND_META(RedirectApplicationControlPath, hos::Version_900), - MAKE_SERVICE_COMMAND_META(RedirectApplicationHtmlDocumentPathDeprecated, hos::Version_100, hos::Version_810), - MAKE_SERVICE_COMMAND_META(RedirectApplicationHtmlDocumentPath, hos::Version_900), - MAKE_SERVICE_COMMAND_META(ResolveApplicationLegalInformationPath), - MAKE_SERVICE_COMMAND_META(RedirectApplicationLegalInformationPathDeprecated, hos::Version_100, hos::Version_810), - MAKE_SERVICE_COMMAND_META(RedirectApplicationLegalInformationPath, hos::Version_900), - MAKE_SERVICE_COMMAND_META(Refresh), - MAKE_SERVICE_COMMAND_META(RedirectApplicationProgramPathDeprecated, hos::Version_500, hos::Version_810), - MAKE_SERVICE_COMMAND_META(RedirectApplicationProgramPath, hos::Version_900), - MAKE_SERVICE_COMMAND_META(ClearApplicationRedirectionDeprecated, hos::Version_500, hos::Version_810), - MAKE_SERVICE_COMMAND_META(ClearApplicationRedirection, hos::Version_900), - MAKE_SERVICE_COMMAND_META(EraseProgramRedirection, hos::Version_500), - MAKE_SERVICE_COMMAND_META(EraseApplicationControlRedirection, hos::Version_500), - MAKE_SERVICE_COMMAND_META(EraseApplicationHtmlDocumentRedirection, hos::Version_500), - MAKE_SERVICE_COMMAND_META(EraseApplicationLegalInformationRedirection, hos::Version_500), - MAKE_SERVICE_COMMAND_META(ResolveProgramPathForDebug, hos::Version_700), - MAKE_SERVICE_COMMAND_META(RedirectProgramPathForDebug, hos::Version_700), - MAKE_SERVICE_COMMAND_META(RedirectApplicationProgramPathForDebugDeprecated, hos::Version_700, hos::Version_810), - MAKE_SERVICE_COMMAND_META(RedirectApplicationProgramPathForDebug, hos::Version_900), - MAKE_SERVICE_COMMAND_META(EraseProgramRedirectionForDebug, hos::Version_700), - }; }; } diff --git a/stratosphere/ncm/source/lr_i_location_resolver.hpp b/libraries/libstratosphere/include/stratosphere/lr/lr_i_location_resolver.hpp similarity index 90% rename from stratosphere/ncm/source/lr_i_location_resolver.hpp rename to libraries/libstratosphere/include/stratosphere/lr/lr_i_location_resolver.hpp index 437dbc43f..1b35ecfd5 100644 --- a/stratosphere/ncm/source/lr_i_location_resolver.hpp +++ b/libraries/libstratosphere/include/stratosphere/lr/lr_i_location_resolver.hpp @@ -15,10 +15,8 @@ */ #pragma once -#include -#include - -#include "impl/lr_redirection.hpp" +#include +#include namespace ams::lr { @@ -53,17 +51,13 @@ namespace ams::lr { EraseProgramRedirectionForDebug = 19, }; protected: - impl::LocationRedirector program_redirector; - impl::LocationRedirector debug_program_redirector; - impl::LocationRedirector app_control_redirector; - impl::LocationRedirector html_docs_redirector; - impl::LocationRedirector legal_info_redirector; + LocationRedirector program_redirector; + LocationRedirector debug_program_redirector; + LocationRedirector app_control_redirector; + LocationRedirector html_docs_redirector; + LocationRedirector legal_info_redirector; protected: - bool GetRedirectedPath(Path* out, impl::LocationRedirector* redirector, ncm::ProgramId id) { - return redirector->FindRedirection(out, id); - } - - void ClearRedirections(u32 flags = impl::RedirectionFlags_None) { + void ClearRedirections(u32 flags = RedirectionFlags_None) { this->program_redirector.ClearRedirections(flags); this->debug_program_redirector.ClearRedirections(flags); this->app_control_redirector.ClearRedirections(flags); diff --git a/stratosphere/ncm/source/lr_i_location_resolver_interface.hpp b/libraries/libstratosphere/include/stratosphere/lr/lr_i_location_resolver_interface.hpp similarity index 98% rename from stratosphere/ncm/source/lr_i_location_resolver_interface.hpp rename to libraries/libstratosphere/include/stratosphere/lr/lr_i_location_resolver_interface.hpp index cf8231f9a..16ed42c45 100644 --- a/stratosphere/ncm/source/lr_i_location_resolver_interface.hpp +++ b/libraries/libstratosphere/include/stratosphere/lr/lr_i_location_resolver_interface.hpp @@ -15,10 +15,8 @@ */ #pragma once -#include -#include - -#include "lr_i_location_resolver.hpp" +#include +#include namespace ams::lr { diff --git a/stratosphere/ncm/source/lr_i_location_resolver_manager.hpp b/libraries/libstratosphere/include/stratosphere/lr/lr_i_location_resolver_manager.hpp similarity index 87% rename from stratosphere/ncm/source/lr_i_location_resolver_manager.hpp rename to libraries/libstratosphere/include/stratosphere/lr/lr_i_location_resolver_manager.hpp index 549e42a3b..6d2088fde 100644 --- a/stratosphere/ncm/source/lr_i_location_resolver_manager.hpp +++ b/libraries/libstratosphere/include/stratosphere/lr/lr_i_location_resolver_manager.hpp @@ -15,12 +15,10 @@ */ #pragma once -#include -#include - -#include "lr_add_on_content_location_resolver.hpp" -#include "lr_i_location_resolver_interface.hpp" -#include "lr_registered_location_resolver.hpp" +#include +#include +#include +#include namespace ams::lr { diff --git a/stratosphere/ncm/source/impl/lr_redirection.hpp b/libraries/libstratosphere/include/stratosphere/lr/lr_location_redirector.hpp similarity index 96% rename from stratosphere/ncm/source/impl/lr_redirection.hpp rename to libraries/libstratosphere/include/stratosphere/lr/lr_location_redirector.hpp index 9cd397dc8..6187eb1a7 100644 --- a/stratosphere/ncm/source/impl/lr_redirection.hpp +++ b/libraries/libstratosphere/include/stratosphere/lr/lr_location_redirector.hpp @@ -15,10 +15,9 @@ */ #pragma once -#include -#include +#include -namespace ams::lr::impl { +namespace ams::lr { enum RedirectionFlags { RedirectionFlags_None = (0 << 0), @@ -38,7 +37,7 @@ namespace ams::lr::impl { LocationRedirector() { /* ... */ } ~LocationRedirector() { this->ClearRedirections(); } - bool FindRedirection(Path *out, ncm::ProgramId program_id); + bool FindRedirection(Path *out, ncm::ProgramId program_id) const; void SetRedirection(ncm::ProgramId program_id, const Path &path, u32 flags = RedirectionFlags_None); void SetRedirection(ncm::ProgramId program_id, ncm::ProgramId owner_id, const Path &path, u32 flags = RedirectionFlags_None); void SetRedirectionFlags(ncm::ProgramId program_id, u32 flags); diff --git a/stratosphere/ncm/source/impl/lr_location_resolver_manager_impl.hpp b/libraries/libstratosphere/include/stratosphere/lr/lr_location_resolver_manager_impl.hpp similarity index 82% rename from stratosphere/ncm/source/impl/lr_location_resolver_manager_impl.hpp rename to libraries/libstratosphere/include/stratosphere/lr/lr_location_resolver_manager_impl.hpp index e188400f8..5ddcb34e2 100644 --- a/stratosphere/ncm/source/impl/lr_location_resolver_manager_impl.hpp +++ b/libraries/libstratosphere/include/stratosphere/lr/lr_location_resolver_manager_impl.hpp @@ -15,20 +15,15 @@ */ #pragma once -#include -#include +#include +#include +#include -#include "../lr_add_on_content_location_resolver.hpp" -#include "../lr_i_location_resolver_interface.hpp" -#include "../lr_i_location_resolver_manager.hpp" -#include "../lr_registered_location_resolver.hpp" -#include "ncm_bounded_map.hpp" - -namespace ams::lr::impl { +namespace ams::lr { class LocationResolverManagerImpl final : public ILocationResolverManager { private: - ncm::impl::BoundedMap, 5> g_location_resolvers; + ncm::BoundedMap, 5> g_location_resolvers; std::shared_ptr g_registered_location_resolver = nullptr; std::shared_ptr g_add_on_content_location_resolver = nullptr; os::Mutex g_mutex; diff --git a/stratosphere/ncm/source/lr_redirect_only_location_resolver.hpp b/libraries/libstratosphere/include/stratosphere/lr/lr_redirect_only_location_resolver.hpp similarity index 55% rename from stratosphere/ncm/source/lr_redirect_only_location_resolver.hpp rename to libraries/libstratosphere/include/stratosphere/lr/lr_redirect_only_location_resolver.hpp index a4d298672..7dfb33c46 100644 --- a/stratosphere/ncm/source/lr_redirect_only_location_resolver.hpp +++ b/libraries/libstratosphere/include/stratosphere/lr/lr_redirect_only_location_resolver.hpp @@ -15,10 +15,8 @@ */ #pragma once -#include -#include - -#include "lr_content_location_resolver.hpp" +#include +#include namespace ams::lr { @@ -52,35 +50,6 @@ namespace ams::lr { virtual Result RedirectApplicationProgramPathForDebugDeprecated(const Path &path, ncm::ProgramId id) override; virtual Result RedirectApplicationProgramPathForDebug(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) override; virtual Result EraseProgramRedirectionForDebug(ncm::ProgramId id) override; - public: - DEFINE_SERVICE_DISPATCH_TABLE { - MAKE_SERVICE_COMMAND_META(ResolveProgramPath), - MAKE_SERVICE_COMMAND_META(RedirectProgramPath), - MAKE_SERVICE_COMMAND_META(ResolveApplicationControlPath), - MAKE_SERVICE_COMMAND_META(ResolveApplicationHtmlDocumentPath), - MAKE_SERVICE_COMMAND_META(ResolveDataPath), - MAKE_SERVICE_COMMAND_META(RedirectApplicationControlPathDeprecated, hos::Version_100, hos::Version_810), - MAKE_SERVICE_COMMAND_META(RedirectApplicationControlPath, hos::Version_900), - MAKE_SERVICE_COMMAND_META(RedirectApplicationHtmlDocumentPathDeprecated, hos::Version_100, hos::Version_810), - MAKE_SERVICE_COMMAND_META(RedirectApplicationHtmlDocumentPath, hos::Version_900), - MAKE_SERVICE_COMMAND_META(ResolveApplicationLegalInformationPath), - MAKE_SERVICE_COMMAND_META(RedirectApplicationLegalInformationPathDeprecated, hos::Version_100, hos::Version_810), - MAKE_SERVICE_COMMAND_META(RedirectApplicationLegalInformationPath, hos::Version_900), - MAKE_SERVICE_COMMAND_META(Refresh), - MAKE_SERVICE_COMMAND_META(RedirectApplicationProgramPathDeprecated, hos::Version_500, hos::Version_810), - MAKE_SERVICE_COMMAND_META(RedirectApplicationProgramPath, hos::Version_900), - MAKE_SERVICE_COMMAND_META(ClearApplicationRedirectionDeprecated, hos::Version_500, hos::Version_810), - MAKE_SERVICE_COMMAND_META(ClearApplicationRedirection, hos::Version_900), - MAKE_SERVICE_COMMAND_META(EraseProgramRedirection, hos::Version_500), - MAKE_SERVICE_COMMAND_META(EraseApplicationControlRedirection, hos::Version_500), - MAKE_SERVICE_COMMAND_META(EraseApplicationHtmlDocumentRedirection, hos::Version_500), - MAKE_SERVICE_COMMAND_META(EraseApplicationLegalInformationRedirection, hos::Version_500), - MAKE_SERVICE_COMMAND_META(ResolveProgramPathForDebug, hos::Version_700), - MAKE_SERVICE_COMMAND_META(RedirectProgramPathForDebug, hos::Version_700), - MAKE_SERVICE_COMMAND_META(RedirectApplicationProgramPathForDebugDeprecated, hos::Version_700, hos::Version_810), - MAKE_SERVICE_COMMAND_META(RedirectApplicationProgramPathForDebug, hos::Version_900), - MAKE_SERVICE_COMMAND_META(EraseProgramRedirectionForDebug, hos::Version_700), - }; }; } diff --git a/stratosphere/ncm/source/impl/lr_registered_data.hpp b/libraries/libstratosphere/include/stratosphere/lr/lr_registered_data.hpp similarity index 96% rename from stratosphere/ncm/source/impl/lr_registered_data.hpp rename to libraries/libstratosphere/include/stratosphere/lr/lr_registered_data.hpp index 75f4b4e98..644ffd4c4 100644 --- a/stratosphere/ncm/source/impl/lr_registered_data.hpp +++ b/libraries/libstratosphere/include/stratosphere/lr/lr_registered_data.hpp @@ -15,10 +15,9 @@ */ #pragma once -#include -#include +#include -namespace ams::lr::impl { +namespace ams::lr { template class RegisteredData { @@ -97,9 +96,9 @@ namespace ams::lr::impl { } } - bool Find(Value *out, const Key &key) { + bool Find(Value *out, const Key &key) const { for (size_t i = 0; i < this->GetCapacity(); i++) { - Entry& entry = this->entries[i]; + const Entry& entry = this->entries[i]; if (entry.is_valid && entry.key == key) { *out = entry.value; return true; diff --git a/stratosphere/ncm/source/lr_registered_location_resolver.hpp b/libraries/libstratosphere/include/stratosphere/lr/lr_registered_location_resolver.hpp similarity index 84% rename from stratosphere/ncm/source/lr_registered_location_resolver.hpp rename to libraries/libstratosphere/include/stratosphere/lr/lr_registered_location_resolver.hpp index 25b30299c..6332866d5 100644 --- a/stratosphere/ncm/source/lr_registered_location_resolver.hpp +++ b/libraries/libstratosphere/include/stratosphere/lr/lr_registered_location_resolver.hpp @@ -15,11 +15,9 @@ */ #pragma once -#include -#include - -#include "impl/lr_redirection.hpp" -#include "impl/lr_registered_data.hpp" +#include +#include +#include namespace ams::lr { @@ -44,14 +42,12 @@ namespace ams::lr { RefreshExcluding = 9, }; private: - impl::LocationRedirector program_redirector; - impl::RegisteredLocations registered_program_locations; - impl::LocationRedirector html_docs_redirector; - impl::RegisteredLocations registered_html_docs_locations; + LocationRedirector program_redirector; + RegisteredLocations registered_program_locations; + LocationRedirector html_docs_redirector; + RegisteredLocations registered_html_docs_locations; private: - void ClearRedirections(u32 flags = impl::RedirectionFlags_None); - void RegisterPath(const Path& path, impl::RegisteredLocations* locations, ncm::ProgramId id, ncm::ProgramId owner_id); - bool ResolvePath(Path* out, impl::LocationRedirector* redirector, impl::RegisteredLocations* locations, ncm::ProgramId id); + void ClearRedirections(u32 flags = RedirectionFlags_None); Result RefreshImpl(const ncm::ProgramId* excluding_ids, size_t num_ids); public: RegisteredLocationResolverInterface() : registered_program_locations(hos::GetVersion() < hos::Version_900 ? 0x10 : MaxRegisteredLocations), registered_html_docs_locations(hos::GetVersion() < hos::Version_900 ? 0x10 : MaxRegisteredLocations) { /* ... */ } diff --git a/libraries/libstratosphere/include/stratosphere/lr/lr_types.hpp b/libraries/libstratosphere/include/stratosphere/lr/lr_types.hpp index 5062a39c8..894bb538c 100644 --- a/libraries/libstratosphere/include/stratosphere/lr/lr_types.hpp +++ b/libraries/libstratosphere/include/stratosphere/lr/lr_types.hpp @@ -16,8 +16,9 @@ #pragma once #include -#include "../fs/fs_directory.hpp" -#include "../sf/sf_buffer_tags.hpp" +#include +#include +#include namespace ams::lr { @@ -48,7 +49,7 @@ namespace ams::lr { if (this->str[i] == '\x00') { return true; } - } + } return false; } }; diff --git a/stratosphere/ncm/source/impl/ncm_bounded_map.hpp b/libraries/libstratosphere/include/stratosphere/ncm/ncm_bounded_map.hpp similarity index 96% rename from stratosphere/ncm/source/impl/ncm_bounded_map.hpp rename to libraries/libstratosphere/include/stratosphere/ncm/ncm_bounded_map.hpp index 3f508b4a5..357c7e26f 100644 --- a/stratosphere/ncm/source/impl/ncm_bounded_map.hpp +++ b/libraries/libstratosphere/include/stratosphere/ncm/ncm_bounded_map.hpp @@ -13,13 +13,12 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - #pragma once -#include -#include +#include +#include + +namespace ams::ncm { -namespace ams::ncm::impl { - template class BoundedMap { private: diff --git a/stratosphere/ncm/source/ncm_i_content_meta_database.hpp b/libraries/libstratosphere/include/stratosphere/ncm/ncm_i_content_meta_database.hpp similarity index 98% rename from stratosphere/ncm/source/ncm_i_content_meta_database.hpp rename to libraries/libstratosphere/include/stratosphere/ncm/ncm_i_content_meta_database.hpp index 3b352c9f1..27fd44be2 100644 --- a/stratosphere/ncm/source/ncm_i_content_meta_database.hpp +++ b/libraries/libstratosphere/include/stratosphere/ncm/ncm_i_content_meta_database.hpp @@ -15,8 +15,7 @@ */ #pragma once -#include -#include +#include #include namespace ams::ncm { @@ -56,12 +55,12 @@ namespace ams::ncm { return ResultSuccess(); } public: - IContentMetaDatabase(ams::kvdb::MemoryKeyValueStore* kvs) : + IContentMetaDatabase(ams::kvdb::MemoryKeyValueStore* kvs) : kvs(kvs), disabled(false) { } - IContentMetaDatabase(ams::kvdb::MemoryKeyValueStore* kvs, const char* mount_name) : + IContentMetaDatabase(ams::kvdb::MemoryKeyValueStore* kvs, const char* mount_name) : IContentMetaDatabase(kvs) { strcpy(this->mount_name, mount_name); diff --git a/stratosphere/ncm/source/ncm_i_content_storage.hpp b/libraries/libstratosphere/include/stratosphere/ncm/ncm_i_content_storage.hpp similarity index 99% rename from stratosphere/ncm/source/ncm_i_content_storage.hpp rename to libraries/libstratosphere/include/stratosphere/ncm/ncm_i_content_storage.hpp index 8f60425f9..f0b282572 100644 --- a/stratosphere/ncm/source/ncm_i_content_storage.hpp +++ b/libraries/libstratosphere/include/stratosphere/ncm/ncm_i_content_storage.hpp @@ -15,11 +15,10 @@ */ #pragma once -#include -#include +#include namespace ams::ncm { - + class IContentStorage : public sf::IServiceObject { protected: enum class CommandId { diff --git a/stratosphere/ncm/source/lr_add_on_content_location_resolver.cpp b/libraries/libstratosphere/source/lr/lr_add_on_content_location_resolver.cpp similarity index 89% rename from stratosphere/ncm/source/lr_add_on_content_location_resolver.cpp rename to libraries/libstratosphere/source/lr/lr_add_on_content_location_resolver.cpp index 15368cb00..8324c983f 100644 --- a/stratosphere/ncm/source/lr_add_on_content_location_resolver.cpp +++ b/libraries/libstratosphere/source/lr/lr_add_on_content_location_resolver.cpp @@ -13,9 +13,15 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ +#include -#include "impl/ncm_content_manager.hpp" -#include "lr_add_on_content_location_resolver.hpp" +/* TODO: Properly integrate NCM api into libstratosphere to avoid linker hack. */ +namespace ams::ncm::impl { + + Result OpenContentMetaDatabase(std::shared_ptr *, ncm::StorageId); + Result OpenContentStorage(std::shared_ptr *, ncm::StorageId); + +} namespace ams::lr { @@ -31,7 +37,7 @@ namespace ams::lr { std::shared_ptr content_storage; R_TRY(ncm::impl::OpenContentStorage(&content_storage, storage_id)); R_ABORT_UNLESS(content_storage->GetPath(out.GetPointer(), data_content_id)); - + return ResultSuccess(); } diff --git a/stratosphere/ncm/source/lr_content_location_resolver.cpp b/libraries/libstratosphere/source/lr/lr_content_location_resolver.cpp similarity index 82% rename from stratosphere/ncm/source/lr_content_location_resolver.cpp rename to libraries/libstratosphere/source/lr/lr_content_location_resolver.cpp index e71967788..bb1c0bcc8 100644 --- a/stratosphere/ncm/source/lr_content_location_resolver.cpp +++ b/libraries/libstratosphere/source/lr/lr_content_location_resolver.cpp @@ -13,9 +13,15 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ +#include -#include "impl/ncm_content_manager.hpp" -#include "lr_content_location_resolver.hpp" +/* TODO: Properly integrate NCM api into libstratosphere to avoid linker hack. */ +namespace ams::ncm::impl { + + Result OpenContentMetaDatabase(std::shared_ptr *, ncm::StorageId); + Result OpenContentStorage(std::shared_ptr *, ncm::StorageId); + +} namespace ams::lr { @@ -28,13 +34,13 @@ namespace ams::lr { } Result ContentLocationResolverInterface::ResolveProgramPath(sf::Out out, ncm::ProgramId id) { - R_UNLESS(!this->GetRedirectedPath(out.GetPointer(), &this->program_redirector, id), ResultSuccess()); + R_UNLESS(!this->program_redirector.FindRedirection(out.GetPointer(), id), ResultSuccess()); ncm::ContentId program_content_id; R_TRY_CATCH(this->content_meta_database->GetLatestProgram(&program_content_id, id)) { R_CONVERT(ncm::ResultContentMetaNotFound, lr::ResultProgramNotFound()) } R_END_TRY_CATCH; - + this->GetContentStoragePath(out.GetPointer(), program_content_id); return ResultSuccess(); } @@ -45,12 +51,12 @@ namespace ams::lr { } Result ContentLocationResolverInterface::ResolveApplicationControlPath(sf::Out out, ncm::ProgramId id) { - R_UNLESS(this->GetRedirectedPath(out.GetPointer(), &this->app_control_redirector, id), lr::ResultControlNotFound()); + R_UNLESS(this->app_control_redirector.FindRedirection(out.GetPointer(), id), lr::ResultControlNotFound()); return ResultSuccess(); } Result ContentLocationResolverInterface::ResolveApplicationHtmlDocumentPath(sf::Out out, ncm::ProgramId id) { - R_UNLESS(this->GetRedirectedPath(out.GetPointer(), &this->html_docs_redirector, id), lr::ResultHtmlDocumentNotFound()); + R_UNLESS(this->html_docs_redirector.FindRedirection(out.GetPointer(), id), lr::ResultHtmlDocumentNotFound()); return ResultSuccess(); } @@ -63,37 +69,37 @@ namespace ams::lr { } Result ContentLocationResolverInterface::RedirectApplicationControlPathDeprecated(const Path &path, ncm::ProgramId id) { - this->app_control_redirector.SetRedirection(id, path, impl::RedirectionFlags_Application); + this->app_control_redirector.SetRedirection(id, path, RedirectionFlags_Application); return ResultSuccess(); } Result ContentLocationResolverInterface::RedirectApplicationControlPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) { - this->app_control_redirector.SetRedirection(id, owner_id, path, impl::RedirectionFlags_Application); + this->app_control_redirector.SetRedirection(id, owner_id, path, RedirectionFlags_Application); return ResultSuccess(); } Result ContentLocationResolverInterface::RedirectApplicationHtmlDocumentPathDeprecated(const Path &path, ncm::ProgramId id) { - this->html_docs_redirector.SetRedirection(id, path, impl::RedirectionFlags_Application); + this->html_docs_redirector.SetRedirection(id, path, RedirectionFlags_Application); return ResultSuccess(); } Result ContentLocationResolverInterface::RedirectApplicationHtmlDocumentPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) { - this->html_docs_redirector.SetRedirection(id, owner_id, path, impl::RedirectionFlags_Application); + this->html_docs_redirector.SetRedirection(id, owner_id, path, RedirectionFlags_Application); return ResultSuccess(); } Result ContentLocationResolverInterface::ResolveApplicationLegalInformationPath(sf::Out out, ncm::ProgramId id) { - R_UNLESS(this->GetRedirectedPath(out.GetPointer(), &this->legal_info_redirector, id), lr::ResultLegalInformationNotFound()); + R_UNLESS(this->legal_info_redirector.FindRedirection(out.GetPointer(), id), lr::ResultLegalInformationNotFound()); return ResultSuccess(); } Result ContentLocationResolverInterface::RedirectApplicationLegalInformationPathDeprecated(const Path &path, ncm::ProgramId id) { - this->legal_info_redirector.SetRedirection(id, path, impl::RedirectionFlags_Application); + this->legal_info_redirector.SetRedirection(id, path, RedirectionFlags_Application); return ResultSuccess(); } Result ContentLocationResolverInterface::RedirectApplicationLegalInformationPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) { - this->legal_info_redirector.SetRedirection(id, owner_id, path, impl::RedirectionFlags_Application); + this->legal_info_redirector.SetRedirection(id, owner_id, path, RedirectionFlags_Application); return ResultSuccess(); } @@ -110,17 +116,17 @@ namespace ams::lr { } Result ContentLocationResolverInterface::RedirectApplicationProgramPathDeprecated(const Path &path, ncm::ProgramId id) { - this->program_redirector.SetRedirection(id, path, impl::RedirectionFlags_Application); + this->program_redirector.SetRedirection(id, path, RedirectionFlags_Application); return ResultSuccess(); } Result ContentLocationResolverInterface::RedirectApplicationProgramPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) { - this->program_redirector.SetRedirection(id, owner_id, path, impl::RedirectionFlags_Application); + this->program_redirector.SetRedirection(id, owner_id, path, RedirectionFlags_Application); return ResultSuccess(); } Result ContentLocationResolverInterface::ClearApplicationRedirectionDeprecated() { - this->ClearRedirections(impl::RedirectionFlags_Application); + this->ClearRedirections(RedirectionFlags_Application); return ResultSuccess(); } @@ -150,12 +156,12 @@ namespace ams::lr { } Result ContentLocationResolverInterface::ResolveProgramPathForDebug(sf::Out out, ncm::ProgramId id) { - R_UNLESS(!this->GetRedirectedPath(out.GetPointer(), &this->debug_program_redirector, id), ResultSuccess()); + R_UNLESS(!this->debug_program_redirector.FindRedirection(out.GetPointer(), id), ResultSuccess()); R_TRY_CATCH(this->ResolveProgramPath(out.GetPointer(), id)) { R_CONVERT(ResultProgramNotFound, lr::ResultDebugProgramNotFound()) } R_END_TRY_CATCH; - + return ResultSuccess(); } @@ -165,12 +171,12 @@ namespace ams::lr { } Result ContentLocationResolverInterface::RedirectApplicationProgramPathForDebugDeprecated(const Path &path, ncm::ProgramId id) { - this->debug_program_redirector.SetRedirection(id, path, impl::RedirectionFlags_Application); + this->debug_program_redirector.SetRedirection(id, path, RedirectionFlags_Application); return ResultSuccess(); } Result ContentLocationResolverInterface::RedirectApplicationProgramPathForDebug(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) { - this->debug_program_redirector.SetRedirection(id, owner_id, path, impl::RedirectionFlags_Application); + this->debug_program_redirector.SetRedirection(id, owner_id, path, RedirectionFlags_Application); return ResultSuccess(); } diff --git a/stratosphere/ncm/source/impl/lr_redirection.cpp b/libraries/libstratosphere/source/lr/lr_location_redirector.cpp similarity index 98% rename from stratosphere/ncm/source/impl/lr_redirection.cpp rename to libraries/libstratosphere/source/lr/lr_location_redirector.cpp index 9b693fe00..272159cb2 100644 --- a/stratosphere/ncm/source/impl/lr_redirection.cpp +++ b/libraries/libstratosphere/source/lr/lr_location_redirector.cpp @@ -13,10 +13,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ +#include -#include "lr_redirection.hpp" - -namespace ams::lr::impl { +namespace ams::lr { class LocationRedirector::Redirection : public util::IntrusiveListBaseNode { NON_COPYABLE(Redirection); @@ -51,7 +50,7 @@ namespace ams::lr::impl { } }; - bool LocationRedirector::FindRedirection(Path *out, ncm::ProgramId program_id) { + bool LocationRedirector::FindRedirection(Path *out, ncm::ProgramId program_id) const { for (const auto &redirection : this->redirection_list) { if (redirection.GetProgramId() == program_id) { redirection.GetPath(out); diff --git a/stratosphere/ncm/source/impl/lr_location_resolver_manager_impl.cpp b/libraries/libstratosphere/source/lr/lr_location_resolver_manager_impl.cpp similarity index 94% rename from stratosphere/ncm/source/impl/lr_location_resolver_manager_impl.cpp rename to libraries/libstratosphere/source/lr/lr_location_resolver_manager_impl.cpp index cbc70d823..ec201e2d2 100644 --- a/stratosphere/ncm/source/impl/lr_location_resolver_manager_impl.cpp +++ b/libraries/libstratosphere/source/lr/lr_location_resolver_manager_impl.cpp @@ -13,12 +13,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ +#include -#include "../lr_content_location_resolver.hpp" -#include "../lr_redirect_only_location_resolver.hpp" -#include "lr_location_resolver_manager_impl.hpp" - -namespace ams::lr::impl { +namespace ams::lr { Result LocationResolverManagerImpl::OpenLocationResolver(sf::Out> out, ncm::StorageId storage_id) { std::scoped_lock lk(g_mutex); @@ -51,7 +48,7 @@ namespace ams::lr::impl { out.SetValue(std::move(new_intf)); return ResultSuccess(); } - + Result LocationResolverManagerImpl::RefreshLocationResolver(ncm::StorageId storage_id) { std::scoped_lock lk(g_mutex); auto resolver = g_location_resolvers.Find(storage_id); @@ -71,7 +68,7 @@ namespace ams::lr::impl { if (!g_add_on_content_location_resolver) { g_add_on_content_location_resolver = std::make_shared(); } - + std::shared_ptr new_intf = g_add_on_content_location_resolver; out.SetValue(std::move(new_intf)); return ResultSuccess(); diff --git a/stratosphere/ncm/source/lr_redirect_only_location_resolver.cpp b/libraries/libstratosphere/source/lr/lr_redirect_only_location_resolver.cpp similarity index 81% rename from stratosphere/ncm/source/lr_redirect_only_location_resolver.cpp rename to libraries/libstratosphere/source/lr/lr_redirect_only_location_resolver.cpp index 958d292ba..aeb31ae8a 100644 --- a/stratosphere/ncm/source/lr_redirect_only_location_resolver.cpp +++ b/libraries/libstratosphere/source/lr/lr_redirect_only_location_resolver.cpp @@ -13,9 +13,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - -#include "impl/ncm_content_manager.hpp" -#include "lr_redirect_only_location_resolver.hpp" +#include namespace ams::lr { @@ -24,7 +22,7 @@ namespace ams::lr { } Result RedirectOnlyLocationResolverInterface::ResolveProgramPath(sf::Out out, ncm::ProgramId id) { - R_UNLESS(this->GetRedirectedPath(out.GetPointer(), &this->program_redirector, id), lr::ResultProgramNotFound()); + R_UNLESS(this->program_redirector.FindRedirection(out.GetPointer(), id), lr::ResultProgramNotFound()); return ResultSuccess(); } @@ -34,12 +32,12 @@ namespace ams::lr { } Result RedirectOnlyLocationResolverInterface::ResolveApplicationControlPath(sf::Out out, ncm::ProgramId id) { - R_UNLESS(this->GetRedirectedPath(out.GetPointer(), &this->app_control_redirector, id), lr::ResultControlNotFound()); + R_UNLESS(this->app_control_redirector.FindRedirection(out.GetPointer(), id), lr::ResultControlNotFound()); return ResultSuccess(); } Result RedirectOnlyLocationResolverInterface::ResolveApplicationHtmlDocumentPath(sf::Out out, ncm::ProgramId id) { - R_UNLESS(this->GetRedirectedPath(out.GetPointer(), &this->html_docs_redirector, id), lr::ResultHtmlDocumentNotFound()); + R_UNLESS(this->html_docs_redirector.FindRedirection(out.GetPointer(), id), lr::ResultHtmlDocumentNotFound()); return ResultSuccess(); } @@ -48,37 +46,37 @@ namespace ams::lr { } Result RedirectOnlyLocationResolverInterface::RedirectApplicationControlPathDeprecated(const Path &path, ncm::ProgramId id) { - this->app_control_redirector.SetRedirection(id, path, impl::RedirectionFlags_Application); + this->app_control_redirector.SetRedirection(id, path, RedirectionFlags_Application); return ResultSuccess(); } Result RedirectOnlyLocationResolverInterface::RedirectApplicationControlPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) { - this->app_control_redirector.SetRedirection(id, owner_id, path, impl::RedirectionFlags_Application); + this->app_control_redirector.SetRedirection(id, owner_id, path, RedirectionFlags_Application); return ResultSuccess(); } Result RedirectOnlyLocationResolverInterface::RedirectApplicationHtmlDocumentPathDeprecated(const Path &path, ncm::ProgramId id) { - this->html_docs_redirector.SetRedirection(id, path, impl::RedirectionFlags_Application); + this->html_docs_redirector.SetRedirection(id, path, RedirectionFlags_Application); return ResultSuccess(); } Result RedirectOnlyLocationResolverInterface::RedirectApplicationHtmlDocumentPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) { - this->html_docs_redirector.SetRedirection(id, owner_id, path, impl::RedirectionFlags_Application); + this->html_docs_redirector.SetRedirection(id, owner_id, path, RedirectionFlags_Application); return ResultSuccess(); } Result RedirectOnlyLocationResolverInterface::ResolveApplicationLegalInformationPath(sf::Out out, ncm::ProgramId id) { - R_UNLESS(this->GetRedirectedPath(out.GetPointer(), &this->legal_info_redirector, id), lr::ResultLegalInformationNotFound()); + R_UNLESS(this->legal_info_redirector.FindRedirection(out.GetPointer(), id), lr::ResultLegalInformationNotFound()); return ResultSuccess(); } Result RedirectOnlyLocationResolverInterface::RedirectApplicationLegalInformationPathDeprecated(const Path &path, ncm::ProgramId id) { - this->legal_info_redirector.SetRedirection(id, path, impl::RedirectionFlags_Application); + this->legal_info_redirector.SetRedirection(id, path, RedirectionFlags_Application); return ResultSuccess(); } Result RedirectOnlyLocationResolverInterface::RedirectApplicationLegalInformationPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) { - this->legal_info_redirector.SetRedirection(id, owner_id, path, impl::RedirectionFlags_Application); + this->legal_info_redirector.SetRedirection(id, owner_id, path, RedirectionFlags_Application); return ResultSuccess(); } @@ -88,17 +86,17 @@ namespace ams::lr { } Result RedirectOnlyLocationResolverInterface::RedirectApplicationProgramPathDeprecated(const Path &path, ncm::ProgramId id) { - this->program_redirector.SetRedirection(id, path, impl::RedirectionFlags_Application); + this->program_redirector.SetRedirection(id, path, RedirectionFlags_Application); return ResultSuccess(); } Result RedirectOnlyLocationResolverInterface::RedirectApplicationProgramPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) { - this->program_redirector.SetRedirection(id, owner_id, path, impl::RedirectionFlags_Application); + this->program_redirector.SetRedirection(id, owner_id, path, RedirectionFlags_Application); return ResultSuccess(); } Result RedirectOnlyLocationResolverInterface::ClearApplicationRedirectionDeprecated() { - this->ClearRedirections(impl::RedirectionFlags_Application); + this->ClearRedirections(RedirectionFlags_Application); return ResultSuccess(); } @@ -128,12 +126,12 @@ namespace ams::lr { } Result RedirectOnlyLocationResolverInterface::ResolveProgramPathForDebug(sf::Out out, ncm::ProgramId id) { - R_UNLESS(!this->GetRedirectedPath(out.GetPointer(), &this->debug_program_redirector, id), ResultSuccess()); + R_UNLESS(!this->debug_program_redirector.FindRedirection(out.GetPointer(), id), ResultSuccess()); R_TRY_CATCH(this->ResolveProgramPath(out.GetPointer(), id)) { R_CONVERT(ResultProgramNotFound, lr::ResultDebugProgramNotFound()) } R_END_TRY_CATCH; - + return ResultSuccess(); } @@ -143,12 +141,12 @@ namespace ams::lr { } Result RedirectOnlyLocationResolverInterface::RedirectApplicationProgramPathForDebugDeprecated(const Path &path, ncm::ProgramId id) { - this->debug_program_redirector.SetRedirection(id, path, impl::RedirectionFlags_Application); + this->debug_program_redirector.SetRedirection(id, path, RedirectionFlags_Application); return ResultSuccess(); } Result RedirectOnlyLocationResolverInterface::RedirectApplicationProgramPathForDebug(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) { - this->debug_program_redirector.SetRedirection(id, owner_id, path, impl::RedirectionFlags_Application); + this->debug_program_redirector.SetRedirection(id, owner_id, path, RedirectionFlags_Application); return ResultSuccess(); } diff --git a/stratosphere/ncm/source/lr_registered_location_resolver.cpp b/libraries/libstratosphere/source/lr/lr_registered_location_resolver.cpp similarity index 75% rename from stratosphere/ncm/source/lr_registered_location_resolver.cpp rename to libraries/libstratosphere/source/lr/lr_registered_location_resolver.cpp index 1b956354a..6f48f24d8 100644 --- a/stratosphere/ncm/source/lr_registered_location_resolver.cpp +++ b/libraries/libstratosphere/source/lr/lr_registered_location_resolver.cpp @@ -13,11 +13,36 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - -#include "lr_registered_location_resolver.hpp" +#include namespace ams::lr { + namespace { + + template + bool ResolvePath(Path *out, const LocationRedirector &redirector, const RegisteredLocations &locations, ncm::ProgramId id) { + if (!redirector.FindRedirection(out, id)) { + if (!locations.Find(out, id)) { + return false; + } + } + return true; + } + + template + void RegisterPath(RegisteredLocations &locations, ncm::ProgramId id, const Path& path, ncm::ProgramId owner_id) { + /* If we register successfully, we're good. */ + if (locations.Register(id, path, owner_id)) { + return; + } + + /* Otherwise, clear and register (this should always succeed). */ + locations.Clear(); + locations.Register(id, path, owner_id); + } + + } + RegisteredLocationResolverInterface::~RegisteredLocationResolverInterface() { /* Ensure entries are deallocated */ this->ClearRedirections(); @@ -28,22 +53,6 @@ namespace ams::lr { this->program_redirector.ClearRedirections(flags); } - void RegisteredLocationResolverInterface::RegisterPath(const Path& path, impl::RegisteredLocations* locations, ncm::ProgramId id, ncm::ProgramId owner_id) { - if (!locations->Register(id, path, owner_id)) { - locations->Clear(); - locations->Register(id, path, owner_id); - } - } - - bool RegisteredLocationResolverInterface::ResolvePath(Path* out, impl::LocationRedirector* redirector, impl::RegisteredLocations* locations, ncm::ProgramId id) { - if (!redirector->FindRedirection(out, id)) { - if (!locations->Find(out, id)) { - return false; - } - } - return true; - } - Result RegisteredLocationResolverInterface::RefreshImpl(const ncm::ProgramId* excluding_ids, size_t num_ids) { /* On < 9.0.0, exclusion lists were not supported yet, so simply clear and return. */ if (hos::GetVersion() < hos::Version_900) { @@ -59,7 +68,7 @@ namespace ams::lr { /* If we don't, just perform a general clear (as pre 9.0.0 did). */ this->ClearRedirections(); } - + /* Clear redirectors using exclusion lists. */ this->program_redirector.ClearRedirections(excluding_ids, num_ids); this->html_docs_redirector.ClearRedirections(excluding_ids, num_ids); @@ -67,17 +76,17 @@ namespace ams::lr { } Result RegisteredLocationResolverInterface::ResolveProgramPath(sf::Out out, ncm::ProgramId id) { - R_UNLESS(this->ResolvePath(out.GetPointer(), &this->program_redirector, &this->registered_program_locations, id), lr::ResultProgramNotFound()); + R_UNLESS(ResolvePath(out.GetPointer(), this->program_redirector, this->registered_program_locations, id), lr::ResultProgramNotFound()); return ResultSuccess(); } Result RegisteredLocationResolverInterface::RegisterProgramPathDeprecated(const Path &path, ncm::ProgramId id) { - this->RegisterPath(path, &this->registered_program_locations, id, ncm::ProgramId::Invalid); + RegisterPath(this->registered_program_locations, id, path, ncm::ProgramId::Invalid); return ResultSuccess(); } Result RegisteredLocationResolverInterface::RegisterProgramPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) { - this->RegisterPath(path, &this->registered_program_locations, id, owner_id); + RegisterPath(this->registered_program_locations, id, path, owner_id); return ResultSuccess(); } @@ -97,17 +106,17 @@ namespace ams::lr { } Result RegisteredLocationResolverInterface::ResolveHtmlDocumentPath(sf::Out out, ncm::ProgramId id) { - R_UNLESS(this->ResolvePath(out.GetPointer(), &this->html_docs_redirector, &this->registered_html_docs_locations, id), lr::ResultHtmlDocumentNotFound()); + R_UNLESS(ResolvePath(out.GetPointer(), this->html_docs_redirector, this->registered_html_docs_locations, id), lr::ResultHtmlDocumentNotFound()); return ResultSuccess(); } Result RegisteredLocationResolverInterface::RegisterHtmlDocumentPathDeprecated(const Path &path, ncm::ProgramId id) { - this->RegisterPath(path, &this->registered_html_docs_locations, id, ncm::ProgramId::Invalid); + RegisterPath(this->registered_html_docs_locations, id, path, ncm::ProgramId::Invalid); return ResultSuccess(); } Result RegisteredLocationResolverInterface::RegisterHtmlDocumentPath(const Path &path, ncm::ProgramId id, ncm::ProgramId owner_id) { - this->RegisterPath(path, &this->registered_html_docs_locations, id, owner_id); + RegisterPath(this->registered_html_docs_locations, id, path, owner_id); return ResultSuccess(); } diff --git a/stratosphere/ncm/source/impl/ncm_content_manager.hpp b/stratosphere/ncm/source/impl/ncm_content_manager.hpp index bf2598c51..844a0d58f 100644 --- a/stratosphere/ncm/source/impl/ncm_content_manager.hpp +++ b/stratosphere/ncm/source/impl/ncm_content_manager.hpp @@ -18,9 +18,6 @@ #include #include -#include "../ncm_i_content_meta_database.hpp" -#include "../ncm_i_content_storage.hpp" - namespace ams::ncm::impl { /* Initialization/Finalization. */ diff --git a/stratosphere/ncm/source/ncm_content_manager_service.hpp b/stratosphere/ncm/source/ncm_content_manager_service.hpp index 6cf09f573..1184b8c6f 100644 --- a/stratosphere/ncm/source/ncm_content_manager_service.hpp +++ b/stratosphere/ncm/source/ncm_content_manager_service.hpp @@ -18,9 +18,6 @@ #include #include -#include "ncm_i_content_meta_database.hpp" -#include "ncm_i_content_storage.hpp" - namespace ams::ncm { class ContentManagerService final : public sf::IServiceObject { diff --git a/stratosphere/ncm/source/ncm_content_meta_database.hpp b/stratosphere/ncm/source/ncm_content_meta_database.hpp index b8651ea00..5f2b575b8 100644 --- a/stratosphere/ncm/source/ncm_content_meta_database.hpp +++ b/stratosphere/ncm/source/ncm_content_meta_database.hpp @@ -18,8 +18,6 @@ #include #include -#include "ncm_i_content_meta_database.hpp" - namespace ams::ncm { class ContentMetaDatabaseInterface : public IContentMetaDatabase { @@ -53,7 +51,7 @@ namespace ams::ncm { virtual Result GetAttributes(sf::Out out_attributes, ContentMetaKey key) override; virtual Result GetRequiredApplicationVersion(sf::Out out_version, ContentMetaKey key) override; virtual Result GetContentIdByTypeAndIdOffset(sf::Out out_content_id, ContentMetaKey key, ContentType type, u8 id_offset) override; - + /* APIs. */ virtual Result GetLatestProgram(ContentId* out_content_id, ProgramId program_id) override; virtual Result GetLatestData(ContentId* out_content_id, ProgramId program_id) override; diff --git a/stratosphere/ncm/source/ncm_content_storage.hpp b/stratosphere/ncm/source/ncm_content_storage.hpp index efdd5857e..fa7b9b140 100644 --- a/stratosphere/ncm/source/ncm_content_storage.hpp +++ b/stratosphere/ncm/source/ncm_content_storage.hpp @@ -20,7 +20,6 @@ #include "impl/ncm_placeholder_accessor.hpp" #include "impl/ncm_rights_cache.hpp" -#include "ncm_i_content_storage.hpp" #include "ncm_path_utils.hpp" namespace ams::ncm { diff --git a/stratosphere/ncm/source/ncm_main.cpp b/stratosphere/ncm/source/ncm_main.cpp index 0235c39ec..f9d20a807 100644 --- a/stratosphere/ncm/source/ncm_main.cpp +++ b/stratosphere/ncm/source/ncm_main.cpp @@ -17,7 +17,6 @@ #include #include "impl/ncm_content_manager.hpp" -#include "impl/lr_location_resolver_manager_impl.hpp" #include "ncm_content_manager_service.hpp" extern "C" { @@ -28,7 +27,7 @@ extern "C" { #define INNER_HEAP_SIZE 0x100000 size_t nx_inner_heap_size = INNER_HEAP_SIZE; char nx_inner_heap[INNER_HEAP_SIZE]; - + void __libnx_initheap(void); void __appInit(void); void __appExit(void); @@ -87,58 +86,97 @@ void __appExit(void) { namespace { - struct NcmServerOptions { + struct ContentManagerServerOptions { static constexpr size_t PointerBufferSize = 0x400; static constexpr size_t MaxDomains = 0; static constexpr size_t MaxDomainObjects = 0; }; - constexpr sm::ServiceName NcmServiceName = sm::ServiceName::Encode("ncm"); - constexpr size_t NcmMaxSessions = 16; - constexpr size_t NcmNumServers = 1; + constexpr inline size_t ContentManagerNumServers = 1; + constexpr inline size_t ContentManagerManagerSessions = 16; + constexpr inline size_t ContentManagerExtraSessions = 16; + constexpr inline size_t ContentManagerMaxSessions = ContentManagerManagerSessions + ContentManagerExtraSessions; - constexpr sm::ServiceName LrServiceName = sm::ServiceName::Encode("lr"); - constexpr size_t LrMaxSessions = 16; - constexpr size_t LrNumServers = 1; + constexpr inline sm::ServiceName ContentManagerServiceName = sm::ServiceName::Encode("ncm"); + + struct LocationResolverServerOptions { + static constexpr size_t PointerBufferSize = 0x400; + static constexpr size_t MaxDomains = 0; + static constexpr size_t MaxDomainObjects = 0; + }; + + constexpr inline size_t LocationResolverNumServers = 1; + constexpr inline size_t LocationResolverManagerSessions = 16; + constexpr inline size_t LocationResolverExtraSessions = 16; + constexpr inline size_t LocationResolverMaxSessions = LocationResolverManagerSessions + LocationResolverExtraSessions; + + constexpr inline sm::ServiceName LocationResolverServiceName = sm::ServiceName::Encode("lr"); + + class LocationResolverServerManager : public sf::hipc::ServerManager { + private: + static constexpr size_t ThreadStackSize = 0x4000; + static constexpr int ThreadPriority = 0x15; + + using ServiceType = lr::LocationResolverManagerImpl; + private: + os::StaticThread thread; + std::shared_ptr lr_manager; + private: + static void ThreadFunction(void *_this) { + reinterpret_cast(_this)->LoopProcess(); + } + public: + LocationResolverServerManager(ServiceType *m) + : thread(ThreadFunction, this, ThreadPriority), lr_manager(sf::ServiceObjectTraits::SharedPointerHelper::GetEmptyDeleteSharedPointer(m)) + { + /* ... */ + } + + ams::Result Initialize() { + return this->RegisterServer(LocationResolverServiceName, LocationResolverManagerSessions, this->lr_manager); + } + + ams::Result StartThreads() { + return this->thread.Start(); + } + + void Wait() { + this->thread.Join(); + } + }; + + sf::hipc::ServerManager g_ncm_server_manager; + + lr::LocationResolverManagerImpl g_lr_manager_service_object; + LocationResolverServerManager g_lr_server_manager(std::addressof(g_lr_manager_service_object)); - sf::hipc::ServerManager g_ncm_server_manager; - sf::hipc::ServerManager g_lr_server_manager; } void ContentManagerServerMain(void* arg) { /* Create services. */ - R_ABORT_UNLESS(g_ncm_server_manager.RegisterServer(NcmServiceName, NcmMaxSessions)); + R_ABORT_UNLESS(g_ncm_server_manager.RegisterServer(ContentManagerServiceName, ContentManagerManagerSessions)); /* Loop forever, servicing our services. */ g_ncm_server_manager.LoopProcess(); } -void LocationResolverServerMain(void* arg) { - /* Create services. */ - R_ABORT_UNLESS(g_lr_server_manager.RegisterServer(LrServiceName, LrMaxSessions)); - - /* Loop forever, servicing our services. */ - g_lr_server_manager.LoopProcess(); -} - int main(int argc, char **argv) { /* Initialize content manager implementation. */ R_ABORT_UNLESS(ams::ncm::impl::InitializeContentManager()); static os::Thread s_content_manager_thread; - static os::Thread s_location_resolver_thread; R_ABORT_UNLESS(s_content_manager_thread.Initialize(&ContentManagerServerMain, nullptr, 0x4000, 0x15)); R_ABORT_UNLESS(s_content_manager_thread.Start()); - R_ABORT_UNLESS(s_location_resolver_thread.Initialize(&LocationResolverServerMain, nullptr, 0x4000, 0x15)); - R_ABORT_UNLESS(s_location_resolver_thread.Start()); + R_ABORT_UNLESS(g_lr_server_manager.Initialize()); + R_ABORT_UNLESS(g_lr_server_manager.StartThreads()); s_content_manager_thread.Join(); - s_location_resolver_thread.Join(); + g_lr_server_manager.Wait(); ams::ncm::impl::FinalizeContentManager(); - + return 0; } diff --git a/stratosphere/ncm/source/ncm_read_only_content_storage.hpp b/stratosphere/ncm/source/ncm_read_only_content_storage.hpp index 83659c3fc..fee4b8cb6 100644 --- a/stratosphere/ncm/source/ncm_read_only_content_storage.hpp +++ b/stratosphere/ncm/source/ncm_read_only_content_storage.hpp @@ -18,8 +18,6 @@ #include #include -#include "ncm_i_content_storage.hpp" - namespace ams::ncm { class ReadOnlyContentStorageInterface : public IContentStorage {