-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathexecutor.cpp
More file actions
34 lines (31 loc) · 1.33 KB
/
executor.cpp
File metadata and controls
34 lines (31 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "mach/executor.hpp"
#include <thread>
#include <memory>
#include <spdlog/spdlog.h>
#include "mach/sequences/sequence_manager.hpp"
#include "mach/device/device_manager.hpp"
void mach::Executor::executeSequence(const std::string sequenceName) {
std::shared_ptr<Sequence> sequence = SequenceManager::getInstance().getSequence(sequenceName);
if (sequence == nullptr) {
spdlog::warn("Sequence '{}' not found, skipping execution!", sequenceName);
return;
}
if (executing.exchange(true, std::memory_order_acq_rel)) {
if (!sequence->isOverride()) {
spdlog::warn("MACH: Skipped executing sequence {}, another sequence is already being executed.", sequenceName);
return;
}
DeviceManager::getInstance().enableAbortMode();
}
std::thread([this, sequence]() {
spdlog::info("MACH: Executing sequence {}.", sequence->getName());
sequence->execute();
spdlog::info("MACH: Finished sequence {}.", sequence->getName());
// If this sequence was an abort, disable the abort mode after 5 seconds.
if (sequence->isOverride()) {
std::this_thread::sleep_for(std::chrono::seconds(5));
DeviceManager::getInstance().disableAbortMode();
}
this->executing.store(false, std::memory_order_release);
}).detach();
}