refactor: use static function references

This commit is contained in:
Zaiming (Stone) Shi 2022-11-24 19:40:40 +01:00
parent 57c0c9db79
commit cb1c0032a5
2 changed files with 17 additions and 13 deletions

View File

@ -2,7 +2,7 @@
{application, emqx_rule_engine, [
{description, "EMQX Rule Engine"},
% strict semver, bump manually!
{vsn, "5.0.4"},
{vsn, "5.0.5"},
{modules, []},
{registered, [emqx_rule_engine_sup, emqx_rule_engine]},
{applications, [kernel, stdlib, rulesql, getopt]},

View File

@ -89,20 +89,20 @@ reload() ->
load(Topic) ->
HookPoint = event_name(Topic),
emqx_hooks:put(
HookPoint, {?MODULE, hook_fun(HookPoint), [#{event_topic => Topic}]}, ?HP_RULE_ENGINE
HookPoint, {hook_fun(HookPoint), [#{event_topic => Topic}]}, ?HP_RULE_ENGINE
).
unload() ->
lists:foreach(
fun(HookPoint) ->
emqx_hooks:del(HookPoint, {?MODULE, hook_fun(HookPoint)})
emqx_hooks:del(HookPoint, hook_fun(HookPoint))
end,
event_names()
).
unload(Topic) ->
HookPoint = event_name(Topic),
emqx_hooks:del(HookPoint, {?MODULE, hook_fun(HookPoint)}).
emqx_hooks:del(HookPoint, hook_fun(HookPoint)).
%%--------------------------------------------------------------------
%% Callbacks
@ -987,15 +987,19 @@ columns_example_props_specific(unsub_props) ->
%% Helper functions
%%--------------------------------------------------------------------
hook_fun(<<"$bridges/", _/binary>>) ->
on_bridge_message_received;
hook_fun(Event) ->
case string:split(atom_to_list(Event), ".") of
[Prefix, Name] ->
list_to_atom(lists:append(["on_", Prefix, "_", Name]));
[_] ->
error(invalid_event, Event)
end.
hook_fun(<<"$bridges/", _/binary>>) -> fun ?MODULE:on_bridge_message_received/2;
hook_fun('client.connected') -> fun ?MODULE:on_client_connected/3;
hook_fun('client.disconnected') -> fun ?MODULE:on_client_disconnected/4;
hook_fun('client.connack') -> fun ?MODULE:on_client_connack/4;
hook_fun('client.check_authz_complete') -> fun ?MODULE:on_client_check_authz_complete/6;
hook_fun('session.subscribed') -> fun ?MODULE:on_session_subscribed/4;
hook_fun('session.unsubscribed') -> fun ?MODULE:on_session_unsubscribed/4;
hook_fun('message.delivered') -> fun ?MODULE:on_message_delivered/3;
hook_fun('message.acked') -> fun ?MODULE:on_message_acked/3;
hook_fun('message.dropped') -> fun ?MODULE:on_message_dropped/4;
hook_fun('delivery.dropped') -> fun ?MODULE:on_delivery_dropped/4;
hook_fun('message.publish') -> fun ?MODULE:on_message_publish/2;
hook_fun(Event) -> error({invalid_event, Event}).
reason(Reason) when is_atom(Reason) -> Reason;
reason({shutdown, Reason}) when is_atom(Reason) -> Reason;