1
0
Fork 0
mirror of https://github.com/DarkMatterCore/nxdumptool.git synced 2024-09-20 05:53:25 +01:00
nxdumptool/source/tasks.cpp
Pablo Curiel e48aa2e937 Implemented background tasks for Borealis.
* core: implemented SCOPED_TRY_LOCK macro. Specific functions are now using it instead of SCOPED_LOCK to avoid potentially locking the Borealis UI.

* UI: implemented background tasks for Borealis, which call functions that now use SCOPED_TRY_LOCK.
2021-06-09 00:48:17 -04:00

103 lines
3.2 KiB
C++

/*
* tasks.cpp
*
* Copyright (c) 2020-2021, DarkMatterCore <pabloacurielz@gmail.com>.
*
* This file is part of nxdumptool (https://github.com/DarkMatterCore/nxdumptool).
*
* nxdumptool is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* nxdumptool is distributed in the hope that 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 <https://www.gnu.org/licenses/>.
*/
#include <nxdt_includes.h>
#include <tasks.hpp>
namespace nxdt::tasks
{
/* Gamecard task. */
GameCardTask::GameCardTask(GameCardStatusEvent *gc_status_event) : brls::RepeatingTask(100) /* 100 ms intervals. */
{
this->gc_status_event = gc_status_event;
}
void GameCardTask::run(retro_time_t current_time)
{
brls::RepeatingTask::run(current_time);
this->cur_gc_status = (GameCardStatus)gamecardGetStatus();
if (this->cur_gc_status != this->prev_gc_status)
{
this->gc_status_event->fire(this->cur_gc_status);
this->prev_gc_status = this->cur_gc_status;
brls::Logger::debug("Gamecard status change triggered: {}.", this->cur_gc_status);
}
}
/* Gamecard title task. */
GameCardTitleTask::GameCardTitleTask(VoidEvent *gc_title_event) : brls::RepeatingTask(100) /* 100 ms intervals. */
{
this->gc_title_event = gc_title_event;
}
void GameCardTitleTask::run(retro_time_t current_time)
{
brls::RepeatingTask::run(current_time);
if (titleIsGameCardInfoUpdated())
{
this->gc_title_event->fire();
brls::Logger::debug("Gamecard title info updated.");
}
}
/* USB Mass Storage task. */
UmsTask::UmsTask(VoidEvent *ums_event) : brls::RepeatingTask(100) /* 100 ms intervals. */
{
this->ums_event = ums_event;
}
void UmsTask::run(retro_time_t current_time)
{
brls::RepeatingTask::run(current_time);
if (umsIsDeviceInfoUpdated())
{
this->ums_event->fire();
brls::Logger::debug("UMS device info updated.");
}
}
/* USB host device connection task. */
UsbHostTask::UsbHostTask(BooleanEvent *usb_host_event) : brls::RepeatingTask(100) /* 100 ms intervals. */
{
this->usb_host_event = usb_host_event;
}
void UsbHostTask::run(retro_time_t current_time)
{
brls::RepeatingTask::run(current_time);
this->cur_usb_host_status = usbIsReady();
if (this->cur_usb_host_status != this->prev_usb_host_status)
{
this->usb_host_event->fire(this->cur_usb_host_status);
this->prev_usb_host_status = this->cur_usb_host_status;
brls::Logger::debug("USB host status change triggered: {}.", this->cur_usb_host_status);
}
}
}