fix
This commit is contained in:
parent
04254def4b
commit
37cb8d89af
@ -1,60 +0,0 @@
|
||||
%%%-------------------------------------------------------------------
|
||||
%%% @author aresei
|
||||
%%% @copyright (C) 2023, <COMPANY>
|
||||
%%% @doc
|
||||
%%% @end
|
||||
%%%-------------------------------------------------------------------
|
||||
-module(iot_device_sup).
|
||||
-include("iot.hrl").
|
||||
|
||||
-behaviour(supervisor).
|
||||
|
||||
-export([start_link/0, init/1, delete_device/1, ensured_device_started/1]).
|
||||
|
||||
start_link() ->
|
||||
supervisor:start_link({local, ?MODULE}, ?MODULE, []).
|
||||
|
||||
init([]) ->
|
||||
%% 启动主机相关的devices
|
||||
{ok, DeviceInfos} = device_bo:get_all_devices(),
|
||||
Specs = lists:map(fun child_spec/1, DeviceInfos),
|
||||
|
||||
{ok, {#{strategy => one_for_one, intensity => 1000, period => 3600}, Specs}}.
|
||||
|
||||
-spec ensured_device_started(UUID :: binary()) -> {ok, Pid :: pid()} | {error, Reason :: any()}.
|
||||
ensured_device_started(DeviceUUID) when is_binary(DeviceUUID) ->
|
||||
case iot_device:get_pid(DeviceUUID) of
|
||||
undefined ->
|
||||
case supervisor:start_child(?MODULE, child_spec(DeviceUUID)) of
|
||||
{ok, Pid} when is_pid(Pid) ->
|
||||
{ok, Pid};
|
||||
{error, {'already_started', Pid}} when is_pid(Pid) ->
|
||||
{ok, Pid};
|
||||
{error, Error} ->
|
||||
{error, Error}
|
||||
end;
|
||||
Pid when is_pid(Pid) ->
|
||||
{ok, Pid}
|
||||
end.
|
||||
|
||||
delete_device(UUID) when is_binary(UUID) ->
|
||||
Id = iot_device:get_name(UUID),
|
||||
ok = supervisor:terminate_child(?MODULE, Id),
|
||||
supervisor:delete_child(?MODULE, Id).
|
||||
|
||||
child_spec(DeviceUUID) when is_binary(DeviceUUID) ->
|
||||
Name = iot_device:get_name(DeviceUUID),
|
||||
#{id => Name,
|
||||
start => {iot_device, start_link, [Name, DeviceUUID]},
|
||||
restart => permanent,
|
||||
shutdown => 2000,
|
||||
type => worker,
|
||||
modules => ['iot_device']};
|
||||
child_spec(DeviceInfo = #{<<"device_uuid">> := DeviceUUID}) when is_binary(DeviceUUID) ->
|
||||
Name = iot_device:get_name(DeviceUUID),
|
||||
#{id => Name,
|
||||
start => {iot_device, start_link, [Name, DeviceInfo]},
|
||||
restart => permanent,
|
||||
shutdown => 2000,
|
||||
type => worker,
|
||||
modules => ['iot_device']}.
|
||||
@ -325,7 +325,7 @@ handle_event({call, From}, {activate_device, DeviceUUID, Auth}, _, State = #stat
|
||||
|
||||
%% 需要将消息转换成json格式然后再处理, 需要在host进程里面处理, 数据带有props,服务端暂时未用到
|
||||
handle_event(cast, {handle, {data, Data}}, ?STATE_ACTIVATED, State = #state{has_session = true}) ->
|
||||
handle_data(Data, State),
|
||||
%handle_data(Data, State),
|
||||
{keep_state, State};
|
||||
|
||||
%% ping的数据是通过aes加密后的,因此需要在有会话的情况下才行
|
||||
|
||||
@ -28,15 +28,6 @@ start_link() ->
|
||||
init([]) ->
|
||||
SupFlags = #{strategy => one_for_one, intensity => 1000, period => 3600},
|
||||
Specs = [
|
||||
#{
|
||||
id => 'iot_device_sup',
|
||||
start => {'iot_device_sup', start_link, []},
|
||||
restart => permanent,
|
||||
shutdown => 2000,
|
||||
type => supervisor,
|
||||
modules => ['iot_device_sup']
|
||||
},
|
||||
|
||||
#{
|
||||
id => 'iot_host_sup',
|
||||
start => {'iot_host_sup', start_link, []},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user