Skip to content

Commit

Permalink
feat: add un hook
Browse files Browse the repository at this point in the history
  • Loading branch information
dawnwinterLiu committed Apr 23, 2024
1 parent 202bf36 commit b8e39c0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion apps/dgiot_modbus/src/modbus/modbus_tcp.erl
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ parse_frame(StartAddr, FileName, Data, MinAddr) ->
_ ->
pass
end,
Ncc#{Devaddr1 => #{a => CacheAck, b => Shard_data}};
Ncc#{Devaddr1 => Calculated};
(_, _, Ncc) ->
Ncc
end, #{}, AllData),
Expand Down
19 changes: 19 additions & 0 deletions apps/dgiot_parse/src/dgiot_parse_hook.erl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
do_request_hook/6,
subscribe/3,
subscribe/4,
unsubscribe/3,
unsubscribe/4,
publish/2,
add_trigger/3,
del_trigger/2,
Expand Down Expand Up @@ -58,6 +60,23 @@ subscribe(Table, Method, Channel, Keys) ->
end,
add_hook({Table, Method}).

unsubscribe(Table, Method, Channel) ->
subscribe(Table, Method, Channel, [<<"*">>]).

unsubscribe(Table, Method, Channel, Keys) ->
NewKeys =
case Method of
put -> Keys;
_ -> [<<"*">>]
end,
case dgiot_data:get({sub, Table, Method}) of
not_find ->
pass;
Acc ->

dgiot_data:insert({sub, Table, Method}, dgiot_utils:unique_2(Acc -- [{Channel, NewKeys}]))
end.

add_hook(Key) ->
dgiot_hook:add(one_for_one, Key, fun dgiot_parse_hook:do_hook/1).

Expand Down

0 comments on commit b8e39c0

Please sign in to comment.