fix
This commit is contained in:
parent
3279ff2ebd
commit
2802d9ac32
@ -304,19 +304,21 @@ handle_event({call, From}, {activate, false}, _, State = #state{uuid = UUID, cha
|
|||||||
{next_state, ?STATE_DENIED, State#state{channel_pid = undefined, has_session = false}, [{reply, From, ok}]};
|
{next_state, ?STATE_DENIED, State#state{channel_pid = undefined, has_session = false}, [{reply, From, ok}]};
|
||||||
|
|
||||||
%% 绑定channel
|
%% 绑定channel
|
||||||
handle_event({call, From}, {attach_channel, ChannelPid}, ?STATE_ACTIVATED, State = #state{uuid = UUID, channel_pid = undefined}) ->
|
handle_event({call, From}, {attach_channel, ChannelPid}, StateName, State = #state{uuid = UUID, channel_pid = undefined}) ->
|
||||||
erlang:monitor(process, ChannelPid),
|
case StateName of
|
||||||
%% 更新主机为在线状态
|
?STATE_ACTIVATED ->
|
||||||
{ok, AffectedRow} = host_bo:change_status(UUID, ?HOST_ONLINE),
|
erlang:monitor(process, ChannelPid),
|
||||||
report_event(UUID, ?HOST_ONLINE),
|
%% 更新主机为在线状态
|
||||||
lager:debug("[iot_host] host_id(attach_channel) uuid: ~p, will change status, affected_row: ~p", [UUID, AffectedRow]),
|
{ok, AffectedRow} = host_bo:change_status(UUID, ?HOST_ONLINE),
|
||||||
|
report_event(UUID, ?HOST_ONLINE),
|
||||||
{keep_state, State#state{channel_pid = ChannelPid, has_session = true}, [{reply, From, ok}]};
|
lager:debug("[iot_host] host_id(attach_channel) uuid: ~p, will change status, affected_row: ~p", [UUID, AffectedRow]),
|
||||||
%% 主机没有激活
|
{keep_state, State#state{channel_pid = ChannelPid, has_session = true}, [{reply, From, ok}]};
|
||||||
handle_event({call, From}, {attach_channel, ChannelPid}, ?STATE_DENIED, State = #state{uuid = UUID, channel_pid = undefined}) ->
|
%% 主机未激活
|
||||||
lager:notice("[iot_host] attach_channel host_id uuid: ~p, channel: ~p, host inactivated", [UUID, ChannelPid]),
|
?STATE_DENIED ->
|
||||||
erlang:monitor(process, ChannelPid),
|
lager:notice("[iot_host] attach_channel host_id uuid: ~p, channel: ~p, host inactivated", [UUID, ChannelPid]),
|
||||||
{keep_state, State, [{reply, From, {error, <<"host inactivated">>}}]};
|
erlang:monitor(process, ChannelPid),
|
||||||
|
{keep_state, State#state{channel_pid = ChannelPid}, [{reply, From, {denied, <<"host inactivated">>}}]}
|
||||||
|
end;
|
||||||
%% 已经绑定了channel
|
%% 已经绑定了channel
|
||||||
handle_event({call, From}, {attach_channel, _}, _, State = #state{uuid = UUID, channel_pid = OldChannelPid}) ->
|
handle_event({call, From}, {attach_channel, _}, _, State = #state{uuid = UUID, channel_pid = OldChannelPid}) ->
|
||||||
lager:notice("[iot_host] attach_channel host_id uuid: ~p, old channel exists: ~p", [UUID, OldChannelPid]),
|
lager:notice("[iot_host] attach_channel host_id uuid: ~p, old channel exists: ~p", [UUID, OldChannelPid]),
|
||||||
|
|||||||
@ -108,7 +108,9 @@ handle_info({tcp, Socket, <<?PACKET_REQUEST, PacketId:32, ?METHOD_AUTH:8, AuthRe
|
|||||||
Transport:send(Socket, <<?PACKET_RESPONSE, PacketId:32, 0:8, AuthReplyBin/binary>>),
|
Transport:send(Socket, <<?PACKET_RESPONSE, PacketId:32, 0:8, AuthReplyBin/binary>>),
|
||||||
|
|
||||||
{noreply, State#state{uuid = UUID, host_pid = HostPid}};
|
{noreply, State#state{uuid = UUID, host_pid = HostPid}};
|
||||||
{error, Reason} when is_binary(Reason) ->
|
|
||||||
|
{denied, Reason} when is_binary(Reason) ->
|
||||||
|
erlang:monitor(process, HostPid),
|
||||||
AuthReplyBin = message_pb:encode_msg(#auth_reply{
|
AuthReplyBin = message_pb:encode_msg(#auth_reply{
|
||||||
code = -1,
|
code = -1,
|
||||||
message = Reason,
|
message = Reason,
|
||||||
@ -118,6 +120,18 @@ handle_info({tcp, Socket, <<?PACKET_REQUEST, PacketId:32, ?METHOD_AUTH:8, AuthRe
|
|||||||
|
|
||||||
lager:debug("[ws_channel] uuid: ~p, attach channel get error: ~p, stop channel", [UUID, Reason]),
|
lager:debug("[ws_channel] uuid: ~p, attach channel get error: ~p, stop channel", [UUID, Reason]),
|
||||||
|
|
||||||
|
{noreply, State#state{uuid = UUID, host_pid = HostPid}};
|
||||||
|
|
||||||
|
{error, Reason} when is_binary(Reason) ->
|
||||||
|
AuthReplyBin = message_pb:encode_msg(#auth_reply{
|
||||||
|
code = -2,
|
||||||
|
message = Reason,
|
||||||
|
repository_url = <<"">>
|
||||||
|
}),
|
||||||
|
Transport:send(Socket, <<?PACKET_RESPONSE, PacketId:32, 0:8, AuthReplyBin/binary>>),
|
||||||
|
|
||||||
|
lager:debug("[ws_channel] uuid: ~p, attach channel get error: ~p, stop channel", [UUID, Reason]),
|
||||||
|
|
||||||
{stop, State}
|
{stop, State}
|
||||||
end
|
end
|
||||||
end;
|
end;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user