go-hep.org/x/hep@v0.38.1/fwk/taskbase.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 "reflect" 9 10 "go-hep.org/x/hep/fwk/fsm" 11 ) 12 13 // TaskBase provides a base implementation for fwk.Task 14 type TaskBase struct { 15 t string 16 n string 17 mgr App 18 } 19 20 // NewTask creates a new TaskBase of type typ and name name, 21 // managed by the fwk.App mgr. 22 func NewTask(typ, name string, mgr App) TaskBase { 23 return TaskBase{ 24 t: typ, 25 n: name, 26 mgr: mgr, 27 } 28 } 29 30 // Type returns the fully qualified type of the underlying task. 31 // e.g. "go-hep.org/x/hep/fwk/internal/fwktest.task1" 32 func (tsk *TaskBase) Type() string { 33 return tsk.t 34 } 35 36 // Name returns the name of the underlying task. 37 // e.g. "my-task" 38 func (tsk *TaskBase) Name() string { 39 return tsk.n 40 } 41 42 // DeclInPort declares this task has an input Port with name n and type t. 43 func (tsk *TaskBase) DeclInPort(n string, t reflect.Type) error { 44 return tsk.mgr.DeclInPort(tsk, n, t) 45 } 46 47 // DeclOutPort declares this task has an output Port with name n and type t. 48 func (tsk *TaskBase) DeclOutPort(n string, t reflect.Type) error { 49 return tsk.mgr.DeclOutPort(tsk, n, t) 50 } 51 52 // DeclProp declares this task has a property named n, 53 // and takes a pointer to the associated value. 54 func (tsk *TaskBase) DeclProp(n string, ptr any) error { 55 return tsk.mgr.DeclProp(tsk, n, ptr) 56 } 57 58 // SetProp sets the property name n with the value v. 59 func (tsk *TaskBase) SetProp(n string, v any) error { 60 return tsk.mgr.SetProp(tsk, n, v) 61 } 62 63 // GetProp returns the value of the property named n. 64 func (tsk *TaskBase) GetProp(n string) (any, error) { 65 return tsk.mgr.GetProp(tsk, n) 66 } 67 68 // FSMState returns the current state of the FSM 69 func (tsk *TaskBase) FSMState() fsm.State { 70 return tsk.mgr.FSMState() 71 }