From b8520bfeefcdea4f5dfd2eebee7017f8f16dfbc9 Mon Sep 17 00:00:00 2001 From: Simon Thelen Date: Thu, 18 Jul 2024 10:26:10 +0200 Subject: [PATCH] Forward potential errors from registerStaticReceiverProxy up through RegisterUseCase. These errors are currently always API misuse, but it might be nice to extend RegisterUseCase to allow returning errors anyway. --- cmd/remote/main.go | 33 +++++++++++++++++++++++++++------ cmd/remote/ucs.go | 4 ++-- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/cmd/remote/main.go b/cmd/remote/main.go index b04f45d4..d1604b7b 100644 --- a/cmd/remote/main.go +++ b/cmd/remote/main.go @@ -15,7 +15,8 @@ import ( "github.com/enbility/eebus-go/api" "github.com/enbility/eebus-go/usecases/cem/evcc" "github.com/enbility/eebus-go/usecases/cem/evsecc" - "github.com/enbility/eebus-go/usecases/eg/lpc" + cslpc "github.com/enbility/eebus-go/usecases/cs/lpc" + eglpc "github.com/enbility/eebus-go/usecases/eg/lpc" "github.com/enbility/eebus-go/usecases/ma/mpc" shipapi "github.com/enbility/ship-go/api" "github.com/enbility/ship-go/cert" @@ -111,18 +112,38 @@ func main() { log.Fatal(err) } - r.RegisterUseCase(model.EntityTypeTypeCEM, "EG-LPC", func(localEntity spineapi.EntityLocalInterface, eventCB api.EntityEventCallback) api.UseCaseInterface { - return lpc.NewLPC(localEntity, eventCB) }) - r.RegisterUseCase(model.EntityTypeTypeCEM, "MA-MPC", func(localEntity spineapi.EntityLocalInterface, eventCB api.EntityEventCallback) api.UseCaseInterface { + if err != nil { + log.Fatal(err) + } + + err = r.RegisterUseCase(model.EntityTypeTypeCEM, "EG-LPC", func(localEntity spineapi.EntityLocalInterface, eventCB api.EntityEventCallback) api.UseCaseInterface { + return eglpc.NewLPC(localEntity, eventCB) + }) + if err != nil { + log.Fatal(err) + } + + err = r.RegisterUseCase(model.EntityTypeTypeCEM, "MA-MPC", func(localEntity spineapi.EntityLocalInterface, eventCB api.EntityEventCallback) api.UseCaseInterface { return mpc.NewMPC(localEntity, eventCB) }) - r.RegisterUseCase(model.EntityTypeTypeCEM, "CEM-EVCC", func(localEntity spineapi.EntityLocalInterface, eventCB api.EntityEventCallback) api.UseCaseInterface { + if err != nil { + log.Fatal(err) + } + + err = r.RegisterUseCase(model.EntityTypeTypeCEM, "CEM-EVCC", func(localEntity spineapi.EntityLocalInterface, eventCB api.EntityEventCallback) api.UseCaseInterface { return evcc.NewEVCC(r.service, localEntity, eventCB) }) - r.RegisterUseCase(model.EntityTypeTypeCEM, "CEM-EVSECC", func(localEntity spineapi.EntityLocalInterface, eventCB api.EntityEventCallback) api.UseCaseInterface { + if err != nil { + log.Fatal(err) + } + + err = r.RegisterUseCase(model.EntityTypeTypeCEM, "CEM-EVSECC", func(localEntity spineapi.EntityLocalInterface, eventCB api.EntityEventCallback) api.UseCaseInterface { return evsecc.NewEVSECC(localEntity, eventCB) }) + if err != nil { + log.Fatal(err) + } ctx, cancelCtx := context.WithCancel(context.Background()) if err = r.Listen(ctx, "tcp", net.JoinHostPort("::", strconv.Itoa(3393))); err != nil { diff --git a/cmd/remote/ucs.go b/cmd/remote/ucs.go index 224cefa3..d1eead23 100644 --- a/cmd/remote/ucs.go +++ b/cmd/remote/ucs.go @@ -18,7 +18,7 @@ const ( type UseCaseBuilder func(spineapi.EntityLocalInterface, api.EntityEventCallback) api.UseCaseInterface -func (r *Remote) RegisterUseCase(entityType model.EntityTypeType, usecaseId string, builder UseCaseBuilder) { +func (r *Remote) RegisterUseCase(entityType model.EntityTypeType, usecaseId string, builder UseCaseBuilder) error { // entityType/uc var identifier UseCaseId = UseCaseId(fmt.Sprintf("%s/%s", entityType, usecaseId)) @@ -33,7 +33,7 @@ func (r *Remote) RegisterUseCase(entityType model.EntityTypeType, usecaseId stri }) r.service.AddUseCase(uc) - r.registerStaticReceiverProxy(usecaseId, uc) + return r.registerStaticReceiverProxy(usecaseId, uc) } func (r *Remote) PropagateEvent(