fix device
This commit is contained in:
parent
c92bfb70dd
commit
c92f3ec921
@ -49,8 +49,8 @@ is_activated(undefined) ->
|
||||
is_activated(Pid) when is_pid(Pid) ->
|
||||
gen_statem:call(Pid, is_activated).
|
||||
|
||||
-spec change_status(Pid :: pid(), NewStatus :: integer()) -> no_return().
|
||||
change_status(undefined, _NewStatus) ->
|
||||
-spec change_status(Pid :: pid() | undefined, NewStatus :: integer()) -> no_return().
|
||||
change_status(undefined, _) ->
|
||||
ok;
|
||||
change_status(Pid, NewStatus) when is_pid(Pid), is_integer(NewStatus) ->
|
||||
gen_statem:cast(Pid, {change_status, NewStatus}).
|
||||
@ -114,19 +114,12 @@ callback_mode() ->
|
||||
handle_event({call, From}, is_activated, StateName, State = #state{}) ->
|
||||
{keep_state, State, [{reply, From, StateName =:= ?STATE_ACTIVATED}]};
|
||||
|
||||
%% 改变数据库的状态, 离线状态事件必须执行(主动触发离线的情况很少,不会造成数据库眼里)
|
||||
handle_event(cast, {change_status, ?DEVICE_OFFLINE}, ?STATE_ACTIVATED, State = #state{device_uuid = DeviceUUID}) ->
|
||||
{ok, _} = device_bo:change_status(DeviceUUID, ?DEVICE_OFFLINE),
|
||||
{keep_state, State#state{status = ?DEVICE_OFFLINE}};
|
||||
%% 改变为在线状态,但是数据库中的状态已经是在线状态,忽略
|
||||
handle_event(cast, {change_status, ?DEVICE_ONLINE}, ?STATE_ACTIVATED, State = #state{status = ?DEVICE_ONLINE}) ->
|
||||
{keep_state, State};
|
||||
%% 其他情况下需要修改数据状态为在线状态
|
||||
handle_event(cast, {change_status, ?DEVICE_ONLINE}, ?STATE_ACTIVATED, State = #state{device_uuid = DeviceUUID}) ->
|
||||
{ok, _} = device_bo:change_status(DeviceUUID, ?DEVICE_ONLINE),
|
||||
{keep_state, State#state{status = ?DEVICE_ONLINE}};
|
||||
%% 其他状态下不存在在线状态的变化
|
||||
handle_event(cast, {change_status, _}, _, State = #state{}) ->
|
||||
%% 改变数据库的状态, 其他情况下执行次数都很少
|
||||
handle_event(cast, {change_status, NewStatus}, _, State = #state{device_uuid = DeviceUUID}) ->
|
||||
{ok, _} = device_bo:change_status(DeviceUUID, NewStatus),
|
||||
{keep_state, State};
|
||||
|
||||
%% 重新加载数据库数据
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user