QtStateMachine does not support blocking transitions?
-
I'm trying to implement a custom communication protocol as a state machine on a single thread. I receive messages from wherever and my state machine forwards the messages to the current state via direct function calls and signal / slots. The states are supposed to transition to the appropriate ones depending on the content of the messages.
The problem is I can't directly trigger transitions synchronously. Say I have state A and B, I receive 2 messages over UDP so I emit two signals. The first message arrives at A and tries to transition to B, but since the transition is done over the event loop; the signal / slot of the second message blocks it. So the second message arrives at A too, when it is supposed to arrive at B.
I know this is expected behavior since signal / slots translate to direct calls but I need the same behavior from my state transitions and I couldn't find any way to do that using the QStateMachine API. I've thought of a few solutions such as:
- Separate the message and state machine mechanisms into two threads
- Somehow notify the machine that a transition event is waiting in the loop so it doesn't direct messages to states but to a buffer until the transition is done
Am I missing something or is going around the QStateMachine framework the way forward here?
-
Hi and welcome to devnet,
Maybe using an event based transition could be the solution. Please check the corresponding exemple here.
-
To me it seems that there might be an issue in your state machine design.
Can you maybe provide a drawing showing it and how it should work ?