diff --git a/apps/emqx_gateway/src/bhvrs/emqx_gateway_channel.erl b/apps/emqx_gateway/src/bhvrs/emqx_gateway_channel.erl index abd7391bd..06efe4fd0 100644 --- a/apps/emqx_gateway/src/bhvrs/emqx_gateway_channel.erl +++ b/apps/emqx_gateway/src/bhvrs/emqx_gateway_channel.erl @@ -73,7 +73,11 @@ %% @doc Handle the custom gen_server:call/2 for its connection process -callback handle_call(Req :: any(), channel()) -> {reply, Reply :: any(), channel()} + %% Reply to caller and trigger an event(s) + | {reply, Reply :: any(), + EventOrEvents:: tuple() | list(tuple()), channel()} | {shutdown, Reason :: any(), Reply :: any(), channel()} + %% Shutdown the process, reply to caller and write a packet to client | {shutdown, Reason :: any(), Reply :: any(), emqx_gateway_frame:frame(), channel()}. diff --git a/apps/emqx_gateway/src/bhvrs/emqx_gateway_conn.erl b/apps/emqx_gateway/src/bhvrs/emqx_gateway_conn.erl index 1f5cff043..fa0a830e5 100644 --- a/apps/emqx_gateway/src/bhvrs/emqx_gateway_conn.erl +++ b/apps/emqx_gateway/src/bhvrs/emqx_gateway_conn.erl @@ -550,10 +550,16 @@ handle_call(_From, Req, State = #state{ case ChannMod:handle_call(Req, Channel) of {reply, Reply, NChannel} -> {reply, Reply, State#state{channel = NChannel}}; - {reply, Reply, Replies, NChannel} -> - {reply, Reply, Replies, State#state{channel = NChannel}}; + {reply, Reply, Msgs, NChannel} -> + {reply, Reply, Msgs, State#state{channel = NChannel}}; {shutdown, Reason, Reply, NChannel} -> - shutdown(Reason, Reply, State#state{channel = NChannel}) + shutdown(Reason, Reply, State#state{channel = NChannel}); + {shutdown, Reason, Reply, Packet, NChannel} -> + NState = State#state{channel = NChannel}, + ok = handle_outgoing(Packet, NState), + shutdown(Reason, Reply, NState) + + end. %%-------------------------------------------------------------------- @@ -829,7 +835,6 @@ inc_outgoing_stats(Ctx, FrameMod, Packet) -> %%-------------------------------------------------------------------- %% Helper functions --compile({inline, [next_msgs/1]}). next_msgs(Event) when is_tuple(Event) -> Event; next_msgs(More) when is_list(More) -> diff --git a/apps/emqx_gateway/src/emqx_gateway_cli.erl b/apps/emqx_gateway/src/emqx_gateway_cli.erl index fa2363370..fbd559424 100644 --- a/apps/emqx_gateway/src/emqx_gateway_cli.erl +++ b/apps/emqx_gateway/src/emqx_gateway_cli.erl @@ -50,30 +50,30 @@ is_cmd(Fun) -> %% Cmds gateway(["list"]) -> - lists:foreach(fun(#{id := InstaId, name := Name, type := Type}) -> + lists:foreach(fun(#{type := Type, status := Status}) -> %% FIXME: Get the real running status - emqx_ctl:print("Gateway(~s, name=~s, type=~s, status=running~n", - [InstaId, Name, Type]) + emqx_ctl:print("Gateway(type=~s, status=~s~n", + [Type, Status]) end, emqx_gateway:list()); -gateway(["lookup", GatewayInstaId]) -> - case emqx_gateway:lookup(atom(GatewayInstaId)) of +gateway(["lookup", GwType]) -> + case emqx_gateway:lookup(atom(GwType)) of undefined -> emqx_ctl:print("undefined~n"); Info -> emqx_ctl:print("~p~n", [Info]) end; -gateway(["stop", GatewayInstaId]) -> - case emqx_gateway:stop(atom(GatewayInstaId)) of +gateway(["stop", GwType]) -> + case emqx_gateway:stop(atom(GwType)) of ok -> emqx_ctl:print("ok~n"); {error, Reason} -> emqx_ctl:print("Error: ~p~n", [Reason]) end; -gateway(["start", GatewayInstaId]) -> - case emqx_gateway:start(atom(GatewayInstaId)) of +gateway(["start", GwType]) -> + case emqx_gateway:start(atom(GwType)) of ok -> emqx_ctl:print("ok~n"); {error, Reason} -> @@ -83,12 +83,12 @@ gateway(["start", GatewayInstaId]) -> gateway(_) -> %% TODO: create/remove APIs emqx_ctl:usage([ {"gateway list", - "List all created gateway instances"} - , {"gateway lookup ", + "List all gateway"} + , {"gateway lookup ", "Looup a gateway detailed informations"} - , {"gateway stop ", - "Stop a gateway instance and release all resources"} - , {"gateway start ", + , {"gateway stop ", + "Stop a gateway instance"} + , {"gateway start ", "Start a gateway instance"} ]). @@ -146,8 +146,8 @@ gateway(_) -> end; 'gateway-metrics'(_) -> - emqx_ctl:usage([ {"gateway-metrics ", - "List all metrics for a type of gateway"} + emqx_ctl:usage([ {"gateway-metrics ", + "List all metrics for a gateway"} ]). atom(Id) ->