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