mirror of
https://github.com/J-D-K/JKSV.git
synced 2026-03-22 17:54:33 -05:00
51 lines
1.6 KiB
C++
51 lines
1.6 KiB
C++
#pragma once
|
|
#include <functional>
|
|
#include <memory>
|
|
#include <string>
|
|
#include <thread>
|
|
#include <mutex>
|
|
#include <memory>
|
|
#include <switch.h>
|
|
#include "system/taskData.hpp"
|
|
|
|
namespace sys
|
|
{
|
|
typedef enum
|
|
{
|
|
TASK_TYPE_TASK,
|
|
TASK_TYPE_PROGRESS
|
|
} taskTypes;
|
|
|
|
class task;
|
|
|
|
using taskFunction = std::function<void(sys::task *, sys::sharedTaskData)>;
|
|
|
|
class task
|
|
{
|
|
public:
|
|
// taskFunction is void that takes a sys::task pointer and shared taskArgs pointer
|
|
task(sys::taskFunction threadFunction, sys::sharedTaskData);
|
|
// This can pass through a child class of task. This is for progressTask mostly. Maybe more down the line.
|
|
task(sys::taskFunction threadFunction, sys::task *childTask, sys::sharedTaskData);
|
|
~task();
|
|
// Returns status string of task.
|
|
std::string getThreadStatus(void);
|
|
// Sets status of task
|
|
void setThreadStatus(const std::string &newStatus);
|
|
// Sets m_IsRunning to false
|
|
void finished(void);
|
|
// Returns if task
|
|
bool isRunning(void);
|
|
|
|
private:
|
|
// Thread. Orignally used C++ threads, but without control they choked the main thread. LOL nevermind.
|
|
std::unique_ptr<std::thread> m_Thread;
|
|
// Status string
|
|
std::string m_ThreadStatus;
|
|
// Mutexes to protect status and running bool
|
|
std::mutex m_StatusMutex, m_RunningMutex;
|
|
// Whether task still running
|
|
bool m_IsRunning = true;
|
|
};
|
|
}
|