fsm:use_fsm
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| fsm:use_fsm [2007/04/29 13:48] – fgm | fsm:use_fsm [2020/11/23 17:23] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 12: | Line 12: | ||
| Implementing the FSM once the table is defined means implementing each event (foo) as an event-handling function called f_foo. The return values of this function must be the ones defined in the f_transitions entry for that state. Returning a non accepted value throws an exception. | Implementing the FSM once the table is defined means implementing each event (foo) as an event-handling function called f_foo. The return values of this function must be the ones defined in the f_transitions entry for that state. Returning a non accepted value throws an exception. | ||
| + | |||
| + | ===== Controlling the FSM operation ===== | ||
| + | ==== Directed work with the " | ||
| + | |||
| + | A special built-in event is fsm:: | ||
| + | |||
| + | This event can be turned off by setting the FSM " | ||
| + | |||
| + | Syntactic sugar: the idle() method is a shorthand for apply_events(fsm:: | ||
| + | |||
| + | ==== Filtering events ==== | ||
| + | |||
| + | The OSInet FSM has three event processing modes, controlled by the {get|set}_event_mode methods: | ||
| + | |||
| + | * fsm:: | ||
| + | * Switching from fsm:: | ||
| + | * fsm:: | ||
| + | * fsm:: | ||
| + | * Switching from fsm:: | ||
| + | |||
| + | ==== Disabling post-events actions ==== | ||
| + | |||
| + | Firing of post-event actions is enabled by default, but can be disabled by setting the $allow_actions property to false. | ||
| + | |||
| + | In that case, applications can still decide to fire the event themselves by reading the fsm_action field in the fsm_result returns by fsm:: | ||
| ===== Example ===== | ===== Example ===== | ||
| Line 17: | Line 42: | ||
| For a very basic FSM going just from initial to final randomly, building the table and transitions can look like: | For a very basic FSM going just from initial to final randomly, building the table and transitions can look like: | ||
| - | <php> | + | <code php> |
| class foo extends fsm | class foo extends fsm | ||
| { | { | ||
| Line 44: | Line 69: | ||
| } | } | ||
| } | } | ||
| - | </php> | + | </code> |
| + | |||
| Application code not involved in the FSM operation can use the FSM apply_event method($event_name) to submit an event to the FSM. Only allowed events for the given state the FSM is in are allowed: submitting other events throws an exception. | Application code not involved in the FSM operation can use the FSM apply_event method($event_name) to submit an event to the FSM. Only allowed events for the given state the FSM is in are allowed: submitting other events throws an exception. | ||
fsm/use_fsm.1177854529.txt.gz · Last modified: (external edit)
