This commit is contained in:
@@ -411,7 +411,7 @@ void MissionQueue::runMissionActions(nlohmann::json& entry)
|
||||
}
|
||||
}
|
||||
|
||||
void MissionQueue::executeActionsUnlocked(const nlohmann::json& actions,
|
||||
MissionQueue::LoopControl MissionQueue::executeActionsUnlocked(const nlohmann::json& actions,
|
||||
const nlohmann::json& parameters,
|
||||
nlohmann::json& log,
|
||||
int loop_depth)
|
||||
@@ -426,7 +426,7 @@ void MissionQueue::executeActionsUnlocked(const nlohmann::json& actions,
|
||||
while (paused_ && !stop_)
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
if (stop_)
|
||||
return;
|
||||
return LoopControl::None;
|
||||
|
||||
const std::string action_id = action.value("id", "");
|
||||
const std::string kind = action.value("kind", "action");
|
||||
@@ -445,30 +445,58 @@ void MissionQueue::executeActionsUnlocked(const nlohmann::json& actions,
|
||||
{
|
||||
const std::string ref_id = action.value("refId", "");
|
||||
nlohmann::json ref_mission = nlohmann::json::object();
|
||||
// Nested mission snapshot should be resolved by frontend before queueing.
|
||||
(void)ref_id;
|
||||
log.push_back({{"ts", IdUtil::nowIso8601()}, {"level", "info"}, {"message", "Sub-mission: " + label}});
|
||||
if (action.contains("resolved_mission") && action["resolved_mission"].is_object())
|
||||
{
|
||||
const auto& nested_actions = action["resolved_mission"]["actions"];
|
||||
executeActionsUnlocked(nested_actions, parameters, log, loop_depth);
|
||||
const LoopControl nested = executeActionsUnlocked(nested_actions, parameters, log, loop_depth);
|
||||
if (nested == LoopControl::Break)
|
||||
return LoopControl::Break;
|
||||
if (nested == LoopControl::Continue)
|
||||
continue;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (type == "break")
|
||||
{
|
||||
log.push_back({{"ts", IdUtil::nowIso8601()}, {"level", "info"}, {"message", "Break loop"}});
|
||||
return LoopControl::Break;
|
||||
}
|
||||
|
||||
if (type == "continue")
|
||||
{
|
||||
log.push_back({{"ts", IdUtil::nowIso8601()}, {"level", "info"}, {"message", "Continue loop"}});
|
||||
return LoopControl::Continue;
|
||||
}
|
||||
|
||||
if (type == "loop")
|
||||
{
|
||||
const std::string mode = params.value("mode", "count");
|
||||
const int count = static_cast<int>(paramNumber(params, "count", 1));
|
||||
const auto& children =
|
||||
action.contains("children") && action["children"].is_array() ? action["children"] : nlohmann::json::array();
|
||||
const int iterations = mode == "endless" ? 1 : std::max(1, count);
|
||||
for (int i = 0; i < iterations; ++i)
|
||||
const int iterations = mode == "endless" ? 10000 : std::max(1, count);
|
||||
for (int i = 0; i < iterations && !stop_; ++i)
|
||||
{
|
||||
log.push_back({{"ts", IdUtil::nowIso8601()},
|
||||
{"level", "info"},
|
||||
{"message", "Loop " + std::to_string(i + 1) + "/" + std::to_string(iterations)}});
|
||||
executeActionsUnlocked(children, parameters, log, loop_depth + 1);
|
||||
if (mode == "endless" && i == 0)
|
||||
{
|
||||
log.push_back({{"ts", IdUtil::nowIso8601()},
|
||||
{"level", "info"},
|
||||
{"message", "Loop endless (simulated, max " + std::to_string(iterations) + ")"}});
|
||||
}
|
||||
else if (mode != "endless")
|
||||
{
|
||||
log.push_back({{"ts", IdUtil::nowIso8601()},
|
||||
{"level", "info"},
|
||||
{"message", "Loop " + std::to_string(i + 1) + "/" + std::to_string(iterations)}});
|
||||
}
|
||||
const LoopControl ctrl = executeActionsUnlocked(children, parameters, log, loop_depth + 1);
|
||||
if (ctrl == LoopControl::Break)
|
||||
break;
|
||||
if (ctrl == LoopControl::Continue)
|
||||
continue;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@@ -520,6 +548,7 @@ void MissionQueue::executeActionsUnlocked(const nlohmann::json& actions,
|
||||
{{"ts", IdUtil::nowIso8601()}, {"level", "info"}, {"message", label + " (" + type + ") simulated"}});
|
||||
sleepMs(400);
|
||||
}
|
||||
return LoopControl::None;
|
||||
}
|
||||
|
||||
void MissionQueue::sleepMs(int ms)
|
||||
|
||||
Reference in New Issue
Block a user