lr: move into libstratosphere

This commit is contained in:
Michael Scire 2020-02-25 08:43:52 -08:00
parent 74b06bdb50
commit bdedab0aff
27 changed files with 225 additions and 262 deletions

View file

@ -15,6 +15,14 @@
*/
#pragma once
#include <switch.h>
#include "lr/lr_types.hpp"
#include <vapours.hpp>
#include <stratosphere/lr/lr_types.hpp>
#include <stratosphere/lr/lr_location_redirector.hpp>
#include <stratosphere/lr/lr_registered_data.hpp>
#include <stratosphere/lr/lr_i_location_resolver.hpp>
#include <stratosphere/lr/lr_i_location_resolver_interface.hpp>
#include <stratosphere/lr/lr_content_location_resolver.hpp>
#include <stratosphere/lr/lr_redirect_only_location_resolver.hpp>
#include <stratosphere/lr/lr_registered_location_resolver.hpp>
#include <stratosphere/lr/lr_i_location_resolver_manager.hpp>
#include <stratosphere/lr/lr_location_resolver_manager_impl.hpp>

View file

@ -15,10 +15,8 @@
*/
#pragma once
#include <switch.h>
#include <stratosphere.hpp>
#include "impl/lr_registered_data.hpp"
#include <stratosphere/lr/lr_types.hpp>
#include <stratosphere/lr/lr_registered_data.hpp>
namespace ams::lr {
@ -33,7 +31,7 @@ namespace ams::lr {
UnregisterApplicationAddOnContent = 4,
};
private:
impl::RegisteredStorages<ncm::ProgramId, 0x800> registered_storages;
RegisteredStorages<ncm::ProgramId, 0x800> registered_storages;
public:
AddOnContentLocationResolverInterface() : registered_storages(hos::GetVersion() < hos::Version_900 ? 0x800 : 0x2) { /* ... */ }

View file

@ -15,12 +15,10 @@
*/
#pragma once
#include <switch.h>
#include <stratosphere.hpp>
#include "lr_i_location_resolver_interface.hpp"
#include "ncm_i_content_meta_database.hpp"
#include "ncm_i_content_storage.hpp"
#include <stratosphere/lr/lr_types.hpp>
#include <stratosphere/lr/lr_i_location_resolver_interface.hpp>
#include <stratosphere/ncm/ncm_i_content_meta_database.hpp>
#include <stratosphere/ncm/ncm_i_content_storage.hpp>
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),
};
};
}

View file

@ -15,10 +15,8 @@
*/
#pragma once
#include <switch.h>
#include <stratosphere.hpp>
#include "impl/lr_redirection.hpp"
#include <stratosphere/lr/lr_types.hpp>
#include <stratosphere/lr/lr_location_redirector.hpp>
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);

View file

@ -15,10 +15,8 @@
*/
#pragma once
#include <switch.h>
#include <stratosphere.hpp>
#include "lr_i_location_resolver.hpp"
#include <stratosphere/lr/lr_types.hpp>
#include <stratosphere/lr/lr_i_location_resolver.hpp>
namespace ams::lr {

View file

@ -15,12 +15,10 @@
*/
#pragma once
#include <switch.h>
#include <stratosphere.hpp>
#include "lr_add_on_content_location_resolver.hpp"
#include "lr_i_location_resolver_interface.hpp"
#include "lr_registered_location_resolver.hpp"
#include <stratosphere/lr/lr_types.hpp>
#include <stratosphere/lr/lr_i_location_resolver_interface.hpp>
#include <stratosphere/lr/lr_add_on_content_location_resolver.hpp>
#include <stratosphere/lr/lr_registered_location_resolver.hpp>
namespace ams::lr {

View file

@ -15,10 +15,9 @@
*/
#pragma once
#include <switch.h>
#include <stratosphere.hpp>
#include <stratosphere/lr/lr_types.hpp>
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);

View file

@ -15,20 +15,15 @@
*/
#pragma once
#include <switch.h>
#include <stratosphere.hpp>
#include <stratosphere/lr/lr_types.hpp>
#include <stratosphere/lr/lr_i_location_resolver_manager.hpp>
#include <stratosphere/ncm/ncm_bounded_map.hpp>
#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<ncm::StorageId, std::shared_ptr<ILocationResolverInterface>, 5> g_location_resolvers;
ncm::BoundedMap<ncm::StorageId, std::shared_ptr<ILocationResolverInterface>, 5> g_location_resolvers;
std::shared_ptr<RegisteredLocationResolverInterface> g_registered_location_resolver = nullptr;
std::shared_ptr<AddOnContentLocationResolverInterface> g_add_on_content_location_resolver = nullptr;
os::Mutex g_mutex;

View file

@ -15,10 +15,8 @@
*/
#pragma once
#include <switch.h>
#include <stratosphere.hpp>
#include "lr_content_location_resolver.hpp"
#include <stratosphere/lr/lr_types.hpp>
#include <stratosphere/lr/lr_i_location_resolver_interface.hpp>
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),
};
};
}

View file

