summaryrefslogtreecommitdiffstats
path: root/src/fsm.c
Commit message (Collapse)AuthorAgeFilesLines
* fsm: factor out osmo_fsm_inst_term_children() from osmo_fsm_inst_term()Neels Hofmeyr2016-12-241-20/+42
| | | | | | | | | | | | | | | | | | | | osmo_fsm_inst_term() has code for safe child removal, publish that part as osmo_fsm_inst_term_children(); also use from osmo_fsm_inst_term(). As with osmo_fsm_inst_term(), add osmo_fsm_inst_term_children() macro to pass the caller's source file and line to new _osmo_fsm_inst_term_children(). Rationale: in openbsc's VLR, I want to discard child FSMs when certain events are handled. I could keep a pointer to each one, or simply iterate all children, making the code a lot simpler in some places. (Unfortunately, the patch may be displayed subobtimally. This really only moves the children-loop to a new function, replaces it with a call to _osmo_fsm_inst_term_children(fi, OSMO_FSM_TERM_PARENT, NULL, file, line) and drops two local iterator variables. No other code changes are made, even though the diff may show large removal + addition chunks) Change-Id: I8dac1206259cbd251660f793ad023aaa1dc705a2
* fsm: move LOGPFSMSRC and LOGPFSMLSRC to .hNeels Hofmeyr2016-12-241-13/+0
| | | | | | | | | | | LOGPFSM and LOGPFSML are in the header file, put the *SRC variants also there so users of the osmo_fsm_inst API may conveniently create own functions that log the caller's source file and line. Very useful if many action functions call the same event dispatching function, like foo_fsm_done(), and one needs to know which of the callers to debug. Change-Id: I39447b1d15237b28f88d8c5f08d82c764679dc80
* fsm: log calling file+line for error "event for NULL fi"Neels Hofmeyr2016-12-241-2/+3
| | | | Change-Id: I1970773440865f1415004bcf0164603468acf90b
* fsm: doc: add missing file, line args; fix ws + tweak on one lineNeels Hofmeyr2016-12-241-1/+7
| | | | Change-Id: I6af0d43ab0082e45df676c1d69b26310b59a8031
* fsm: log tweak: upon free, say 'Freeing instance'Neels Hofmeyr2016-12-211-1/+1
| | | | | | | | Logging 'Release' is a bit ambiguous. At first I tought a subscriber connection was being released, IMHO 'Freeing instance' better describes that we are freeing an osmo_fsm_inst. Change-Id: I5cf99707d2ba5620b2988f777fa39cc806ec0212
* utils.h: add OSMO_STRINGIFY and OSMO_VALUE_STRING macrosNeels Hofmeyr2016-12-211-7/+5
| | | | | | | | | | | | | | OSMO_STRINGIFY particularly allows putting port numbers from a #define into VTY doc strings, like: #define FOO_PORT 2342 DEFUN(..., "Foo UDP port (default: " OSMO_STRINGIFY(FOO_PORT) ")\n") OSMO_VALUE_STRING creates value_string items with the string being exactly the enum value's name. Replaces a similar macro def in fsm.c Change-Id: I857af45ae602bb9a647ba26cf8b0d1b23403b54c
* fsm: term: safer iteration to remove all child FSMsNeels Hofmeyr2016-12-201-4/+20
| | | | | | | | | | | | When terminating child FSMs, restart iteration after every child, to make sure that we don't terminate a child twice. Terminating one child may emit events that in turn terminates other children. I created this patch because at first it looked like the cause of a bug, which turned out not to be the case. So I have no actual use case of this situation, but it does generally make sense to me, so submitting this. Change-Id: I00990b47e42eeb43707a9a42abcd9df52fe5f483
* fsm: explicitly log removal from parent fsmNeels Hofmeyr2016-12-161-0/+3
| | | | | | | | | | | Since removing an FSM from its parent twice causes a segfault, it is very interesting to see when that is attempted. Removing could be made more robust, but logging is interesting for investigating why an FSM is being removed twice in the first place (currently the case in openbsc's vlr_lu_fsm). Change-Id: Idec6b7aa5344f1e903c9d2aa2a3640cab0d70fb0
* add value strings for enum osmo_fsm_term_cause and use for loggingNeels Hofmeyr2016-12-151-1/+13
| | | | Change-Id: Iaf63d3cadb0d46bf454e3314ebb439240cafd834
* typo in comment for osmo_fsm_log_addr()Neels Hofmeyr2016-12-141-1/+1
| | | | Change-Id: I6f683ed0c864a87bf1232994eb2deaf9b313a244
* fsm: log caller's source for events and state changes, not fsm.c linesNeels Hofmeyr2016-12-141-17/+45
| | | | | | | | | | | | | | | | | | | | | | | When looking at log output, it is not interesting to see that a state transition's petty details are implemented in fsm.c. Rather log the *caller's* source file and line that caused an event, state change and cascading events. To that end, introduce LOGPSRC() absorbing the guts of LOGP(), to be able to explicitly pass the source file and line information. Prepend an underscore to the function names of osmo_fsm_inst_state_chg(), osmo_fsm_inst_dispatch() and osmo_fsm_inst_term(), and add file and line arguments to them. Provide the previous names as macros that insert the caller's __BASE_FILE__ and __LINE__ constants for the new arguments. Hence no calling code needs to be changed. In fsm.c, add LOGPFSMSRC to call LOGPSRC, and add LOGPFSMLSRC, and use them in above _osmo_fsm_inst_* functions. In addition, in _osmo_fsm_inst_term(), pass the caller's source file and line on to nested event dispatches, so showing where a cascade originated from. Change-Id: Iae72aba7bbf99e19dd584ccabea5867210650dcd
* fsm: add LOGPFSML to pass explicit logging levelNeels Hofmeyr2016-12-141-9/+6
| | | | | | | | | | | | | | Provide one central LOGPFSML to print FSM information, take the FSM logging subsystem from the FSM instance but use an explicitly provided log level instead of the FSM's default level. Use to replace some, essentially, duplications of the LOGPFSM macro. In effect, the fsm_test's expected error changes, since the previous code dup for logging events used round braces to indicate the fi's state, while the central macro uses curly braces. Change-Id: If295fdabb3f31a0fd9490d1e0df57794c75ae547
* Add logging and testing for FSM deallocationMax2016-11-081-0/+1
| | | | | | | | osmo_fsm_inst_alloc() logs allocation but osmo_fsm_inst_free() is silent. Fix this by adding log message for deallocation to make FSM lifecycle tracking easier. Also make sure it's covered by test suite. Change-Id: I7e5b55a1fff8e36cf61c7fb61d3e79c1f00e29d2
* Fix typo in osmo_fsm_log_addr()Max2016-11-011-1/+1
| | | | | | | Previously function parameter was ignored, fsm_log_addr was always set to false. Change-Id: I74f06eab2dfa81dbb95e01f0b4b26448fd1b98f8
* fsm: Make sure we call 'onenter' of new state, not old stateHarald Welte2016-08-011-0/+1
| | | | Change-Id: I1a0181c25d9debe935e86d97ddffc24675e56a5f
* fsm: delete the timer when changing stateHarald Welte2016-07-101-0/+3
| | | | | | | In osmo_fsm_inst_state_chg(), we need to stop any not-yet-expired timer of the old state before transitioning into the new state. Change-Id: I2558f9a7027a877ea8263785ed3c8d70d2513996
* fsm: talloc + copy the 'id' passed into a FSMHarald Welte2016-07-101-1/+2
| | | | | | | | | | The 'id' is used to generate the human-readable name of the FSM. However, when the FSM creates slave FSMs later, the caller-passed "ID" mgiht long be gone again (e.g. it was on stack memory). So let's copy the 'id' string to a chunk of dynamically-allocated memory at time of FSM start to ensure we have it later when creating child FSMs. Change-Id: Ib88a2c02c5c91f17b4ec1e9db57a06d6d66465fb
* fsm: call 'onenter' as last step of a state changeHarald Welte2016-07-101-3/+4
| | | | | | | This is useful to allow the user to terinate the fsm from the onenter() callback. Change-Id: Ia45a1f3279e702028250e10dc54b2d46a4039905
* fsm: Introduce default time-out handlingHarald Welte2016-06-271-8/+13
| | | | | | | | | | | If a FSM doesn't specify any timer_cb, simply terminate the FSM by default on time-out. This is a reasonable default for most cases, and avoids copy+pasting a one-line timer_cb function in every FSM. Also, even if there is a timer_cb, let it have a return value to decide if the core should terminate after return from timer_cb or not. Change-Id: I0461a9593bfb729c82b7d1d1cf9f30b1079d0212
* Add Finite State Machine abstraction codeHarald Welte2016-06-161-0/+422
This code is supposed to formalize some of the state machine handling in Osmocom code. Change-Id: I0b0965a912598c1f6b84042a99fea9d522642466 Reviewed-on: https://gerrit.osmocom.org/163 Tested-by: Jenkins Builder Reviewed-by: Harald Welte <laforge@gnumonks.org>