package third_party import ( "log/slog" "joylink.club/bj-rtsts-server/dto/state_proto" "joylink.club/bj-rtsts-server/third_party/dynamics" "joylink.club/bj-rtsts-server/third_party/semi_physical_train" "joylink.club/bj-rtsts-server/third_party/tpapi" ) 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 default: return state_proto.SimulationThirdPartyApiService_Undefined } } func GetRunningServiceStates() *state_proto.SimulationThirdPartyApiService { ss := &state_proto.SimulationThirdPartyApiService{} for _, tpas := range tpapiService { t := convertServiceName(tpas.Name()) if t == state_proto.SimulationThirdPartyApiService_Undefined { slog.Error("未知的第三方接口服务类型", "name", tpas.Name()) continue } 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, }) } } return ss }