
How do I take this diagram and translate it into a useable program.
I’m not really sure how to read this diagram.
Walk me through it, maybe show an example of code and how it relates to the diagram.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Circles with text inside are the states. Text describes what the state is.
Dashed arrow points to starting state.
Outgoing arrows determine where this state could change. Beside of the arrow is the text divided by the line into upper part and lower part. Lower part is actions that should take place when arrow transition is executed. Upper part is conditions. When they are true – this transition is executed (and so lower part).
Lambda symbol means you should do nothing except changing current state when transition takes place.
So lower parts have coarse corresponding to your functions. And upper parts are the points where you should wait for conditions – polling or async waiting for pending I/O packets, whatever.
Here is some pseudo-code similar to C (I’ve written it just here so do not assume it works or even compiles):
You should also take into account that receive and send functions could be blocking, so code
if (rdt_rcv(rcvpkt)) whatever;is technically incorrect as you don’t check forrdt_senduntil it returns control. So FSM communicates only logical flow, not technical aspects of how it should be organized, thread management etc. And my code doesn’t show this aspects also because it could be decently complicated depending on your needs and because you didn’t give enough details to make informed advices on these sort of things 🙂My only guess is that you would have some sort of bi-directed stream (for input and output respectively) and conditions would be like
if (there_is_ready_for_consuming_packet_in_the_input_queue) continue;andif (data_was_put_to_outgoing_stream_successfully) ...;