2023-10-19 09:33:40 +08:00
|
|
|
package third_party
|
|
|
|
|
2024-01-22 13:10:10 +08:00
|
|
|
import (
|
2024-01-23 09:37:31 +08:00
|
|
|
"log/slog"
|
|
|
|
|
2024-01-22 13:10:10 +08:00
|
|
|
"joylink.club/bj-rtsts-server/dto/state_proto"
|
|
|
|
"joylink.club/bj-rtsts-server/third_party/dynamics"
|
2024-01-23 09:37:31 +08:00
|
|
|
"joylink.club/bj-rtsts-server/third_party/semi_physical_train"
|
2024-01-22 13:10:10 +08:00
|
|
|
"joylink.club/bj-rtsts-server/third_party/tpapi"
|
|
|
|
)
|
2023-10-26 15:06:26 +08:00
|
|
|
|
2024-01-23 09:37:31 +08:00
|
|
|
var tpapiService []tpapi.ThirdPartyApiService
|
|
|
|
|
|
|
|
func Init() {
|
|
|
|
tpapiService = append(
|
|
|
|
tpapiService, dynamics.Default(),
|
|
|
|
semi_physical_train.Default(),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetAllServices() []tpapi.ThirdPartyApiService {
|
|
|
|
return tpapiService
|
|
|
|
}
|
|
|
|
|
|
|
|
func convertServiceName(name string) state_proto.SimulationThirdPartyApiService_Type {
|
|
|
|
switch name {
|
|
|
|
case dynamics.Name:
|
|
|
|
return state_proto.SimulationThirdPartyApiService_Dynamics
|
|
|
|
case semi_physical_train.Name:
|
|
|
|
return state_proto.SimulationThirdPartyApiService_SemiPhysicalTrain
|
|
|
|
}
|
|
|
|
return state_proto.SimulationThirdPartyApiService_Undefined
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetRunningServiceStates() *state_proto.SimulationThirdPartyApiService {
|
2024-01-22 13:10:10 +08:00
|
|
|
ss := &state_proto.SimulationThirdPartyApiService{}
|
2024-01-23 09:37:31 +08:00
|
|
|
for _, tpas := range tpapiService {
|
|
|
|
t := convertServiceName(tpas.Name())
|
|
|
|
if t == state_proto.SimulationThirdPartyApiService_Undefined {
|
|
|
|
slog.Error("未知的第三方接口服务类型", "name", tpas.Name())
|
|
|
|
}
|
|
|
|
switch tpas.State() {
|
|
|
|
case tpapi.ThirdPartyState_Normal:
|
|
|
|
ss.States = append(ss.States, &state_proto.SimulationThirdPartyApiServiceState{
|
|
|
|
Type: t,
|
|
|
|
State: state_proto.SimulationThirdPartyApiService_Normal,
|
|
|
|
})
|
|
|
|
case tpapi.ThirdPartyState_Broken:
|
|
|
|
ss.States = append(ss.States, &state_proto.SimulationThirdPartyApiServiceState{
|
|
|
|
Type: t,
|
|
|
|
State: state_proto.SimulationThirdPartyApiService_Error,
|
|
|
|
})
|
|
|
|
}
|
2024-01-22 13:10:10 +08:00
|
|
|
}
|
|
|
|
return ss
|
2023-10-19 09:33:40 +08:00
|
|
|
}
|