mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-04-22 20:44:49 +00:00
lr: Introducing registered data
This commit is contained in:
parent
81a7fdb42f
commit
d0be5f095e
7 changed files with 122 additions and 100 deletions
|
@ -75,56 +75,6 @@ namespace sts::lr::impl {
|
|||
}
|
||||
}
|
||||
|
||||
bool RegisteredLocationRedirector::FindRedirection(Path *out, ncm::TitleId title_id) {
|
||||
auto redirection = this->redirections.Find(title_id);
|
||||
|
||||
if (redirection) {
|
||||
*out = *redirection;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool RegisteredLocationRedirector::SetRedirection(ncm::TitleId title_id, const Path& path) {
|
||||
if (this->redirections.IsFull()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this->redirections[title_id] = path;
|
||||
return true;
|
||||
}
|
||||
|
||||
void RegisteredLocationRedirector::EraseRedirection(ncm::TitleId title_id) {
|
||||
this->redirections.Remove(title_id);
|
||||
}
|
||||
|
||||
void RegisteredLocationRedirector::ClearRedirections() {
|
||||
this->redirections.RemoveAll();
|
||||
}
|
||||
|
||||
bool AddOnContentRedirector::FindRedirection(ncm::StorageId *out, ncm::TitleId title_id) {
|
||||
auto redirection = this->redirections.Find(title_id);
|
||||
|
||||
if (redirection) {
|
||||
*out = *redirection;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Result AddOnContentRedirector::SetRedirection(ncm::TitleId title_id, ncm::StorageId storage_id) {
|
||||
if (this->redirections.IsFull()) {
|
||||
return ResultLrTooManyRegisteredPaths;
|
||||
}
|
||||
|
||||
this->redirections[title_id] = storage_id;
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
void AddOnContentRedirector::ClearRedirections() {
|
||||
this->redirections.RemoveAll();
|
||||
}
|
||||
|
||||
}
|
|
@ -56,23 +56,4 @@ namespace sts::lr::impl {
|
|||
void ClearRedirections(u32 flags = RedirectionFlags_None);
|
||||
};
|
||||
|
||||
class RegisteredLocationRedirector {
|
||||
private:
|
||||
BoundedMap<ncm::TitleId, Path, 16> redirections;
|
||||
public:
|
||||
bool FindRedirection(Path *out, ncm::TitleId title_id);
|
||||
bool SetRedirection(ncm::TitleId title_id, const Path& path);
|
||||
void EraseRedirection(ncm::TitleId title_id);
|
||||
void ClearRedirections();
|
||||
};
|
||||
|
||||
class AddOnContentRedirector {
|
||||
private:
|
||||
BoundedMap<ncm::TitleId, ncm::StorageId, 0x800> redirections;
|
||||
public:
|
||||
bool FindRedirection(ncm::StorageId *out, ncm::TitleId title_id);
|
||||
Result SetRedirection(ncm::TitleId title_id, ncm::StorageId storage_id);
|
||||
void ClearRedirections();
|
||||
};
|
||||
|
||||
}
|
99
stratosphere/ncm/source/impl/lr_registered_data.hpp
Normal file
99
stratosphere/ncm/source/impl/lr_registered_data.hpp
Normal file
|
@ -0,0 +1,99 @@
|
|||
/*
|
||||
* Copyright (c) 2019 Adubbz
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* 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 "../lr_types.hpp"
|
||||
|
||||
namespace sts::lr::impl {
|
||||
|
||||
template<typename Key, typename Value, size_t NumEntries>
|
||||
class RegisteredData {
|
||||
NON_COPYABLE(RegisteredData);
|
||||
NON_MOVEABLE(RegisteredData);
|
||||
private:
|
||||
struct Entry {
|
||||
Value value;
|
||||
Key key;
|
||||
bool is_valid;
|
||||
};
|
||||
private:
|
||||
Entry entries[NumEntries];
|
||||
public:
|
||||
RegisteredData() {
|
||||
this->Clear();
|
||||
}
|
||||
|
||||
bool Register(const Key &key, const Value &value) {
|
||||
/* Try to find an existing value. */
|
||||
for (size_t i = 0; i < NumEntries; i++) {
|
||||
Entry& entry = this->entries[i];
|
||||
if (entry.is_valid && entry.key == key) {
|
||||
entry.value = value;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < NumEntries; i++) {
|
||||
Entry& entry = this->entries[i];
|
||||
if (!entry.is_valid) {
|
||||
entry.key = key;
|
||||
entry.value = value;
|
||||
entry.is_valid = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void Unregister(const Key &key) {
|
||||
for (size_t i = 0; i < NumEntries; i++) {
|
||||
Entry& entry = this->entries[i];
|
||||
if (entry.is_valid && entry.key == key) {
|
||||
entry.is_valid = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Find(Value *out, const Key &key) {
|
||||
for (size_t i = 0; i < NumEntries; i++) {
|
||||
Entry& entry = this->entries[i];
|
||||
if (entry.is_valid && entry.key == key) {
|
||||
*out = entry.value;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void Clear() {
|
||||
for (size_t i = 0; i < NumEntries; i++) {
|
||||
this->entries[i].is_valid = false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Key, size_t NumEntries>
|
||||
using RegisteredLocations = RegisteredData<Key, lr::Path, NumEntries>;
|
||||
|
||||
template<typename Key, size_t NumEntries>
|
||||
using RegisteredStorages = RegisteredData<Key, ncm::StorageId, NumEntries>;
|
||||
|
||||
}
|
|
@ -19,15 +19,11 @@
|
|||
|
||||
namespace sts::lr {
|
||||
|
||||
AddOnContentLocationResolverInterface::AddOnContentLocationResolverInterface() {
|
||||
this->redirector.ClearRedirections();
|
||||
}
|
||||
|
||||
Result AddOnContentLocationResolverInterface::ResolveAddOnContentPath(OutPointerWithServerSize<Path, 0x1> out, ncm::TitleId tid) {
|
||||
Path path;
|
||||
ncm::StorageId storage_id = ncm::StorageId::None;
|
||||
|
||||
if (!this->redirector.FindRedirection(&storage_id, tid)) {
|
||||
if (!this->registered_storages.Find(&storage_id, tid)) {
|
||||
return ResultLrAddOnContentNotFound;
|
||||
}
|
||||
|
||||
|
@ -45,12 +41,15 @@ namespace sts::lr {
|
|||
}
|
||||
|
||||
Result AddOnContentLocationResolverInterface::RegisterAddOnContentStorage(ncm::StorageId storage_id, ncm::TitleId tid) {
|
||||
R_TRY(this->redirector.SetRedirection(tid, storage_id));
|
||||
if (!this->registered_storages.Register(tid, storage_id)) {
|
||||
return ResultLrTooManyRegisteredPaths;
|
||||
}
|
||||
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result AddOnContentLocationResolverInterface::UnregisterAllAddOnContentPath() {
|
||||
this->redirector.ClearRedirections();
|
||||
this->registered_storages.Clear();
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
#include <switch.h>
|
||||
#include <stratosphere.hpp>
|
||||
|
||||
#include "impl/lr_redirection.hpp"
|
||||
#include "impl/lr_registered_data.hpp"
|
||||
#include "lr_types.hpp"
|
||||
|
||||
namespace sts::lr {
|
||||
|
@ -31,9 +31,7 @@ namespace sts::lr {
|
|||
UnregisterAllAddOnContentPath = 2,
|
||||
};
|
||||
private:
|
||||
impl::AddOnContentRedirector redirector;
|
||||
public:
|
||||
AddOnContentLocationResolverInterface();
|
||||
impl::RegisteredStorages<ncm::TitleId, 0x800> registered_storages;
|
||||
public:
|
||||
virtual Result ResolveAddOnContentPath(OutPointerWithServerSize<Path, 0x1> out, ncm::TitleId tid);
|
||||
virtual Result RegisterAddOnContentStorage(ncm::StorageId storage_id, ncm::TitleId tid);
|
||||
|
|
|
@ -18,11 +18,6 @@
|
|||
|
||||
namespace sts::lr {
|
||||
|
||||
RegisteredLocationResolverInterface::RegisteredLocationResolverInterface() {
|
||||
this->registered_program_redirector.ClearRedirections();
|
||||
this->registered_html_docs_redirector.ClearRedirections();
|
||||
}
|
||||
|
||||
RegisteredLocationResolverInterface::~RegisteredLocationResolverInterface() {
|
||||
/* Ensure entries are deallocated */
|
||||
this->html_docs_redirector.ClearRedirections();
|
||||
|
@ -33,7 +28,7 @@ namespace sts::lr {
|
|||
Path path;
|
||||
|
||||
if (!this->program_redirector.FindRedirection(&path, tid)) {
|
||||
if (!this->registered_program_redirector.FindRedirection(&path, tid)) {
|
||||
if (!this->registered_program_locations.Find(&path, tid)) {
|
||||
return ResultLrProgramNotFound;
|
||||
}
|
||||
}
|
||||
|
@ -45,16 +40,16 @@ namespace sts::lr {
|
|||
Result RegisteredLocationResolverInterface::RegisterProgramPath(InPointer<const Path> path, ncm::TitleId tid) {
|
||||
Path tmp_path = *path.pointer;
|
||||
|
||||
if (!this->registered_program_redirector.SetRedirection(tid, tmp_path)) {
|
||||
this->registered_program_redirector.ClearRedirections();
|
||||
this->registered_program_redirector.SetRedirection(tid, tmp_path);
|
||||
if (!this->registered_program_locations.Register(tid, tmp_path)) {
|
||||
this->registered_program_locations.Clear();
|
||||
this->registered_program_locations.Register(tid, tmp_path);
|
||||
}
|
||||
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result RegisteredLocationResolverInterface::UnregisterProgramPath(ncm::TitleId tid) {
|
||||
this->registered_program_redirector.EraseRedirection(tid);
|
||||
this->registered_program_locations.Unregister(tid);
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
|
@ -68,7 +63,7 @@ namespace sts::lr {
|
|||
Path path;
|
||||
|
||||
if (!this->html_docs_redirector.FindRedirection(&path, tid)) {
|
||||
if (!this->registered_html_docs_redirector.FindRedirection(&path, tid)) {
|
||||
if (!this->registered_html_docs_locations.Find(&path, tid)) {
|
||||
return ResultLrProgramNotFound;
|
||||
}
|
||||
}
|
||||
|
@ -80,16 +75,16 @@ namespace sts::lr {
|
|||
Result RegisteredLocationResolverInterface::RegisterHtmlDocumentPath(InPointer<const Path> path, ncm::TitleId tid) {
|
||||
Path tmp_path = *path.pointer;
|
||||
|
||||
if (!this->registered_html_docs_redirector.SetRedirection(tid, tmp_path)) {
|
||||
this->registered_html_docs_redirector.ClearRedirections();
|
||||
this->registered_html_docs_redirector.SetRedirection(tid, tmp_path);
|
||||
if (!this->registered_html_docs_locations.Register(tid, tmp_path)) {
|
||||
this->registered_html_docs_locations.Clear();
|
||||
this->registered_html_docs_locations.Register(tid, tmp_path);
|
||||
}
|
||||
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result RegisteredLocationResolverInterface::UnregisterHtmlDocumentPath(ncm::TitleId tid) {
|
||||
this->registered_html_docs_redirector.EraseRedirection(tid);
|
||||
this->registered_html_docs_locations.Unregister(tid);
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
|
@ -100,8 +95,8 @@ namespace sts::lr {
|
|||
}
|
||||
|
||||
Result RegisteredLocationResolverInterface::Refresh() {
|
||||
this->registered_program_redirector.ClearRedirections();
|
||||
this->registered_html_docs_redirector.ClearRedirections();
|
||||
this->registered_program_locations.Clear();
|
||||
this->registered_html_docs_locations.Clear();
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include <stratosphere.hpp>
|
||||
|
||||
#include "impl/lr_redirection.hpp"
|
||||
#include "impl/lr_registered_data.hpp"
|
||||
#include "lr_types.hpp"
|
||||
|
||||
namespace sts::lr {
|
||||
|
@ -38,11 +39,10 @@ namespace sts::lr {
|
|||
};
|
||||
private:
|
||||
impl::LocationRedirector program_redirector;
|
||||
impl::RegisteredLocationRedirector registered_program_redirector;
|
||||
impl::RegisteredLocations<ncm::TitleId, 16> registered_program_locations;
|
||||
impl::LocationRedirector html_docs_redirector;
|
||||
impl::RegisteredLocationRedirector registered_html_docs_redirector;
|
||||
impl::RegisteredLocations<ncm::TitleId, 16> registered_html_docs_locations;
|
||||
public:
|
||||
RegisteredLocationResolverInterface();
|
||||
~RegisteredLocationResolverInterface();
|
||||
|
||||
Result ResolveProgramPath(OutPointerWithServerSize<Path, 0x1> out, ncm::TitleId tid);
|
||||
|
|
Loading…
Add table
Reference in a new issue