github.com/erda-project/erda-infra@v1.0.9/providers/component-protocol/cptype/component_default.go (about) 1 // Copyright (c) 2021 Terminus, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package cptype 16 17 // IDefaultComponent std component's default impl should implement this interface. 18 type IDefaultComponent interface { 19 CompStdStructuredPtrCreator 20 CompNonBaseOperationRegister 21 CompFrameworkSteper 22 CompEncoder 23 CompDecoder 24 } 25 26 // CompStdStructuredPtrCreator return creator of StdStructuredPtr. 27 type CompStdStructuredPtrCreator interface { 28 StdStructuredPtrCreator() func() IStdStructuredPtr 29 } 30 31 // IStdStructuredPtr represents std structured pointer type. 32 type IStdStructuredPtr interface { 33 DataPtr() interface{} 34 StatePtr() interface{} 35 InParamsPtr() interface{} 36 } 37 38 // CompNonBaseOperationRegister includes a component's all non-base operations. 39 type CompNonBaseOperationRegister interface { 40 CompStdOperationRegister 41 CompNonStdOperationRegister 42 } 43 44 // CompStdOperationRegister register a component's all standard operations to standard cptype.OperationFunc, 45 // and then used by framework. 46 type CompStdOperationRegister interface { 47 RegisterCompStdOps() (opFuncs map[OperationKey]OperationFunc) 48 } 49 50 // CompNonStdOperationRegister register a component's all non-standard operations to standard cptype.OperationFunc, 51 // and then used by framework. 52 type CompNonStdOperationRegister interface { 53 RegisterCompNonStdOps() (opFuncs map[OperationKey]OperationFunc) 54 } 55 56 // CompFrameworkSteper represents all component steps played in framework. 57 type CompFrameworkSteper interface { 58 Initialize(sdk *SDK) 59 Finalize(sdk *SDK) 60 SkipOp(sdk *SDK) bool 61 Visible(sdk *SDK) bool 62 BeforeHandleOp(sdk *SDK) 63 AfterHandleOp(sdk *SDK) 64 } 65 66 // CompEncoder is a protocol-level interface, convert structured-struct to raw-cp-result. 67 // encode std-struct-ptr to raw-ptr. 68 type CompEncoder interface { 69 EncodeData(srcStdStructPtr interface{}, dstRawPtr *ComponentData) 70 EncodeState(srcStdStructPtr interface{}, dstRawPtr *ComponentState) 71 EncodeInParams(srcStdStructPtr interface{}, dstRawPtr *InParams) 72 } 73 74 // CompDecoder is a protocol-level interface, convert raw-cp-result to structured-struct. 75 // decode raw-ptr to std-struct-ptr. 76 type CompDecoder interface { 77 DecodeData(srcRawPtr ComponentData, dstStdStructPtr interface{}) 78 DecodeState(srcRawPtr ComponentState, dstStdStructPtr interface{}) 79 DecodeInParams(srcRawPtr InParams, dstStdStructPtr interface{}) 80 }