forked from ShuriZma/suyu
result: Make fully constexpr, add ON_RESULT_INCLUDED
This commit is contained in:
parent
c60ab6bbf6
commit
54372fdff5
|
@ -12,7 +12,7 @@ void DefaultErrorApplet::Close() const {}
|
||||||
|
|
||||||
void DefaultErrorApplet::ShowError(Result error, FinishedCallback finished) const {
|
void DefaultErrorApplet::ShowError(Result error, FinishedCallback finished) const {
|
||||||
LOG_CRITICAL(Service_Fatal, "Application requested error display: {:04}-{:04} (raw={:08X})",
|
LOG_CRITICAL(Service_Fatal, "Application requested error display: {:04}-{:04} (raw={:08X})",
|
||||||
error.module.Value(), error.description.Value(), error.raw);
|
error.GetModule(), error.GetDescription(), error.raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DefaultErrorApplet::ShowErrorWithTimestamp(Result error, std::chrono::seconds time,
|
void DefaultErrorApplet::ShowErrorWithTimestamp(Result error, std::chrono::seconds time,
|
||||||
|
@ -20,7 +20,7 @@ void DefaultErrorApplet::ShowErrorWithTimestamp(Result error, std::chrono::secon
|
||||||
LOG_CRITICAL(
|
LOG_CRITICAL(
|
||||||
Service_Fatal,
|
Service_Fatal,
|
||||||
"Application requested error display: {:04X}-{:04X} (raw={:08X}) with timestamp={:016X}",
|
"Application requested error display: {:04X}-{:04X} (raw={:08X}) with timestamp={:016X}",
|
||||||
error.module.Value(), error.description.Value(), error.raw, time.count());
|
error.GetModule(), error.GetDescription(), error.raw, time.count());
|
||||||
}
|
}
|
||||||
|
|
||||||
void DefaultErrorApplet::ShowCustomErrorText(Result error, std::string main_text,
|
void DefaultErrorApplet::ShowCustomErrorText(Result error, std::string main_text,
|
||||||
|
@ -28,7 +28,7 @@ void DefaultErrorApplet::ShowCustomErrorText(Result error, std::string main_text
|
||||||
FinishedCallback finished) const {
|
FinishedCallback finished) const {
|
||||||
LOG_CRITICAL(Service_Fatal,
|
LOG_CRITICAL(Service_Fatal,
|
||||||
"Application requested custom error with error_code={:04X}-{:04X} (raw={:08X})",
|
"Application requested custom error with error_code={:04X}-{:04X} (raw={:08X})",
|
||||||
error.module.Value(), error.description.Value(), error.raw);
|
error.GetModule(), error.GetDescription(), error.raw);
|
||||||
LOG_CRITICAL(Service_Fatal, " Main Text: {}", main_text);
|
LOG_CRITICAL(Service_Fatal, " Main Text: {}", main_text);
|
||||||
LOG_CRITICAL(Service_Fatal, " Detail Text: {}", detail_text);
|
LOG_CRITICAL(Service_Fatal, " Detail Text: {}", detail_text);
|
||||||
}
|
}
|
||||||
|
|
|
@ -189,14 +189,14 @@ enum class ErrorModule : u32 {
|
||||||
union Result {
|
union Result {
|
||||||
u32 raw;
|
u32 raw;
|
||||||
|
|
||||||
BitField<0, 9, ErrorModule> module;
|
using Module = BitField<0, 9, ErrorModule>;
|
||||||
BitField<9, 13, u32> description;
|
using Description = BitField<9, 13, u32>;
|
||||||
|
|
||||||
Result() = default;
|
Result() = default;
|
||||||
constexpr explicit Result(u32 raw_) : raw(raw_) {}
|
constexpr explicit Result(u32 raw_) : raw(raw_) {}
|
||||||
|
|
||||||
constexpr Result(ErrorModule module_, u32 description_)
|
constexpr Result(ErrorModule module_, u32 description_)
|
||||||
: raw(module.FormatValue(module_) | description.FormatValue(description_)) {}
|
: raw(Module::FormatValue(module_) | Description::FormatValue(description_)) {}
|
||||||
|
|
||||||
[[nodiscard]] constexpr bool IsSuccess() const {
|
[[nodiscard]] constexpr bool IsSuccess() const {
|
||||||
return raw == 0;
|
return raw == 0;
|
||||||
|
@ -211,7 +211,15 @@ union Result {
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] constexpr u32 GetInnerValue() const {
|
[[nodiscard]] constexpr u32 GetInnerValue() const {
|
||||||
return static_cast<u32>(module.Value()) | (description << module.bits);
|
return raw;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] constexpr ErrorModule GetModule() const {
|
||||||
|
return Module::ExtractValue(raw);
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] constexpr u32 GetDescription() const {
|
||||||
|
return Description::ExtractValue(raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] constexpr bool Includes(Result result) const {
|
[[nodiscard]] constexpr bool Includes(Result result) const {
|
||||||
|
@ -274,8 +282,9 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] constexpr bool Includes(Result other) const {
|
[[nodiscard]] constexpr bool Includes(Result other) const {
|
||||||
return code.module == other.module && code.description <= other.description &&
|
return code.GetModule() == other.GetModule() &&
|
||||||
other.description <= description_end;
|
code.GetDescription() <= other.GetDescription() &&
|
||||||
|
other.GetDescription() <= description_end;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -330,6 +339,16 @@ constexpr bool EvaluateResultFailure(const Result& r) {
|
||||||
return R_FAILED(r);
|
return R_FAILED(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <auto... R>
|
||||||
|
constexpr bool EvaluateAnyResultIncludes(const Result& r) {
|
||||||
|
return ((r == R) || ...);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <auto... R>
|
||||||
|
constexpr bool EvaluateResultNotIncluded(const Result& r) {
|
||||||
|
return !EvaluateAnyResultIncludes<R...>(r);
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
constexpr void UpdateCurrentResultReference(T result_reference, Result result) = delete;
|
constexpr void UpdateCurrentResultReference(T result_reference, Result result) = delete;
|
||||||
// Intentionally not defined
|
// Intentionally not defined
|
||||||
|
@ -371,6 +390,13 @@ constexpr void UpdateCurrentResultReference<const Result>(Result result_referenc
|
||||||
DECLARE_CURRENT_RESULT_REFERENCE_AND_STORAGE(__COUNTER__); \
|
DECLARE_CURRENT_RESULT_REFERENCE_AND_STORAGE(__COUNTER__); \
|
||||||
ON_RESULT_SUCCESS_2
|
ON_RESULT_SUCCESS_2
|
||||||
|
|
||||||
|
#define ON_RESULT_INCLUDED_2(...) \
|
||||||
|
ON_RESULT_RETURN_IMPL(ResultImpl::EvaluateAnyResultIncludes<__VA_ARGS__>)
|
||||||
|
|
||||||
|
#define ON_RESULT_INCLUDED(...) \
|
||||||
|
DECLARE_CURRENT_RESULT_REFERENCE_AND_STORAGE(__COUNTER__); \
|
||||||
|
ON_RESULT_INCLUDED_2(__VA_ARGS__)
|
||||||
|
|
||||||
constexpr inline Result __TmpCurrentResultReference = ResultSuccess;
|
constexpr inline Result __TmpCurrentResultReference = ResultSuccess;
|
||||||
|
|
||||||
/// Returns a result.
|
/// Returns a result.
|
||||||
|
|
|
@ -27,8 +27,8 @@ struct ErrorCode {
|
||||||
|
|
||||||
static constexpr ErrorCode FromResult(Result result) {
|
static constexpr ErrorCode FromResult(Result result) {
|
||||||
return {
|
return {
|
||||||
.error_category{2000 + static_cast<u32>(result.module.Value())},
|
.error_category{2000 + static_cast<u32>(result.GetModule())},
|
||||||
.error_number{result.description.Value()},
|
.error_number{result.GetDescription()},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -139,7 +139,8 @@ private:
|
||||||
ctx.WriteBufferC(performance_buffer.data(), performance_buffer.size(), 1);
|
ctx.WriteBufferC(performance_buffer.data(), performance_buffer.size(), 1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
LOG_ERROR(Service_Audio, "RequestUpdate failed error 0x{:02X}!", result.description);
|
LOG_ERROR(Service_Audio, "RequestUpdate failed error 0x{:02X}!",
|
||||||
|
result.GetDescription());
|
||||||
}
|
}
|
||||||
|
|
||||||
IPC::ResponseBuilder rb{ctx, 2};
|
IPC::ResponseBuilder rb{ctx, 2};
|
||||||
|
|
|
@ -202,14 +202,14 @@ Result IAlbumAccessorService::TranslateResult(Result in_result) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((in_result.raw & 0x3801ff) == ResultUnknown1024.raw) {
|
if ((in_result.raw & 0x3801ff) == ResultUnknown1024.raw) {
|
||||||
if (in_result.description - 0x514 < 100) {
|
if (in_result.GetDescription() - 0x514 < 100) {
|
||||||
return ResultInvalidFileData;
|
return ResultInvalidFileData;
|
||||||
}
|
}
|
||||||
if (in_result.description - 0x5dc < 100) {
|
if (in_result.GetDescription() - 0x5dc < 100) {
|
||||||
return ResultInvalidFileData;
|
return ResultInvalidFileData;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in_result.description - 0x578 < 100) {
|
if (in_result.GetDescription() - 0x578 < 100) {
|
||||||
if (in_result == ResultFileCountLimit) {
|
if (in_result == ResultFileCountLimit) {
|
||||||
return ResultUnknown22;
|
return ResultUnknown22;
|
||||||
}
|
}
|
||||||
|
@ -244,9 +244,10 @@ Result IAlbumAccessorService::TranslateResult(Result in_result) {
|
||||||
return ResultUnknown1024;
|
return ResultUnknown1024;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in_result.module == ErrorModule::FS) {
|
if (in_result.GetModule() == ErrorModule::FS) {
|
||||||
if ((in_result.description >> 0xc < 0x7d) || (in_result.description - 1000 < 2000) ||
|
if ((in_result.GetDescription() >> 0xc < 0x7d) ||
|
||||||
(((in_result.description - 3000) >> 3) < 0x271)) {
|
(in_result.GetDescription() - 1000 < 2000) ||
|
||||||
|
(((in_result.GetDescription() - 3000) >> 3) < 0x271)) {
|
||||||
// TODO: Translate FS error
|
// TODO: Translate FS error
|
||||||
return in_result;
|
return in_result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,8 +73,8 @@ static void GenerateErrorReport(Core::System& system, Result error_code, const F
|
||||||
"Program entry point: 0x{:16X}\n"
|
"Program entry point: 0x{:16X}\n"
|
||||||
"\n",
|
"\n",
|
||||||
Common::g_scm_branch, Common::g_scm_desc, title_id, error_code.raw,
|
Common::g_scm_branch, Common::g_scm_desc, title_id, error_code.raw,
|
||||||
2000 + static_cast<u32>(error_code.module.Value()),
|
2000 + static_cast<u32>(error_code.GetModule()),
|
||||||
static_cast<u32>(error_code.description.Value()), info.set_flags, info.program_entry_point);
|
static_cast<u32>(error_code.GetDescription()), info.set_flags, info.program_entry_point);
|
||||||
if (info.backtrace_size != 0x0) {
|
if (info.backtrace_size != 0x0) {
|
||||||
crash_report += "Registers:\n";
|
crash_report += "Registers:\n";
|
||||||
for (size_t i = 0; i < info.registers.size(); i++) {
|
for (size_t i = 0; i < info.registers.size(); i++) {
|
||||||
|
|
|
@ -301,7 +301,7 @@ Result NfcInterface::TranslateResultToServiceError(Result result) const {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.module != ErrorModule::NFC) {
|
if (result.GetModule() != ErrorModule::NFC) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -68,8 +68,8 @@ json GetReportCommonData(u64 title_id, Result result, const std::string& timesta
|
||||||
auto out = json{
|
auto out = json{
|
||||||
{"title_id", fmt::format("{:016X}", title_id)},
|
{"title_id", fmt::format("{:016X}", title_id)},
|
||||||
{"result_raw", fmt::format("{:08X}", result.raw)},
|
{"result_raw", fmt::format("{:08X}", result.raw)},
|
||||||
{"result_module", fmt::format("{:08X}", static_cast<u32>(result.module.Value()))},
|
{"result_module", fmt::format("{:08X}", static_cast<u32>(result.GetModule()))},
|
||||||
{"result_description", fmt::format("{:08X}", result.description.Value())},
|
{"result_description", fmt::format("{:08X}", result.GetDescription())},
|
||||||
{"timestamp", timestamp},
|
{"timestamp", timestamp},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -25,8 +25,8 @@ void QtErrorDisplay::ShowError(Result error, FinishedCallback finished) const {
|
||||||
callback = std::move(finished);
|
callback = std::move(finished);
|
||||||
emit MainWindowDisplayError(
|
emit MainWindowDisplayError(
|
||||||
tr("Error Code: %1-%2 (0x%3)")
|
tr("Error Code: %1-%2 (0x%3)")
|
||||||
.arg(static_cast<u32>(error.module.Value()) + 2000, 4, 10, QChar::fromLatin1('0'))
|
.arg(static_cast<u32>(error.GetModule()) + 2000, 4, 10, QChar::fromLatin1('0'))
|
||||||
.arg(error.description, 4, 10, QChar::fromLatin1('0'))
|
.arg(error.GetDescription(), 4, 10, QChar::fromLatin1('0'))
|
||||||
.arg(error.raw, 8, 16, QChar::fromLatin1('0')),
|
.arg(error.raw, 8, 16, QChar::fromLatin1('0')),
|
||||||
tr("An error has occurred.\nPlease try again or contact the developer of the software."));
|
tr("An error has occurred.\nPlease try again or contact the developer of the software."));
|
||||||
}
|
}
|
||||||
|
@ -38,8 +38,8 @@ void QtErrorDisplay::ShowErrorWithTimestamp(Result error, std::chrono::seconds t
|
||||||
const QDateTime date_time = QDateTime::fromSecsSinceEpoch(time.count());
|
const QDateTime date_time = QDateTime::fromSecsSinceEpoch(time.count());
|
||||||
emit MainWindowDisplayError(
|
emit MainWindowDisplayError(
|
||||||
tr("Error Code: %1-%2 (0x%3)")
|
tr("Error Code: %1-%2 (0x%3)")
|
||||||
.arg(static_cast<u32>(error.module.Value()) + 2000, 4, 10, QChar::fromLatin1('0'))
|
.arg(static_cast<u32>(error.GetModule()) + 2000, 4, 10, QChar::fromLatin1('0'))
|
||||||
.arg(error.description, 4, 10, QChar::fromLatin1('0'))
|
.arg(error.GetDescription(), 4, 10, QChar::fromLatin1('0'))
|
||||||
.arg(error.raw, 8, 16, QChar::fromLatin1('0')),
|
.arg(error.raw, 8, 16, QChar::fromLatin1('0')),
|
||||||
tr("An error occurred on %1 at %2.\nPlease try again or contact the developer of the "
|
tr("An error occurred on %1 at %2.\nPlease try again or contact the developer of the "
|
||||||
"software.")
|
"software.")
|
||||||
|
@ -53,8 +53,8 @@ void QtErrorDisplay::ShowCustomErrorText(Result error, std::string dialog_text,
|
||||||
callback = std::move(finished);
|
callback = std::move(finished);
|
||||||
emit MainWindowDisplayError(
|
emit MainWindowDisplayError(
|
||||||
tr("Error Code: %1-%2 (0x%3)")
|
tr("Error Code: %1-%2 (0x%3)")
|
||||||
.arg(static_cast<u32>(error.module.Value()) + 2000, 4, 10, QChar::fromLatin1('0'))
|
.arg(static_cast<u32>(error.GetModule()) + 2000, 4, 10, QChar::fromLatin1('0'))
|
||||||
.arg(error.description, 4, 10, QChar::fromLatin1('0'))
|
.arg(error.GetDescription(), 4, 10, QChar::fromLatin1('0'))
|
||||||
.arg(error.raw, 8, 16, QChar::fromLatin1('0')),
|
.arg(error.raw, 8, 16, QChar::fromLatin1('0')),
|
||||||
tr("An error has occurred.\n\n%1\n\n%2")
|
tr("An error has occurred.\n\n%1\n\n%2")
|
||||||
.arg(QString::fromStdString(dialog_text))
|
.arg(QString::fromStdString(dialog_text))
|
||||||
|
|
Loading…
Reference in New Issue