go-hep.org/x/hep@v0.38.1/fwk/svcbase.go (about)

     1  // Copyright ©2017 The go-hep Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package fwk
     6  
     7  import (
     8  	"go-hep.org/x/hep/fwk/fsm"
     9  )
    10  
    11  // SvcBase provides a base implementation for fwk.Svc
    12  type SvcBase struct {
    13  	t   string
    14  	n   string
    15  	mgr App
    16  }
    17  
    18  // NewSvc creates a new SvcBase of type typ and name name,
    19  // managed by the fwk.App mgr.
    20  func NewSvc(typ, name string, mgr App) SvcBase {
    21  	return SvcBase{
    22  		t:   typ,
    23  		n:   name,
    24  		mgr: mgr,
    25  	}
    26  }
    27  
    28  // Type returns the fully qualified type of the underlying service.
    29  // e.g. "go-hep.org/x/hep/fwk/internal/fwktest.svc1"
    30  func (svc *SvcBase) Type() string {
    31  	return svc.t
    32  }
    33  
    34  // Name returns the name of the underlying service.
    35  // e.g. "my-service"
    36  func (svc *SvcBase) Name() string {
    37  	return svc.n
    38  }
    39  
    40  // DeclProp declares this service has a property named n,
    41  // and takes a pointer to the associated value.
    42  func (svc *SvcBase) DeclProp(n string, ptr any) error {
    43  	return svc.mgr.DeclProp(svc, n, ptr)
    44  }
    45  
    46  // SetProp sets the property name n with the value v.
    47  func (svc *SvcBase) SetProp(name string, value any) error {
    48  	return svc.mgr.SetProp(svc, name, value)
    49  }
    50  
    51  // GetProp returns the value of the property named n.
    52  func (svc *SvcBase) GetProp(name string) (any, error) {
    53  	return svc.mgr.GetProp(svc, name)
    54  }
    55  
    56  // FSMState returns the current state of the FSM
    57  func (svc *SvcBase) FSMState() fsm.State {
    58  	return svc.mgr.FSMState()
    59  }