rts-sim-testing-service/ats/verify/simulation/wayside/memory/wayside_memory.go
2023-08-01 14:54:11 +08:00

69 lines
1.9 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package memory
import (
"sync"
)
///////////////////////////////////////////////////////////////////////////
// 轨旁仿真模型状态
type VerifyStatus struct {
//道岔状态key为道岔id即索引 state.SwitchState
SwitchStateMap sync.Map
//轨道状态key为轨道id即索引 state.LinkState
LinkStateMap sync.Map
//列车状态key为列车id即索引 state.TrainState
TrainStateMap sync.Map
//计轴区段状态key为计轴区段的id即索引 state.SectionState
AxleSectionStateMap sync.Map
//物理区段状态key为物理区段id即索引 state.SectionState
PhysicalSectionStateMap sync.Map
//逻辑区段状态key为逻辑区段id即索引 state.SectionState
LogicSectionStateMap sync.Map
//信号机状态key为信号机id,即索引 state.SignalState
SignalStateMap sync.Map
}
// 轨旁仿真模型状态(变更)
type ChangeVerifyStatus struct {
VerifyStatus
//删除的列车ID列表
RemoveTrainId []string
}
//////////////////////////////////////////////////////////////////////////
// 轨旁仿真内存模型
type WaysideMemory struct {
//可变状态数据:轨旁仿真模型状态(全量数据)
Status *VerifyStatus
// 要变更的状态:用户操作过的状态记录在这里,增量推送次数据
ChangeStatus *ChangeVerifyStatus
//状态保护锁
rwLock *sync.RWMutex
}
// 初始化轨旁仿真内存模型
func (memory *WaysideMemory) Create() *WaysideMemory {
memory.Status = new(VerifyStatus)
memory.ChangeStatus = &ChangeVerifyStatus{}
memory.rwLock = new(sync.RWMutex)
return memory
}
// 状态读保护操作
func (me *WaysideMemory) SafeOptRead(opt func(memory *WaysideMemory) any) any {
me.rwLock.RLock()
defer me.rwLock.RUnlock()
var rt any = opt(me)
return rt
}
// 状态写保护操作
func (me *WaysideMemory) SafeOptWrite(opt func(memory *WaysideMemory) any) any {
me.rwLock.Lock()
defer me.rwLock.Unlock()
var rt any = opt(me)
return rt
}