2018-11-10 09:54:12 +01:00
|
|
|
/*
|
2019-04-08 04:00:49 +02:00
|
|
|
* Copyright (c) 2018-2019 Atmosphère-NX
|
2018-11-10 09:54:12 +01:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
2019-06-18 01:41:03 +02:00
|
|
|
|
2018-11-10 09:54:12 +01:00
|
|
|
#include <switch.h>
|
|
|
|
#include "fatal_types.hpp"
|
|
|
|
#include "fatal_task.hpp"
|
|
|
|
|
2018-11-10 10:04:40 +01:00
|
|
|
#include "fatal_task_error_report.hpp"
|
2018-11-10 12:16:13 +01:00
|
|
|
#include "fatal_task_screen.hpp"
|
2018-11-10 12:51:19 +01:00
|
|
|
#include "fatal_task_sound.hpp"
|
2018-11-10 12:05:14 +01:00
|
|
|
#include "fatal_task_clock.hpp"
|
2018-11-10 10:19:52 +01:00
|
|
|
#include "fatal_task_power.hpp"
|
2018-11-10 10:04:40 +01:00
|
|
|
|
|
|
|
|
2018-11-10 09:54:12 +01:00
|
|
|
static constexpr size_t MaxTasks = 8;
|
|
|
|
static HosThread g_task_threads[MaxTasks];
|
|
|
|
static size_t g_num_threads = 0;
|
|
|
|
|
|
|
|
|
|
|
|
static void RunTaskThreadFunc(void *arg) {
|
|
|
|
IFatalTask *task = reinterpret_cast<IFatalTask *>(arg);
|
2019-06-18 01:41:03 +02:00
|
|
|
|
2019-06-20 11:00:59 +02:00
|
|
|
if (R_FAILED(task->Run())) {
|
2018-11-10 09:54:12 +01:00
|
|
|
/* TODO: Log task failure, somehow? */
|
|
|
|
}
|
2019-06-18 01:41:03 +02:00
|
|
|
|
2018-11-10 11:21:29 +01:00
|
|
|
/* Finish. */
|
2018-11-10 09:54:12 +01:00
|
|
|
}
|
|
|
|
|
2019-06-18 01:41:03 +02:00
|
|
|
static void RunTask(IFatalTask *task, u32 stack_size = 0x4000) {
|
2018-11-10 09:54:12 +01:00
|
|
|
if (g_num_threads >= MaxTasks) {
|
|
|
|
std::abort();
|
|
|
|
}
|
2019-06-18 01:41:03 +02:00
|
|
|
|
2018-11-10 09:54:12 +01:00
|
|
|
HosThread *cur_thread = &g_task_threads[g_num_threads++];
|
2019-06-18 01:41:03 +02:00
|
|
|
|
2018-11-13 15:03:30 +01:00
|
|
|
cur_thread->Initialize(&RunTaskThreadFunc, task, stack_size, 15);
|
2018-11-10 09:54:12 +01:00
|
|
|
cur_thread->Start();
|
|
|
|
}
|
|
|
|
|
2018-11-14 05:22:54 +01:00
|
|
|
void RunFatalTasks(FatalThrowContext *ctx, u64 title_id, bool error_report, Event *erpt_event, Event *battery_event) {
|
2018-11-10 10:04:40 +01:00
|
|
|
RunTask(new ErrorReportTask(ctx, title_id, error_report, erpt_event));
|
2018-11-10 11:42:07 +01:00
|
|
|
RunTask(new PowerControlTask(ctx, title_id, erpt_event, battery_event));
|
2018-11-13 15:03:30 +01:00
|
|
|
RunTask(new ShowFatalTask(ctx, title_id, battery_event), 0x10000);
|
2018-11-10 12:51:19 +01:00
|
|
|
RunTask(new StopSoundTask(ctx, title_id));
|
2018-11-10 12:16:13 +01:00
|
|
|
RunTask(new BacklightControlTask(ctx, title_id));
|
2018-11-10 12:05:14 +01:00
|
|
|
RunTask(new AdjustClockTask(ctx, title_id));
|
2018-11-10 10:41:47 +01:00
|
|
|
RunTask(new PowerButtonObserveTask(ctx, title_id, erpt_event));
|
2018-11-10 10:19:52 +01:00
|
|
|
RunTask(new StateTransitionStopTask(ctx, title_id));
|
2018-11-10 09:54:12 +01:00
|
|
|
}
|