This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#include "robot/robot_runtime.hpp"
|
||||
|
||||
#include "mission/mission_queue.hpp"
|
||||
#include "util/file_util.hpp"
|
||||
#include "storage/database.hpp"
|
||||
#include "util/id_util.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
@@ -16,8 +16,8 @@ constexpr const char* kDefaultMessage = "Waiting for new missions...";
|
||||
|
||||
} // namespace
|
||||
|
||||
RobotRuntime::RobotRuntime(std::filesystem::path runtime_path, MissionQueue& mission_queue)
|
||||
: runtime_path_(std::move(runtime_path)), mission_queue_(mission_queue)
|
||||
RobotRuntime::RobotRuntime(Database& db, MissionQueue& mission_queue)
|
||||
: db_(db), mission_queue_(mission_queue)
|
||||
{
|
||||
load();
|
||||
ensureDefaultsUnlocked();
|
||||
@@ -27,23 +27,14 @@ void RobotRuntime::load()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mu_);
|
||||
state_ = nlohmann::json::object();
|
||||
if (!std::filesystem::exists(runtime_path_))
|
||||
return;
|
||||
try
|
||||
{
|
||||
const auto parsed = nlohmann::json::parse(FileUtil::readBinary(runtime_path_));
|
||||
if (parsed.is_object())
|
||||
state_ = parsed;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
state_ = nlohmann::json::object();
|
||||
}
|
||||
nlohmann::json parsed;
|
||||
if (db_.getDocument("robot_runtime", parsed) && parsed.is_object())
|
||||
state_ = parsed;
|
||||
}
|
||||
|
||||
void RobotRuntime::saveUnlocked() const
|
||||
{
|
||||
FileUtil::writeBinaryAtomic(runtime_path_, state_.dump(2));
|
||||
db_.setDocument("robot_runtime", state_);
|
||||
}
|
||||
|
||||
void RobotRuntime::ensureDefaultsUnlocked()
|
||||
|
||||
Reference in New Issue
Block a user