#ifndef __SD_GUI_QUEUE_MANAGER
|
#define __SD_GUI_QUEUE_MANAGER
|
|
#include <map>
|
#include <chrono>
|
#include <nlohmann/json.hpp>
|
|
#include "utils.hpp"
|
|
#include <wx/event.h>
|
#include <wx/window.h>
|
|
namespace QM
|
{
|
enum QueueStatus
|
{
|
PENDING,
|
RUNNING,
|
PAUSED,
|
FAILED
|
};
|
inline const char *QueueStatus_str[] = {
|
"pending",
|
"running",
|
"paused",
|
"failed"};
|
|
enum QueueEvents
|
{
|
ITEM_DELETED,
|
ITEM_ADDED,
|
ITEM_STATUS_CHANGED,
|
ITEM_UPDATED
|
};
|
struct QueueItem
|
{
|
QueueItem() = default;
|
QueueItem(const QueueItem &other)
|
: id(other.id), created_at(other.created_at), updated_at(other.updated_at),
|
finished_at(other.finished_at), params(other.params), status(other.status) {}
|
|
QueueItem &operator=(const QueueItem &other)
|
{
|
if (this != &other)
|
{
|
id = other.id;
|
created_at = other.created_at;
|
updated_at = other.updated_at;
|
finished_at = other.finished_at;
|
// Másolatot készítünk a params referenciáról
|
// Ha a params referenciához tartozó SDParams objektum módosulna,
|
// akkor ebben az esetben másolatban marad az eredeti QueueItem-ben
|
params = other.params;
|
status = other.status;
|
}
|
return *this;
|
}
|
int id, created_at, updated_at, finished_at;
|
sd_gui_utils::SDParams params;
|
QM::QueueStatus status = QM::QueueStatus::PENDING;
|
};
|
|
inline void to_json(nlohmann::json &j, const QueueItem &p)
|
{
|
j = nlohmann::json{
|
{"id", p.id},
|
{"created_at", p.created_at},
|
{"updated_at", p.updated_at},
|
{"finished_at", p.finished_at},
|
// {"params", p.params},
|
{"status", (int)p.status}};
|
}
|
|
inline void from_json(const nlohmann::json &j, QueueItem &p)
|
{
|
j.at("id").get_to(p.id);
|
j.at("created_at").get_to(p.created_at);
|
j.at("updated_at").get_to(p.updated_at);
|
j.at("finished_at").get_to(p.finished_at);
|
// j.at("params").get_to(p.params);
|
p.status = j.at("status").get<QM::QueueStatus>();
|
}
|
|
class QueueManager
|
{
|
public:
|
QueueManager(wxEvtHandler *eventHandler, std::string jobsdir);
|
int AddItem(QM::QueueItem item);
|
int AddItem(sd_gui_utils::SDParams *params);
|
int AddItem(sd_gui_utils::SDParams params);
|
QM::QueueItem GetItem(int id);
|
QM::QueueItem GetItem(QM::QueueItem item);
|
const std::map<int, QM::QueueItem> getList();
|
int Duplicate(QM::QueueItem item);
|
int Duplicate(int id);
|
void SetStatus(QM::QueueStatus status, int id);
|
void PauseAll();
|
void SendEventToMainWindow(QM::QueueEvents eventType, QM::QueueItem item = QM::QueueItem());
|
void OnThreadMessage(wxThreadEvent &e);
|
|
private:
|
int GetCurrentUnixTimestamp();
|
std::string jobsDir;
|
// thread events handler, toupdate main window data table
|
void onItemAdded(QM::QueueItem item);
|
void LodJobsFromFile();
|
void SaveJobsToFile();
|
|
wxEvtHandler *eventHandler;
|
wxWindow *parent;
|
std::map<int, QM::QueueItem> QueueList;
|
};
|
|
};
|
|
#endif
|