Skip to content

Commit

Permalink
Finish renaming Handler to ModState
Browse files Browse the repository at this point in the history
It is module-specific state.
  • Loading branch information
chrzaszcz committed Feb 9, 2023
1 parent b7e6f3b commit cb60d77
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
20 changes: 10 additions & 10 deletions src/c2s/mongoose_c2s.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1039,24 +1039,24 @@ get_lang(#c2s_data{lang = Lang}) ->
get_stream_id(#c2s_data{streamid = StreamId}) ->
StreamId.

-spec get_mod_state(data(), atom()) -> {ok, term()} | {error, not_found}.
get_mod_state(#c2s_data{state_mod = Handlers}, HandlerName) ->
case maps:get(HandlerName, Handlers, undefined) of
-spec get_mod_state(data(), module()) -> {ok, term()} | {error, not_found}.
get_mod_state(#c2s_data{state_mod = ModStates}, ModName) ->
case maps:get(ModName, ModStates, undefined) of
undefined -> {error, not_found};
HandlerState -> {ok, HandlerState}
ModState -> {ok, ModState}
end.

-spec get_listener_opts(data()) -> listener_opts().
get_listener_opts(#c2s_data{listener_opts = ListenerOpts}) ->
ListenerOpts.

-spec merge_mod_state(data(), map()) -> data().
merge_mod_state(StateData = #c2s_data{state_mod = StateHandlers}, MoreHandlers) ->
StateData#c2s_data{state_mod = maps:merge(StateHandlers, MoreHandlers)}.
-spec merge_mod_state(data(), #{module() => term()}) -> data().
merge_mod_state(StateData = #c2s_data{state_mod = ModStates}, MoreModStates) ->
StateData#c2s_data{state_mod = maps:merge(ModStates, MoreModStates)}.

-spec remove_mod_state(data(), atom()) -> data().
remove_mod_state(StateData = #c2s_data{state_mod = Handlers}, HandlerName) ->
StateData#c2s_data{state_mod = maps:remove(HandlerName, Handlers)}.
-spec remove_mod_state(data(), module()) -> data().
remove_mod_state(StateData = #c2s_data{state_mod = ModStates}, ModName) ->
StateData#c2s_data{state_mod = maps:remove(ModName, ModStates)}.

-spec merge_states(data(), data()) -> data().
merge_states(S0 = #c2s_data{}, S1 = #c2s_data{}) ->
Expand Down
4 changes: 2 additions & 2 deletions src/c2s/mongoose_c2s_acc.erl
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ to_acc_many(Acc, C2SAcc, [Pair | Pairs]) ->
to_acc_many(Acc, NewCAcc, Pairs).

-spec to_c2s_acc(mongoose_c2s_acc:t(), pair()) -> mongoose_c2s_acc:t().
to_c2s_acc(C2SAcc = #{state_mod := Handlers}, {state_mod, {Name, Handler}}) ->
C2SAcc#{state_mod := Handlers#{Name => Handler}};
to_c2s_acc(C2SAcc = #{state_mod := ModStates}, {state_mod, {ModName, ModState}}) ->
C2SAcc#{state_mod := ModStates#{ModName => ModState}};
to_c2s_acc(C2SAcc = #{actions := Actions}, {actions, NewActions}) when is_list(NewActions) ->
C2SAcc#{actions := lists:reverse(NewActions) ++ Actions};
to_c2s_acc(C2SAcc = #{actions := Actions}, {actions, Action}) ->
Expand Down

0 comments on commit cb60d77

Please sign in to comment.