2021-06-09 05:48:17 +01:00
|
|
|
/*
|
|
|
|
* tasks.hpp
|
|
|
|
*
|
2022-03-17 12:58:40 +00:00
|
|
|
* Copyright (c) 2020-2022, DarkMatterCore <pabloacurielz@gmail.com>.
|
2021-06-09 05:48:17 +01:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#ifndef __TASKS_HPP__
|
|
|
|
#define __TASKS_HPP__
|
|
|
|
|
|
|
|
#include <borealis.hpp>
|
|
|
|
|
2021-07-28 00:47:12 +01:00
|
|
|
#include "defines.h"
|
2021-06-09 05:48:17 +01:00
|
|
|
#include "core/gamecard.h"
|
|
|
|
#include "core/title.h"
|
|
|
|
#include "core/ums.h"
|
|
|
|
#include "core/usb.h"
|
2021-07-29 20:55:31 +01:00
|
|
|
#include "download_task.hpp"
|
2021-06-09 05:48:17 +01:00
|
|
|
|
2021-08-11 08:17:57 +01:00
|
|
|
#define EVENT_SUBSCRIPTION(event_type, event_name) \
|
|
|
|
ALWAYS_INLINE event_type::Subscription RegisterListener(event_type::Callback cb) { return this->event_name.subscribe(cb); } \
|
|
|
|
ALWAYS_INLINE void UnregisterListener(event_type::Subscription subscription) { this->event_name.unsubscribe(subscription); }
|
|
|
|
|
2021-06-09 05:48:17 +01:00
|
|
|
namespace nxdt::tasks
|
|
|
|
{
|
2021-06-23 19:27:06 +01:00
|
|
|
/* Used to hold status info data. */
|
|
|
|
typedef struct {
|
2021-08-07 09:42:03 +01:00
|
|
|
struct tm timeinfo;
|
2021-06-23 19:27:06 +01:00
|
|
|
u32 charge_percentage;
|
|
|
|
PsmChargerType charger_type;
|
|
|
|
NifmInternetConnectionType connection_type;
|
|
|
|
char *ip_addr;
|
|
|
|
} StatusInfoData;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-23 19:27:06 +01:00
|
|
|
/* Used to hold pointers to application metadata entries. */
|
2021-06-11 01:33:11 +01:00
|
|
|
typedef std::vector<TitleApplicationMetadata*> TitleApplicationMetadataVector;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-23 19:27:06 +01:00
|
|
|
/* Used to hold UMS devices. */
|
2021-06-11 01:33:11 +01:00
|
|
|
typedef std::vector<UsbHsFsDevice> UmsDeviceVector;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-23 19:27:06 +01:00
|
|
|
/* Custom event types. */
|
|
|
|
typedef brls::Event<const StatusInfoData*> StatusInfoEvent;
|
|
|
|
typedef brls::Event<GameCardStatus> GameCardStatusEvent;
|
|
|
|
typedef brls::Event<const TitleApplicationMetadataVector*> TitleEvent;
|
|
|
|
typedef brls::Event<const UmsDeviceVector*> UmsEvent;
|
2021-06-25 22:01:15 +01:00
|
|
|
typedef brls::Event<UsbHostSpeed> UsbHostEvent;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-18 08:02:23 +01:00
|
|
|
/* Status info task. */
|
2021-06-23 19:27:06 +01:00
|
|
|
/* Its event returns a pointer to a StatusInfoData struct. */
|
2021-06-18 08:02:23 +01:00
|
|
|
class StatusInfoTask: public brls::RepeatingTask
|
|
|
|
{
|
|
|
|
private:
|
2021-06-23 19:27:06 +01:00
|
|
|
StatusInfoEvent status_info_event;
|
|
|
|
StatusInfoData status_info_data = {0};
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-18 08:02:23 +01:00
|
|
|
protected:
|
|
|
|
void run(retro_time_t current_time) override;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-18 08:02:23 +01:00
|
|
|
public:
|
|
|
|
StatusInfoTask(void);
|
|
|
|
~StatusInfoTask(void);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-07-30 22:07:26 +01:00
|
|
|
bool IsInternetConnectionAvailable(void);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-08-11 08:17:57 +01:00
|
|
|
EVENT_SUBSCRIPTION(StatusInfoEvent, status_info_event);
|
2021-06-18 08:02:23 +01:00
|
|
|
};
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-09 05:48:17 +01:00
|
|
|
/* Gamecard task. */
|
2021-06-23 19:27:06 +01:00
|
|
|
/* Its event returns a GameCardStatus value. */
|
2021-06-09 05:48:17 +01:00
|
|
|
class GameCardTask: public brls::RepeatingTask
|
|
|
|
{
|
|
|
|
private:
|
2021-06-11 01:33:11 +01:00
|
|
|
GameCardStatusEvent gc_status_event;
|
2021-06-09 05:48:17 +01:00
|
|
|
GameCardStatus cur_gc_status = GameCardStatus_NotInserted;
|
|
|
|
GameCardStatus prev_gc_status = GameCardStatus_NotInserted;
|
2021-07-19 22:09:58 +01:00
|
|
|
bool first_notification = true;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-13 07:18:14 +01:00
|
|
|
protected:
|
|
|
|
void run(retro_time_t current_time) override;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-09 05:48:17 +01:00
|
|
|
public:
|
2021-06-11 01:33:11 +01:00
|
|
|
GameCardTask(void);
|
|
|
|
~GameCardTask(void);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-08-11 08:17:57 +01:00
|
|
|
EVENT_SUBSCRIPTION(GameCardStatusEvent, gc_status_event);
|
2021-06-09 05:48:17 +01:00
|
|
|
};
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-11 01:33:11 +01:00
|
|
|
/* Title task. */
|
2021-06-23 19:27:06 +01:00
|
|
|
/* Its event returns a pointer to a TitleApplicationMetadataVector with metadata for user titles (system titles don't change at runtime). */
|
2021-06-11 01:33:11 +01:00
|
|
|
class TitleTask: public brls::RepeatingTask
|
2021-06-09 05:48:17 +01:00
|
|
|
{
|
|
|
|
private:
|
2021-06-23 19:27:06 +01:00
|
|
|
TitleEvent title_event;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-11 01:33:11 +01:00
|
|
|
TitleApplicationMetadataVector system_metadata;
|
|
|
|
TitleApplicationMetadataVector user_metadata;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-11 01:33:11 +01:00
|
|
|
void PopulateApplicationMetadataVector(bool is_system);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-13 07:18:14 +01:00
|
|
|
protected:
|
|
|
|
void run(retro_time_t current_time) override;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-09 05:48:17 +01:00
|
|
|
public:
|
2021-06-11 01:33:11 +01:00
|
|
|
TitleTask(void);
|
|
|
|
~TitleTask(void);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2022-09-12 19:19:10 +01:00
|
|
|
/* Intentionally left here to let views retrieve title metadata. */
|
2021-06-24 00:02:47 +01:00
|
|
|
const TitleApplicationMetadataVector* GetApplicationMetadata(bool is_system);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-08-11 08:17:57 +01:00
|
|
|
EVENT_SUBSCRIPTION(TitleEvent, title_event);
|
2021-06-09 05:48:17 +01:00
|
|
|
};
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-09 05:48:17 +01:00
|
|
|
/* USB Mass Storage task. */
|
2021-06-23 19:27:06 +01:00
|
|
|
/* Its event returns a pointer to a UmsDeviceVector. */
|
2021-06-09 05:48:17 +01:00
|
|
|
class UmsTask: public brls::RepeatingTask
|
|
|
|
{
|
|
|
|
private:
|
2021-06-23 19:27:06 +01:00
|
|
|
UmsEvent ums_event;
|
2021-06-11 01:33:11 +01:00
|
|
|
UmsDeviceVector ums_devices;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-11 01:33:11 +01:00
|
|
|
void PopulateUmsDeviceVector(void);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-13 07:18:14 +01:00
|
|
|
protected:
|
|
|
|
void run(retro_time_t current_time) override;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-09 05:48:17 +01:00
|
|
|
public:
|
2021-06-11 01:33:11 +01:00
|
|
|
UmsTask(void);
|
|
|
|
~UmsTask(void);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2022-09-12 19:19:10 +01:00
|
|
|
/* Intentionally left here to let views retrieve UMS device info. */
|
|
|
|
const UmsDeviceVector* GetUmsDevices(void);
|
|
|
|
|
2021-08-11 08:17:57 +01:00
|
|
|
EVENT_SUBSCRIPTION(UmsEvent, ums_event);
|
2021-06-09 05:48:17 +01:00
|
|
|
};
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-09 05:48:17 +01:00
|
|
|
/* USB host device connection task. */
|
|
|
|
class UsbHostTask: public brls::RepeatingTask
|
|
|
|
{
|
|
|
|
private:
|
2021-06-23 19:27:06 +01:00
|
|
|
UsbHostEvent usb_host_event;
|
2021-06-25 22:01:15 +01:00
|
|
|
UsbHostSpeed cur_usb_host_speed = UsbHostSpeed_None;
|
|
|
|
UsbHostSpeed prev_usb_host_speed = UsbHostSpeed_None;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-13 07:18:14 +01:00
|
|
|
protected:
|
|
|
|
void run(retro_time_t current_time) override;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-09 05:48:17 +01:00
|
|
|
public:
|
2021-06-11 01:33:11 +01:00
|
|
|
UsbHostTask(void);
|
|
|
|
~UsbHostTask(void);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-08-11 08:17:57 +01:00
|
|
|
EVENT_SUBSCRIPTION(UsbHostEvent, usb_host_event);
|
2021-06-09 05:48:17 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-08-11 08:17:57 +01:00
|
|
|
#undef EVENT_SUBSCRIPTION
|
|
|
|
|
2021-06-09 05:48:17 +01:00
|
|
|
#endif /* __TASKS_HPP__ */
|