subsvc.go 688 B

12345678910111213141516171819202122232425262728293031323334
  1. package core
  2. type ISubService interface {
  3. Prepare(ctx *SubServiceContext) error
  4. Run(ctx *SubServiceContext) error
  5. Stop(ctx *SubServiceContext)
  6. }
  7. type SubServiceWrapper struct {
  8. subSvc ISubService
  9. name string
  10. ctx *SubServiceContext
  11. }
  12. func NewSubServiceWrapper(frame IAppFramework, name string, svc ISubService) *SubServiceWrapper {
  13. w := &SubServiceWrapper{
  14. subSvc: svc,
  15. name: name,
  16. ctx: NewSubServiceContext(name, frame),
  17. }
  18. return w
  19. }
  20. func (w *SubServiceWrapper) Prepare() error {
  21. return w.subSvc.Prepare(w.ctx)
  22. }
  23. func (w *SubServiceWrapper) Run() error {
  24. return w.subSvc.Run(w.ctx)
  25. }
  26. func (w *SubServiceWrapper) Stop(xerr error) {
  27. w.subSvc.Stop(w.ctx)
  28. }