Merge "mecm-mepm uninstall playbook added"
[ealt-edge.git] / mep / mepserver / mp1 / arch / workspace / task_base.go
1 /*
2  * Copyright 2020 Huawei Technologies Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17
18 package workspace
19
20 type TaskBaseIf interface {
21         OnRequest(data string) TaskCode
22         Parse(params string)
23         OnFork(wkSpace interface{}, param interface{}) int
24         GetErrCode() (ErrCode, string)
25         OnStop() int
26         WithName(name string)
27         SetSerErrInfo(serErr *SerErrInfo)
28 }
29
30 type TaskBase struct {
31         serErr     *SerErrInfo
32         errMsg     string
33         Name       string
34         Param      []string
35         resultCode ErrCode
36 }
37
38 func (t *TaskBase) WithName(name string) {
39         t.Name = name
40 }
41
42 func (t *TaskBase) Parse(params string) {
43         t.Param = append(t.Param, params)
44 }
45
46 func (t *TaskBase) OnFork(wkSpace interface{}, param interface{}) int {
47         return 0
48 }
49
50 func (t *TaskBase) OnStop() int {
51         return 0
52 }
53
54 type TaskCode int
55
56 const (
57         TaskFinish TaskCode = iota
58         TaskWaitMore
59         TaskError
60 )
61
62 func (t *TaskBase) OnRequest(wkSpace interface{}) TaskCode {
63         return TaskFinish
64 }
65
66 func (t *TaskBase) SetFirstErrorCode(code ErrCode, msg string) {
67         if t.resultCode > TaskOK {
68                 return
69         }
70         t.resultCode = code
71         t.errMsg = msg
72 }
73
74 func (t *TaskBase) GetErrCode() (ErrCode, string) {
75         return t.resultCode, t.errMsg
76 }
77
78 func (t *TaskBase) SetSerErrInfo(serErr *SerErrInfo) {
79         t.serErr = serErr
80 }
81
82 func (t *TaskBase) GetSerErrInfo() *SerErrInfo {
83         return t.serErr
84 }
85
86 type StepMap map[string]interface{}
87
88 var StepData StepMap = StepMap{}
89
90 func NameMap(name string, obj interface{}, listenOn string) bool {
91         StepData[name] = obj
92         return true
93 }