replace deprecated gen_fsm with gen_statem - #1
Open
tsw2k wants to merge 1 commit into
Open
Conversation
The gen_fsm behaviour has been deprecated since OTP 20. Convert gtt_as_fsm to gen_statem in state_functions callback mode, following the same shape as the tcap ITU modules. * gtt_as_fsm: down/2, inactive/2, active/2 and pending/2 become /3 taking an event type, with the events arriving as cast. Each state gains a trailing info clause returning keep_state_and_data, which is what the former no-op handle_info/3 did. * The no-op handle_event/3 and handle_sync_event/4 are dropped rather than carried over as an unreachable handle_event/4; nothing sends all-state events to this process. * gtt_m3ua_cb notifies the AS with gen_statem:cast/2. * gtt_as_fsm_sup starts children with gen_statem:start_link/3.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
gen_fsmhas been deprecated since OTP 20 and every build emits deprecationwarnings for
gtt_as_fsmand its callers. This converts it togen_stateminstate_functionscallback mode, following the shape already used by thetcapITU modules.
What changed
gtt_as_fsm—down/2,inactive/2,active/2andpending/2become/3taking a leading event type. Every event this process receives arrives ascast, so the clause bodies are untouched; only the heads changed.callback_mode/0returns[state_functions], and astate()type was addedfor the callback specs.
gtt_m3ua_cb— the fivecatch gen_fsm:send_event(AS, ...)notificationsbecome
catch gen_statem:cast(AS, ...).gtt_as_fsm_sup— the child spec startsgen_statem:start_link/3.Notes for review
The no-op all-state callbacks were dropped, not carried over.
gtt_as_fsmhad
handle_event/3andhandle_sync_event/4that both returned{next_state, StateName, StateData}unchanged. Nothing sends all-state orsynchronous events to this process, so rather than turn them into a
handle_event/4thatstate_functionsmode would never invoke, they wereremoved. If you would rather keep the symmetry with the ITU modules, say so
and I will add it back.
handle_info/3became a per-stateinfoclause. Each state function nowends with
StateName(info, _EventContent, _StateData) -> keep_state_and_data.,matching both the old no-op and the pattern in
tcap_tsm_fsmandtcap_dha_fsm.Unexpected events still crash. Because the info clause is the only
catch-all, an unhandled
castin a given state still fails withfunction_clause, exactly as before. That behaviour is reachable today — forexample
'M-ASP_ACTIVE'in thedownstate, or'M-NOTIFY'at ansg-roleAS — so it was preserved deliberately rather than softened into a silent
no-op.
pendingand timer T(r) are unchanged.pending(timeout, ...)is carriedover as-is, and the
?Trmacro is still unused: no transition intopendingarms a timer, so that clause remains unreachable. Wiring up T(r) looked like a
separate decision, so it is left alone here.
Testing
m3uaandsccp. Comparing the warning setsbefore and after: the eleven
gen_fsmdeprecation warnings are gone, no newwarning appears, and the nine unrelated pre-existing warnings are unchanged.
dialyzerreports exactly the same findings as before the change (thepre-existing
m3ua:register/7,m3ua:cast/9andstatus/4contractwarnings), with only line numbers shifted.
xrefreports no undefined function calls.SCTP (
gen_sctp:open/1returns{error, eprotonosupport}), so anything thatneeds a live M3UA association should be checked on Linux before merging.