1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-11-15 00:16:48 +00:00
Atmosphere/libraries/libstratosphere/source/ncm/ncm_registered_host_content.cpp

91 lines
3 KiB
C++
Raw Normal View History

2021-09-17 09:33:17 +01:00
/*
* Copyright (c) Atmosphère-NX
2021-09-17 09:33:17 +01:00
*
* 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/>.
*/
#include <stratosphere.hpp>
namespace ams::ncm {
2021-09-19 19:00:57 +01:00
2021-09-17 09:33:17 +01:00
class RegisteredHostContent::RegisteredPath : public util::IntrusiveListBaseNode<RegisteredPath> {
NON_COPYABLE(RegisteredPath);
NON_MOVEABLE(RegisteredPath);
private:
2021-10-10 08:14:06 +01:00
ContentId m_content_id;
Path m_path;
2021-09-17 09:33:17 +01:00
public:
2021-10-10 08:14:06 +01:00
RegisteredPath(const ncm::ContentId &content_id, const Path &p) : m_content_id(content_id), m_path(p) {
2021-09-19 19:00:57 +01:00
/* ... */
2021-09-17 09:33:17 +01:00
}
ncm::ContentId GetContentId() const {
2021-10-10 08:14:06 +01:00
return m_content_id;
2021-09-17 09:33:17 +01:00
}
void GetPath(Path *out) const {
2021-10-10 08:14:06 +01:00
*out = m_path;
2021-09-17 09:33:17 +01:00
}
void SetPath(const Path &path) {
2021-10-10 08:14:06 +01:00
m_path = path;
2021-09-17 09:33:17 +01:00
}
};
2021-09-19 19:00:57 +01:00
RegisteredHostContent::~RegisteredHostContent() {
/* ... */
}
2021-09-17 09:33:17 +01:00
Result RegisteredHostContent::RegisterPath(const ncm::ContentId &content_id, const ncm::Path &path) {
2021-10-10 08:14:06 +01:00
std::scoped_lock lk(m_mutex);
2021-09-17 09:33:17 +01:00
/* Replace the path of any existing entries. */
2021-10-10 08:14:06 +01:00
for (auto &registered_path : m_path_list) {
2021-09-17 09:33:17 +01:00
if (registered_path.GetContentId() == content_id) {
registered_path.SetPath(path);
return ResultSuccess();
}
}
/* Allocate a new registered path. TODO: Verify allocator. */
RegisteredPath *registered_path = new RegisteredPath(content_id, path);
R_UNLESS(registered_path != nullptr, ncm::ResultBufferInsufficient());
/* Insert the path into the list. */
2021-10-10 08:14:06 +01:00
m_path_list.push_back(*registered_path);
2021-09-17 09:33:17 +01:00
return ResultSuccess();
}
Result RegisteredHostContent::GetPath(Path *out, const ncm::ContentId &content_id) {
2021-10-10 08:14:06 +01:00
std::scoped_lock lk(m_mutex);
2021-09-17 09:33:17 +01:00
/* Obtain the path of the content. */
2021-10-10 08:14:06 +01:00
for (const auto &registered_path : m_path_list) {
2021-09-17 09:33:17 +01:00
if (registered_path.GetContentId() == content_id) {
registered_path.GetPath(out);
return ResultSuccess();
}
}
return ncm::ResultContentNotFound();
}
void RegisteredHostContent::ClearPaths() {
/* Remove all paths. */
2021-10-10 08:14:06 +01:00
for (auto it = m_path_list.begin(); it != m_path_list.end(); /* ... */) {
2021-09-17 09:33:17 +01:00
auto *obj = std::addressof(*it);
2021-10-10 08:14:06 +01:00
it = m_path_list.erase(it);
2021-09-17 09:33:17 +01:00
delete obj;
}
}
}