/
task1.go
98 lines (78 loc) · 1.66 KB
/
task1.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Copyright ©2017 The go-hep Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"reflect"
"go-hep.org/x/hep/fwk"
)
type task1 struct {
fwk.TaskBase
f1 float64
f2 float64
}
func (tsk *task1) Configure(ctx fwk.Context) error {
var err error
msg := ctx.Msg()
msg.Infof("configure ...\n")
msg.Infof("configure ... [done]\n")
return err
}
func (tsk *task1) StartTask(ctx fwk.Context) error {
msg := ctx.Msg()
msg.Infof("start...\n")
return nil
}
func (tsk *task1) StopTask(ctx fwk.Context) error {
msg := ctx.Msg()
msg.Infof("stop...\n")
return nil
}
func (tsk *task1) Process(ctx fwk.Context) error {
var err error
msg := ctx.Msg()
msg.Infof("proc...\n")
store := ctx.Store()
err = store.Put("floats1", tsk.f1)
if err != nil {
return err
}
err = store.Put("floats2", tsk.f2)
if err != nil {
return err
}
return nil
}
func init() {
fwk.Register(reflect.TypeOf(task1{}),
func(typ, name string, mgr fwk.App) (fwk.Component, error) {
var err error
tsk := &task1{
TaskBase: fwk.NewTask(typ, name, mgr),
f1: -1,
f2: +2,
}
err = tsk.DeclProp("Float1", &tsk.f1)
if err != nil {
return nil, err
}
err = tsk.DeclProp("Float2", &tsk.f2)
if err != nil {
return nil, err
}
err = tsk.SetProp("Float1", 1.)
if err != nil {
return nil, err
}
err = tsk.DeclOutPort("floats1", reflect.TypeOf(float64(1.0)))
if err != nil {
return nil, err
}
err = tsk.DeclOutPort("floats2", reflect.TypeOf(float64(1.0)))
if err != nil {
return nil, err
}
return tsk, err
},
)
}