2015-05-12 16:25:15 -04:00
|
|
|
// Copyright 2015 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2018-11-19 12:54:06 -05:00
|
|
|
#include "core/hle/kernel/errors.h"
|
2016-09-21 02:52:38 -04:00
|
|
|
#include "core/hle/kernel/resource_limit.h"
|
2018-11-19 12:54:06 -05:00
|
|
|
#include "core/hle/result.h"
|
2015-05-12 16:25:15 -04:00
|
|
|
|
|
|
|
namespace Kernel {
|
2018-11-19 12:54:06 -05:00
|
|
|
namespace {
|
|
|
|
constexpr std::size_t ResourceTypeToIndex(ResourceType type) {
|
|
|
|
return static_cast<std::size_t>(type);
|
|
|
|
}
|
|
|
|
} // Anonymous namespace
|
2015-05-12 16:25:15 -04:00
|
|
|
|
2018-08-28 12:30:33 -04:00
|
|
|
ResourceLimit::ResourceLimit(KernelCore& kernel) : Object{kernel} {}
|
|
|
|
ResourceLimit::~ResourceLimit() = default;
|
2015-05-12 16:25:15 -04:00
|
|
|
|
2019-11-24 20:15:51 -05:00
|
|
|
std::shared_ptr<ResourceLimit> ResourceLimit::Create(KernelCore& kernel) {
|
|
|
|
return std::make_shared<ResourceLimit>(kernel);
|
2015-05-12 16:25:15 -04:00
|
|
|
}
|
|
|
|
|
2018-11-19 12:54:06 -05:00
|
|
|
s64 ResourceLimit::GetCurrentResourceValue(ResourceType resource) const {
|
|
|
|
return values.at(ResourceTypeToIndex(resource));
|
|
|
|
}
|
|
|
|
|
|
|
|
s64 ResourceLimit::GetMaxResourceValue(ResourceType resource) const {
|
|
|
|
return limits.at(ResourceTypeToIndex(resource));
|
2015-05-12 16:25:15 -04:00
|
|
|
}
|
|
|
|
|
2018-11-19 12:54:06 -05:00
|
|
|
ResultCode ResourceLimit::SetLimitValue(ResourceType resource, s64 value) {
|
|
|
|
const auto index = ResourceTypeToIndex(resource);
|
|
|
|
|
|
|
|
if (value < values[index]) {
|
|
|
|
return ERR_INVALID_STATE;
|
2015-05-12 16:25:15 -04:00
|
|
|
}
|
2018-11-19 12:54:06 -05:00
|
|
|
|
|
|
|
values[index] = value;
|
|
|
|
return RESULT_SUCCESS;
|
2015-05-12 16:25:15 -04:00
|
|
|
}
|
2018-01-20 02:48:02 -05:00
|
|
|
} // namespace Kernel
|