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