2023-10-26 16:41:18 +08:00
|
|
|
package message_server
|
|
|
|
|
|
|
|
import (
|
2024-01-23 09:37:31 +08:00
|
|
|
"log/slog"
|
|
|
|
"sync"
|
|
|
|
|
2024-01-11 10:24:56 +08:00
|
|
|
"joylink.club/bj-rtsts-server/dto/data_proto"
|
2024-01-23 09:37:31 +08:00
|
|
|
"joylink.club/bj-rtsts-server/message_server/ms_api"
|
2023-10-26 17:16:07 +08:00
|
|
|
"joylink.club/bj-rtsts-server/ts/simulation/wayside/memory"
|
2023-10-26 16:41:18 +08:00
|
|
|
)
|
|
|
|
|
2024-01-23 09:37:31 +08:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2023-10-26 16:41:18 +08:00
|
|
|
// 启动仿真所需的消息服务
|
|
|
|
func Start(vs *memory.VerifySimulation) {
|
2024-01-23 09:37:31 +08:00
|
|
|
// 添加仿真状态消息服务
|
|
|
|
_default.AddTasks(vs.SimulationId, NewStateMs(vs))
|
|
|
|
_default.AddTasks(vs.SimulationId, NewTpapiServiceMs(vs))
|
2023-12-25 14:15:22 +08:00
|
|
|
for _, mapId := range vs.MapIds {
|
|
|
|
t := memory.QueryGiType(mapId)
|
|
|
|
switch t {
|
2024-01-11 10:24:56 +08:00
|
|
|
case data_proto.PictureType_StationLayout: // 平面布置图
|
2023-12-25 14:15:22 +08:00
|
|
|
// 添加车站关联的平面布置图、IBP、PSL信息
|
2024-01-23 09:37:31 +08:00
|
|
|
_default.AddTasks(vs.SimulationId, NewSfpMs(vs, mapId), NewIBPMs(vs, mapId), NewPSLMs(vs, mapId))
|
2024-01-11 10:24:56 +08:00
|
|
|
case data_proto.PictureType_RelayCabinetLayout: // 继电器柜
|
2024-01-23 09:37:31 +08:00
|
|
|
_default.AddTasks(vs.SimulationId, NewRccMs(vs, mapId))
|
2024-03-19 08:28:50 +08:00
|
|
|
case data_proto.PictureType_TrainControlCab:
|
2024-03-19 14:49:44 +08:00
|
|
|
_default.AddTasks(vs.SimulationId, NewTrainControlMs(vs, mapId))
|
2023-10-27 14:57:37 +08:00
|
|
|
}
|
2023-10-26 16:41:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 关闭仿真消息服务
|
|
|
|
func Close(vs *memory.VerifySimulation) {
|
2024-01-23 09:37:31 +08:00
|
|
|
_default.RemoveTasks(vs.SimulationId)
|
2023-10-26 17:48:43 +08:00
|
|
|
}
|