Hi Paul,
I've just made a proof of concept prototype for drawing state diagrams for nanomsg. The code is currently here: https://github.com/tailhook/nanomsg/blob/state_diagrams/utils/diag.py It's a simple python script that scans C code (using clang's parser) and produces dot file for whatever it found. It doesn't understand everything, but most of the transitions does. You may look at generated pictures here: https://drive.google.com/folderview?id=0Byd_FTQksoKLM3ExekJMVnZJU0U&usp=sharing So what all of you think about this? :)
Super-cool!Where should we store such generated documentation? In the repo itself? Website? Elsewhere?
It seems that shutdown code is handled by a bunch of if statements at the start of handlers, instead of switches. Why it's handled in a special way?
I wanted to blog about this but haven't have found time so far. Let me explain in short:
State machine can have arbitrary number of states. In each state some sub-components are initialised some are not initialised.
State machine shutdown (as if nn_close() is called) can occur in any state, thus, each "normal" state would have to have a chain of attached "shutdown" states to stop all the sub-components cleanly.
That increases the number of states in thr state machine quadratically.To avoid proliferation of states, I've introduced special handling for shutdown, which simply stops anything that's still running, not depending on the initial state of the state machine (see attached picture).
HTH, Martin
Attachment:
state1.png
Description: PNG image