Skip to content

replace deprecated gen_fsm with gen_statem - #1

Open
tsw2k wants to merge 1 commit into
sigscale:masterfrom
tsw2k:gen_statem
Open

replace deprecated gen_fsm with gen_statem#1
tsw2k wants to merge 1 commit into
sigscale:masterfrom
tsw2k:gen_statem

Conversation

@tsw2k

@tsw2k tsw2k commented Aug 1, 2026

Copy link
Copy Markdown

gen_fsm has been deprecated since OTP 20 and every build emits deprecation
warnings for gtt_as_fsm and its callers. This converts it to gen_statem in
state_functions callback mode, following the shape already used by the tcap
ITU modules.

What changed

  • gtt_as_fsmdown/2, inactive/2, active/2 and pending/2 become
    /3 taking a leading event type. Every event this process receives arrives as
    cast, so the clause bodies are untouched; only the heads changed.
    callback_mode/0 returns [state_functions], and a state() type was added
    for the callback specs.
  • gtt_m3ua_cb — the five catch gen_fsm:send_event(AS, ...) notifications
    become catch gen_statem:cast(AS, ...).
  • gtt_as_fsm_sup — the child spec starts gen_statem:start_link/3.

Notes for review

  • The no-op all-state callbacks were dropped, not carried over. gtt_as_fsm
    had handle_event/3 and handle_sync_event/4 that both returned
    {next_state, StateName, StateData} unchanged. Nothing sends all-state or
    synchronous events to this process, so rather than turn them into a
    handle_event/4 that state_functions mode would never invoke, they were
    removed. If you would rather keep the symmetry with the ITU modules, say so
    and I will add it back.

  • handle_info/3 became a per-state info clause. Each state function now
    ends with StateName(info, _EventContent, _StateData) -> keep_state_and_data.,
    matching both the old no-op and the pattern in tcap_tsm_fsm and
    tcap_dha_fsm.

  • Unexpected events still crash. Because the info clause is the only
    catch-all, an unhandled cast in a given state still fails with
    function_clause, exactly as before. That behaviour is reachable today — for
    example 'M-ASP_ACTIVE' in the down state, or 'M-NOTIFY' at an sg-role
    AS — so it was preserved deliberately rather than softened into a silent
    no-op.

  • pending and timer T(r) are unchanged. pending(timeout, ...) is carried
    over as-is, and the ?Tr macro is still unused: no transition into pending
    arms a timer, so that clause remains unreachable. Wiring up T(r) looked like a
    separate decision, so it is left alone here.

Testing

  • Compiles clean on OTP 29 against m3ua and sccp. Comparing the warning sets
    before and after: the eleven gen_fsm deprecation warnings are gone, no new
    warning appears, and the nine unrelated pre-existing warnings are unchanged.
  • dialyzer reports exactly the same findings as before the change (the
    pre-existing m3ua:register/7, m3ua:cast/9 and status/4 contract
    warnings), with only line numbers shifted.
  • xref reports no undefined function calls.
  • Not run: the SCTP-dependent paths were not exercised. macOS provides no
    SCTP (gen_sctp:open/1 returns {error, eprotonosupport}), so anything that
    needs a live M3UA association should be checked on Linux before merging.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant