state machine, parallel seems to work, final state and info about active atomic states
This commit is contained in:
@@ -39,11 +39,22 @@ public:
|
||||
PIStateMachine(const PIString & n = {});
|
||||
|
||||
bool start();
|
||||
bool isRunning() const { return is_running; }
|
||||
void addOnFinish(std::function<void()> f) { on_finish = f; }
|
||||
|
||||
template<typename... Args>
|
||||
bool postEvent(int event_id, Args... args) {
|
||||
if (!is_running) return false;
|
||||
need_finish = false;
|
||||
PIScopeExitCall exit_call([this] {
|
||||
if (need_finish) {
|
||||
is_running = false;
|
||||
if (on_finish) on_finish();
|
||||
}
|
||||
});
|
||||
PIVector<PIStateBase *> active_states;
|
||||
gatherActiveStates(active_states);
|
||||
// piCout << "active" << active_states;
|
||||
for (auto * s: active_states) {
|
||||
for (auto * t: s->transitions) {
|
||||
if (t->eventID != event_id) continue;
|
||||
@@ -55,6 +66,12 @@ public:
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
void onFinish() override;
|
||||
|
||||
bool is_running = false, need_finish = false;
|
||||
std::function<void()> on_finish;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user