package message_server import ( "log/slog" "sync" "joylink.club/bj-rtsts-server/dto/data_proto" "joylink.club/bj-rtsts-server/message_server/ms_api" "joylink.club/bj-rtsts-server/ts/simulation/wayside/memory" ) var _default = &publishTaskManage{tasks: make(map[string][]ms_api.MsgTask)} // 仿真消息任务管理 type publishTaskManage struct { mu sync.Mutex tasks map[string][]ms_api.MsgTask } func (m *publishTaskManage) AddTasks(simulationId string, tasks ...ms_api.MsgTask) { m.mu.Lock() defer m.mu.Unlock() m.tasks[simulationId] = append(m.tasks[simulationId], tasks...) } func (m *publishTaskManage) RemoveTasks(simulationId string) { m.mu.Lock() defer m.mu.Unlock() slog.Info("停止并移除仿真消息服务", "simulationId", simulationId, "tasks", m.tasks[simulationId]) for _, task := range m.tasks[simulationId] { task.Stop() } delete(m.tasks, simulationId) } // 启动仿真所需的消息服务 func Start(vs *memory.VerifySimulation) { // 添加仿真状态消息服务 _default.AddTasks(vs.SimulationId, NewStateMs(vs)) _default.AddTasks(vs.SimulationId, NewTpapiServiceMs(vs)) for _, mapId := range vs.MapIds { t := memory.QueryGiType(mapId) switch t { case data_proto.PictureType_StationLayout: // 平面布置图 // 添加车站关联的平面布置图、IBP、PSL信息 _default.AddTasks(vs.SimulationId, NewSfpMs(vs, mapId), NewIBPMs(vs, mapId), NewPSLMs(vs, mapId)) case data_proto.PictureType_RelayCabinetLayout: // 继电器柜 _default.AddTasks(vs.SimulationId, NewRccMs(vs, mapId)) case data_proto.PictureType_TrainControlCab: _default.AddTasks(vs.SimulationId, NewTrainControlMs(vs, mapId)) } } } // 关闭仿真消息服务 func Close(vs *memory.VerifySimulation) { _default.RemoveTasks(vs.SimulationId) }