rts-sim-testing-service/message_server/simulation_state_ms.go

31 lines
922 B
Go
Raw Normal View History

package message_server
import (
2023-12-26 13:27:09 +08:00
"fmt"
"joylink.club/bj-rtsts-server/dto/state_proto"
2023-12-26 13:27:09 +08:00
2023-12-20 10:37:54 +08:00
"joylink.club/bj-rtsts-server/message_server/ms_api"
"joylink.club/bj-rtsts-server/mqtt"
"joylink.club/bj-rtsts-server/ts/simulation/wayside/memory"
2023-10-27 16:51:48 +08:00
"joylink.club/ecs"
)
2023-12-20 10:37:54 +08:00
func NewStateMs(vs *memory.VerifySimulation) ms_api.MsgTask {
2023-12-26 13:27:09 +08:00
return ms_api.NewMonitorTask(fmt.Sprintf("仿真[%s]状态", vs.SimulationId), func() {
2023-12-20 10:37:54 +08:00
ecs.WorldStateChangeEvent.Subscribe(vs.World, func(_ ecs.World, e ecs.WorldStateChange) {
s := &state_proto.SimulationStatus{SimulationId: vs.SimulationId}
2023-12-20 10:37:54 +08:00
switch e.NewState {
2023-12-25 13:28:24 +08:00
case ecs.WorldClosed:
s.State = state_proto.SimulationStatus_DESTROY
2023-12-20 10:37:54 +08:00
case ecs.WorldError:
s.State = state_proto.SimulationStatus_ERROR
2023-12-20 10:37:54 +08:00
case ecs.WorldPause:
s.State = state_proto.SimulationStatus_PAUSE
2023-12-25 14:15:22 +08:00
default:
return
2023-12-20 10:37:54 +08:00
}
2023-12-25 14:15:22 +08:00
mqtt.GetMsgClient().PubSimulationState(vs.SimulationId, s)
2023-12-20 10:37:54 +08:00
})
2023-10-27 16:51:48 +08:00
})
}