rts-sim-testing-service/message_server/simulation.go
2023-12-20 10:37:54 +08:00

57 lines
1.5 KiB
Go

package message_server
import (
"sync"
"joylink.club/bj-rtsts-server/message_server/ms_api"
"joylink.club/bj-rtsts-server/ts/protos/graphicData"
"joylink.club/bj-rtsts-server/ts/simulation/wayside/memory"
)
var smsMap sync.Map
// 仿真消息服务
// 管理仿真消息服务,整体可以作为一个消息服务,也可以每个消息子服务各自作为一个消息服务,暂时先按整体作为一个消息服务的方式使用
type SimulationMs struct {
vs *memory.VerifySimulation
tasks []ms_api.MsgTask
}
// 启动仿真所需的消息服务
func Start(vs *memory.VerifySimulation) {
_, ok := smsMap.Load(vs.SimulationId)
if !ok {
sms := &SimulationMs{
vs: vs,
tasks: []ms_api.MsgTask{},
//mss: []ms_api.IMsgServer{},
}
for _, mapId := range vs.MapIds {
t := memory.QueryGiType(mapId)
switch t {
case graphicData.PictureType_StationLayout: // 平面布置图
// 添加车站关联的平面布置图、IBP、PSL信息
sms.tasks = append(sms.tasks, NewSfpMs(vs, mapId), NewIBPMs(vs, mapId), NewPSLMs(vs, mapId))
case graphicData.PictureType_RelayCabinetLayout: // 继电器柜
sms.tasks = append(sms.tasks, NewRccMs(vs, mapId))
}
}
// 启动仿真状态服务
sms.tasks = append(sms.tasks, NewStateMs(vs))
smsMap.Store(vs.SimulationId, sms)
}
}
// 关闭仿真消息服务
func Close(vs *memory.VerifySimulation) {
sms, ok := smsMap.Load(vs.SimulationId)
if ok {
ms := sms.(*SimulationMs)
for _, task := range ms.tasks {
task.Stop()
}
ms.tasks = nil
smsMap.Delete(vs.SimulationId)
}
}