@ -15,10 +15,9 @@
*/
#pragma once
#include <switch.h>
#include <stratosphere.hpp>
#include <stratosphere/lr/lr_types.hpp>
namespace ams::lr::impl {
namespace ams::lr {
template<typename Key, typename Value, size_t NumEntries>
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;

View file

@ -15,11 +15,9 @@
*/
#pragma once
#include <switch.h>
#include <stratosphere.hpp>
#include "impl/lr_redirection.hpp"
#include "impl/lr_registered_data.hpp"
#include <stratosphere/lr/lr_types.hpp>
#include <stratosphere/lr/lr_location_redirector.hpp>
#include <stratosphere/lr/lr_registered_data.hpp>
namespace ams::lr {
@ -44,14 +42,12 @@ namespace ams::lr {
RefreshExcluding = 9,
};
private:
impl::LocationRedirector program_redirector;
impl::RegisteredLocations<ncm::ProgramId, MaxRegisteredLocations> registered_program_locations;
impl::LocationRedirector html_docs_redirector;
impl::RegisteredLocations<ncm::ProgramId, MaxRegisteredLocations> registered_html_docs_locations;
LocationRedirector program_redirector;
RegisteredLocations<ncm::ProgramId, MaxRegisteredLocations> registered_program_locations;
LocationRedirector html_docs_redirector;
RegisteredLocations<ncm::ProgramId, MaxRegisteredLocations> registered_html_docs_locations;
private:
void ClearRedirections(u32 flags = impl::RedirectionFlags_None);
void RegisterPath(const Path& path, impl::RegisteredLocations<ncm::ProgramId, MaxRegisteredLocations>* locations, ncm::ProgramId id, ncm::ProgramId owner_id);
bool ResolvePath(Path* out, impl::LocationRedirector* redirector, impl::RegisteredLocations<ncm::ProgramId, MaxRegisteredLocations>* 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) { /* ... */ }

View file

@ -16,8 +16,9 @@
#pragma once
#include <vapours.hpp>
#include "../fs/fs_directory.hpp"
#include "../sf/sf_buffer_tags.hpp"
#include <stratosphere/ncm/ncm_types.hpp>
#include <stratosphere/fs/fs_directory.hpp>
#include <stratosphere/sf/sf_buffer_tags.hpp>
namespace ams::lr {
@ -48,7 +49,7 @@ namespace ams::lr {
if (this->str[i] == '\x00') {
return true;
}
}
}
return false;
}
};

View file

@ -13,13 +13,12 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <switch.h>
#include <stratosphere.hpp>
#include <vapours.hpp>
#include <stratosphere/ncm/ncm_types.hpp>
namespace ams::ncm {
namespace ams::ncm::impl {
template<class Key, class Value, size_t N>
class BoundedMap {
private:

View file

@ -15,8 +15,7 @@
*/
#pragma once
#include <switch.h>
#include <stratosphere.hpp>
#include <stratosphere/ncm/ncm_types.hpp>
#include <stratosphere/kvdb/kvdb_memory_key_value_store.hpp>
namespace ams::ncm {
@ -56,12 +55,12 @@ namespace ams::ncm {
return ResultSuccess();
}
public:
IContentMetaDatabase(ams::kvdb::MemoryKeyValueStore<ContentMetaKey>* kvs) :
IContentMetaDatabase(ams::kvdb::MemoryKeyValueStore<ContentMetaKey>* kvs) :
kvs(kvs), disabled(false)
{
}
IContentMetaDatabase(ams::kvdb::MemoryKeyValueStore<ContentMetaKey>* kvs, const char* mount_name) :
IContentMetaDatabase(ams::kvdb::MemoryKeyValueStore<ContentMetaKey>* kvs, const char* mount_name) :
IContentMetaDatabase(kvs)
{
strcpy(this->mount_name, mount_name);

View file

@ -15,11 +15,10 @@
*/
#pragma once
#include <switch.h>
#include <stratosphere.hpp>
#include <stratosphere/ncm/ncm_types.hpp>
namespace ams::ncm {
class IContentStorage : public sf::IServiceObject {
protected:
enum class CommandId {

View file

@ -13,9 +13,15 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stratosphere.hpp>
#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::IContentMetaDatabase> *, ncm::StorageId);
Result OpenContentStorage(std::shared_ptr<ncm::IContentStorage> *, ncm::StorageId);
}
namespace ams::lr {
@ -31,7 +37,7 @@ namespace ams::lr {
std::shared_ptr<ncm::IContentStorage> content_storage;
R_TRY(ncm::impl::OpenContentStorage(&content_storage, storage_id));
R_ABORT_UNLESS(content_storage->GetPath(out.GetPointer(), data_content_id));
return ResultSuccess();
}

View file

@ -13,9 +13,15 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stratosphere.hpp>
#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::IContentMetaDatabase> *, ncm::StorageId);
Result OpenContentStorage(std::shared_ptr<ncm::IContentStorage> *, ncm::StorageId);
}
namespace ams::lr {
@ -28,13 +34,13 @@ namespace ams::lr {
}
Result ContentLocationResolverInterface::ResolveProgramPath(sf::Out<Path> 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<Path> 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<Path> 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<Path> 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<Path> 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();
}

View file

@ -13,10 +13,9 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stratosphere.hpp>
#include "lr_redirection.hpp"
namespace ams::lr::impl {
namespace ams::lr {
class LocationRedirector::Redirection : public util::IntrusiveListBaseNode<Redirection> {
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);

View file

@ -13,12 +13,9 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stratosphere.hpp>
#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<std::shared_ptr<ILocationResolverInterface>> 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<AddOnContentLocationResolverInterface>();
}
std::shared_ptr<AddOnContentLocationResolverInterface> new_intf = g_add_on_content_location_resolver;
out.SetValue(std::move(new_intf));
return ResultSuccess();

View file

@ -13,9 +13,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "impl/ncm_content_manager.hpp"
#include "lr_redirect_only_location_resolver.hpp"
#include <stratosphere.hpp>
namespace ams::lr {
@ -24,7 +22,7 @@ namespace ams::lr {
}
Result RedirectOnlyLocationResolverInterface::ResolveProgramPath(sf::Out<Path> 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<Path> 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<Path> 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<Path> 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<Path> 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();
}

View file

@ -13,11 +13,36 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "lr_registered_location_resolver.hpp"
#include <stratosphere.hpp>
namespace ams::lr {
namespace {
template<size_t N>
bool ResolvePath(Path *out, const LocationRedirector &redirector, const RegisteredLocations<ncm::ProgramId, N> &locations, ncm::ProgramId id) {
if (!redirector.FindRedirection(out, id)) {
if (!locations.Find(out, id)) {
return false;
}
}
return true;
}
template<size_t N>
void RegisterPath(RegisteredLocations<ncm::ProgramId, N> &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<ncm::ProgramId, RegisteredLocationResolverInterface::MaxRegisteredLocations>* 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<ncm::ProgramId, RegisteredLocationResolverInterface::MaxRegisteredLocations>* 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<Path> 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<Path> 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();
}

View file

@ -18,9 +18,6 @@
#include <switch.h>
#include <stratosphere.hpp>
#include "../ncm_i_content_meta_database.hpp"
#include "../ncm_i_content_storage.hpp"
namespace ams::ncm::impl {
/* Initialization/Finalization. */

View file

@ -18,9 +18,6 @@
#include <switch.h>
#include <stratosphere.hpp>
#include "ncm_i_content_meta_database.hpp"
#include "ncm_i_content_storage.hpp"
namespace ams::ncm {
class ContentManagerService final : public sf::IServiceObject {

View file

@ -18,8 +18,6 @@
#include <switch.h>
#include <stratosphere.hpp>
#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<ContentMetaAttribute> out_attributes, ContentMetaKey key) override;
virtual Result GetRequiredApplicationVersion(sf::Out<u32> out_version, ContentMetaKey key) override;
virtual Result GetContentIdByTypeAndIdOffset(sf::Out<ContentId> 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;

View file

@ -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 {

View file

@ -17,7 +17,6 @@
#include <stratosphere.hpp>
#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<LocationResolverNumServers, LocationResolverServerOptions, LocationResolverMaxSessions> {
private:
static constexpr size_t ThreadStackSize = 0x4000;
static constexpr int ThreadPriority = 0x15;
using ServiceType = lr::LocationResolverManagerImpl;
private:
os::StaticThread<ThreadStackSize> thread;
std::shared_ptr<ServiceType> lr_manager;
private:
static void ThreadFunction(void *_this) {
reinterpret_cast<LocationResolverServerManager *>(_this)->LoopProcess();
}
public:
LocationResolverServerManager(ServiceType *m)
: thread(ThreadFunction, this, ThreadPriority), lr_manager(sf::ServiceObjectTraits<ServiceType>::SharedPointerHelper::GetEmptyDeleteSharedPointer(m))
{
/* ... */
}
ams::Result Initialize() {
return this->RegisterServer<ServiceType>(LocationResolverServiceName, LocationResolverManagerSessions, this->lr_manager);
}
ams::Result StartThreads() {
return this->thread.Start();
}
void Wait() {
this->thread.Join();
}
};
sf::hipc::ServerManager<ContentManagerNumServers, ContentManagerServerOptions, ContentManagerMaxSessions> 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<NcmNumServers, NcmServerOptions, NcmMaxSessions> g_ncm_server_manager;
sf::hipc::ServerManager<LrNumServers, NcmServerOptions, LrMaxSessions> g_lr_server_manager;
}
void ContentManagerServerMain(void* arg) {
/* Create services. */
R_ABORT_UNLESS(g_ncm_server_manager.RegisterServer<ncm::ContentManagerService>(NcmServiceName, NcmMaxSessions));
R_ABORT_UNLESS(g_ncm_server_manager.RegisterServer<ncm::ContentManagerService>(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<lr::impl::LocationResolverManagerImpl>(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;
}

View file

@ -18,8 +18,6 @@
#include <switch.h>
#include <stratosphere.hpp>
#include "ncm_i_content_storage.hpp"
namespace ams::ncm {
class ReadOnlyContentStorageInterface : public IContentStorage {