excuting misstion from queue
This commit is contained in:
56
src/mission/mission_queue.hpp
Normal file
56
src/mission/mission_queue.hpp
Normal file
@@ -0,0 +1,56 @@
|
||||
#pragma once
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include <atomic>
|
||||
#include <filesystem>
|
||||
#include <mutex>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
namespace lm {
|
||||
|
||||
class MissionQueue
|
||||
{
|
||||
public:
|
||||
explicit MissionQueue(std::filesystem::path queue_path);
|
||||
~MissionQueue();
|
||||
|
||||
MissionQueue(const MissionQueue&) = delete;
|
||||
MissionQueue& operator=(const MissionQueue&) = delete;
|
||||
|
||||
nlohmann::json list() const;
|
||||
nlohmann::json runnerStatus() const;
|
||||
|
||||
std::optional<nlohmann::json> enqueue(const nlohmann::json& payload, std::string& err);
|
||||
bool removeById(const std::string& id, std::string& err);
|
||||
bool clearAll(std::string& err);
|
||||
bool reorder(const nlohmann::json& ordered_ids, std::string& err);
|
||||
|
||||
private:
|
||||
std::filesystem::path queue_path_;
|
||||
mutable std::mutex mu_;
|
||||
nlohmann::json queue_;
|
||||
nlohmann::json runner_;
|
||||
|
||||
std::thread worker_;
|
||||
std::atomic<bool> stop_{false};
|
||||
std::atomic<bool> wake_{false};
|
||||
|
||||
void load();
|
||||
void saveUnlocked() const;
|
||||
void ensureRunnerDefaults();
|
||||
void startWorkerIfNeeded();
|
||||
void workerLoop();
|
||||
void processQueueUnlocked();
|
||||
void executeMissionUnlocked(nlohmann::json& entry);
|
||||
void executeActionsUnlocked(const nlohmann::json& actions,
|
||||
const nlohmann::json& parameters,
|
||||
nlohmann::json& log,
|
||||
int loop_depth);
|
||||
void sleepMs(int ms);
|
||||
void setRunnerState(const std::string& state, const std::string& message = "");
|
||||
};
|
||||
|
||||
} // namespace lm
|
||||
Reference in New Issue
Block a user