2019-06-27 00:46:19 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2019 Atmosphère-NX
|
|
|
|
*
|
|
|
|
* 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 "ldr_arguments.hpp"
|
|
|
|
|
2019-10-24 11:30:10 +02:00
|
|
|
namespace ams::ldr::args {
|
2019-06-27 00:46:19 +02:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
/* Convenience definitions. */
|
|
|
|
constexpr ncm::TitleId FreeTitleId = {};
|
|
|
|
constexpr size_t MaxArgumentInfos = 10;
|
|
|
|
|
|
|
|
/* Global storage. */
|
|
|
|
ArgumentInfo g_argument_infos[MaxArgumentInfos];
|
|
|
|
|
|
|
|
/* Helpers. */
|
2019-06-28 02:37:33 +02:00
|
|
|
ArgumentInfo *FindArgumentInfo(ncm::TitleId title_id) {
|
2019-06-27 00:46:19 +02:00
|
|
|
for (size_t i = 0; i < MaxArgumentInfos; i++) {
|
|
|
|
if (g_argument_infos[i].title_id == title_id) {
|
|
|
|
return &g_argument_infos[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-06-28 02:37:33 +02:00
|
|
|
ArgumentInfo *FindFreeArgumentInfo() {
|
|
|
|
return FindArgumentInfo(FreeTitleId);
|
2019-06-27 00:46:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* API. */
|
|
|
|
const ArgumentInfo *Get(ncm::TitleId title_id) {
|
2019-06-28 02:37:33 +02:00
|
|
|
return FindArgumentInfo(title_id);
|
2019-06-27 00:46:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Result Set(ncm::TitleId title_id, const void *args, size_t args_size) {
|
2019-10-24 10:40:44 +02:00
|
|
|
R_UNLESS(args_size < ArgumentSizeMax, ldr::ResultTooLongArgument());
|
2019-06-27 00:46:19 +02:00
|
|
|
|
2019-06-28 02:37:33 +02:00
|
|
|
ArgumentInfo *arg_info = FindArgumentInfo(title_id);
|
2019-06-27 00:46:19 +02:00
|
|
|
if (arg_info == nullptr) {
|
2019-06-28 02:37:33 +02:00
|
|
|
arg_info = FindFreeArgumentInfo();
|
2019-06-27 00:46:19 +02:00
|
|
|
}
|
2019-10-24 10:40:44 +02:00
|
|
|
R_UNLESS(arg_info != nullptr, ldr::ResultTooManyArguments());
|
2019-06-27 00:46:19 +02:00
|
|
|
|
|
|
|
arg_info->title_id = title_id;
|
|
|
|
arg_info->args_size = args_size;
|
|
|
|
std::memcpy(arg_info->args, args, args_size);
|
2019-10-24 10:40:44 +02:00
|
|
|
return ResultSuccess();
|
2019-06-27 00:46:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Result Clear() {
|
|
|
|
for (size_t i = 0; i < MaxArgumentInfos; i++) {
|
|
|
|
g_argument_infos[i].title_id = FreeTitleId;
|
|
|
|
}
|
2019-10-24 10:40:44 +02:00
|
|
|
return ResultSuccess();
|
2019-06-27 00:46:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|