Files
Toolbox/inc/luaRunner.h
Yadciel c611b008af Fügt CLI-Toolverwaltung und erweiterte UI-Funktionen hinzu
Ermöglicht die Verwaltung (Erstellen, Auflisten, Ausführen) von Tools über eine Befehlszeilenschnittstelle für Automatisierung und Integration. Die Benutzeroberfläche wurde mit dedizierten Ansichten für Toolerstellung und -bearbeitung, In-App-Lua-Hilfe sowie kontextsensitiven Menüs erweitert. Neue Abhängigkeiten (CLI11, rang) wurden integriert und eine umfassende Testsuite hinzugefügt. Die Lizenzierung wurde auf AGPL-3.0 umgestellt und ein Kontributionsleitfaden bereitgestellt.
2026-07-17 17:22:15 +02:00

60 lines
1.7 KiB
C++

#pragma once
#include <atomic>
#include <filesystem>
#include <functional>
#include <memory>
#include <mutex>
#include <string>
#include <thread>
#include <unordered_map>
#include <vector>
class LuaRunner {
public:
using CompletionCallback = std::function<void(bool)>;
struct RunResult {
bool started = false;
bool singleInstance = false;
};
struct TaskStatus {
bool singleInstance = false;
bool running = false;
};
RunResult run(const std::string& taskId, const std::filesystem::path& scriptPath,
int timeoutSeconds, CompletionCallback onComplete);
TaskStatus status(const std::string& taskId, const std::filesystem::path& scriptPath) const;
void cancel(const std::string& taskId) const;
void shutdown() const;
~LuaRunner();
private:
struct LuaTask {
std::shared_ptr<std::atomic_bool> cancel;
std::shared_ptr<std::atomic_bool> executionFinished;
std::shared_ptr<std::atomic_bool> callbackFinished;
bool singleInstance = false;
std::jthread worker;
LuaTask(std::shared_ptr<std::atomic_bool> cancelFlag,
std::shared_ptr<std::atomic_bool> executionFinishedFlag,
std::shared_ptr<std::atomic_bool> callbackFinishedFlag,
bool isSingleInstance)
: cancel(std::move(cancelFlag)),
executionFinished(std::move(executionFinishedFlag)),
callbackFinished(std::move(callbackFinishedFlag)),
singleInstance(isSingleInstance) {}
};
struct State {
std::mutex tasksMutex;
std::unordered_map<std::string, std::vector<LuaTask>> tasks;
};
std::shared_ptr<State> m_state = std::make_shared<State>();
};