diff --git a/util/blueprint/blueprint.go b/util/blueprint/blueprint.go index 312f01b..af16056 100644 --- a/util/blueprint/blueprint.go +++ b/util/blueprint/blueprint.go @@ -82,9 +82,14 @@ func (bm *Blueprint) Create(graphName string) int64 { if graphName == "" { return 0 } - + graphID := atomic.AddInt64(&bm.seedID, 1) - bm.mapGraph[graphID] = bm.graphPool.Create(graphName, graphID) + gr := bm.graphPool.Create(graphName, graphID) + if gr == nil { + return 0 + } + + bm.mapGraph[graphID] = gr return graphID } diff --git a/util/blueprint/exec.go b/util/blueprint/exec.go index 2d37f61..a4480e5 100644 --- a/util/blueprint/exec.go +++ b/util/blueprint/exec.go @@ -32,8 +32,6 @@ type IExecNode interface { Exec() (int, error) // 返回后续执行的Node的Index GetNextExecLen() int getInnerExecNode() IInnerExecNode - - setVariableName(name string) bool } type innerExecNode struct { @@ -51,7 +49,7 @@ type innerExecNode struct { } type BaseExecNode struct { - *innerExecNode + *innerExecNode // 内部注册的执行结点 // 执行时初始化的数据 *ExecContext @@ -108,26 +106,13 @@ func (bc *BaseExecConfig) GetMaxOutPortId() int { return maxPortId } -//func (em *innerExecNode) AppendInPort(port ...IPort) { -// if len(em.inPort) == 0 { -// em.inPortParamStartIndex = -1 -// } -// -// for i := 0; i < len(port); i++ { -// if !port[i].IsPortExec() && em.inPortParamStartIndex < 0 { -// em.inPortParamStartIndex = len(em.inPort) -// } -// -// em.inPort = append(em.inPort, port[i]) -// } -//} func (em *innerExecNode) PrepareMaxInPortId(maxInPortId int) { - em.inPort = make([]IPort, 0, maxInPortId+1) + em.inPort = make([]IPort, maxInPortId+1) } func (em *innerExecNode) PrepareMaxOutPortId(maxOutPortId int) { - em.outPort = make([]IPort, 0, maxOutPortId+1) + em.outPort = make([]IPort, maxOutPortId+1) } func (em *innerExecNode) SetInPortById(id int, port IPort) bool { @@ -243,6 +228,10 @@ func (em *innerExecNode) GetOutPort(index int) IPort { return em.outPort[index] } +func (en *BaseExecNode) GetVariableName() string { + return en.execNode.variableName +} + func (en *BaseExecNode) GetBluePrintModule() IBlueprintModule { return en.gr.IBlueprintModule } @@ -579,9 +568,6 @@ func (en *BaseExecNode) getInnerExecNode() IInnerExecNode { return en.innerExecNode.IExecNode.(IInnerExecNode) } -func (en *BaseExecNode) setVariableName(name string) bool { - return false -} func (en *BaseExecNode) GetBlueprintModule() IBlueprintModule { if en.gr == nil { diff --git a/util/blueprint/graph.go b/util/blueprint/graph.go index 54bd4d9..3b08f4d 100644 --- a/util/blueprint/graph.go +++ b/util/blueprint/graph.go @@ -6,10 +6,11 @@ import ( "github.com/duanhf2012/origin/v2/service" "github.com/goccy/go-json" + "github.com/duanhf2012/origin/v2/log" ) const ReturnVarial = "g_Return" - +var IsDebug = false type IGraph interface { Do(entranceID int64, args ...any) (Port_Array, error) Release() @@ -28,6 +29,7 @@ type baseGraph struct { } type Graph struct { + graphFileName string graphID int64 *baseGraph graphContext @@ -137,6 +139,10 @@ func (gc *graphConfig) GetNodeByID(nodeID string) *nodeConfig { } func (gr *Graph) Do(entranceID int64, args ...any) (Port_Array, error) { + if IsDebug { + log.Debug("Graph Do", log.String("graphName",gr.graphFileName),log.Int64("graphID", gr.graphID), log.Int64("entranceID", entranceID)) + } + entranceNode := gr.entrance[entranceID] if entranceNode == nil { return nil, fmt.Errorf("entranceID:%d not found", entranceID) diff --git a/util/blueprint/graphpool.go b/util/blueprint/graphpool.go index 112bff8..2e1a953 100644 --- a/util/blueprint/graphpool.go +++ b/util/blueprint/graphpool.go @@ -61,6 +61,7 @@ func (gp *GraphPool) Create(graphName string, graphID int64) IGraph { var graph Graph graph.baseGraph = gr graph.graphID = graphID + graph.graphFileName = graphName graph.context = make(map[string]*ExecContext, 4) graph.IBlueprintModule = gp.blueprintModule return &graph @@ -137,8 +138,6 @@ func (gp *GraphPool) genVarExec(nodeCfg *nodeConfig, graphConfig *graphConfig) ( } e := gp.execPool.GetExec(nodeName) - e.(IExecNode).setVariableName(varName) - return e, varName } diff --git a/util/blueprint/node.go b/util/blueprint/node.go index f26ed79..944a54d 100644 --- a/util/blueprint/node.go +++ b/util/blueprint/node.go @@ -2,6 +2,7 @@ package blueprint import ( "fmt" + "github.com/duanhf2012/origin/v2/log" ) type prePortNode struct { @@ -102,20 +103,6 @@ func (en *execNode) exec(gr *Graph) (int, error) { return -1, err } - //defer func() { - inPort, outPort := node.GetPorts() - debugString := "inPort:" - for i := 0; i < len(inPort); i++ { - debugString += fmt.Sprintf("%+v,", inPort[i]) - } - debugString += " outPort:" - for i := 0; i < len(outPort); i++ { - debugString += fmt.Sprintf("%+v,", outPort[i]) - } - - fmt.Printf("exec node %s,%s\n", en.execNode.GetName(), debugString) - //}() - return e.Exec() } @@ -155,6 +142,10 @@ func (en *execNode) doSetInPort(gr *Graph, index int, inPort IPort) error { } func (en *execNode) Do(gr *Graph, outPortArgs ...any) error { + if IsDebug { + log.Debug("Start ExecNode", log.String("Name",en.execNode.GetName())) + } + // 重新初始化上下文 inPorts, outPorts := en.execNode.CloneInOutPort() gr.context[en.Id] = &ExecContext{ @@ -194,6 +185,10 @@ func (en *execNode) Do(gr *Graph, outPortArgs ...any) error { return err } + if IsDebug { + log.Debug("End ExecNode", log.String("Name",en.execNode.GetName()),log.Any("InPort",inPorts ),log.Any("OutPort",outPorts)) + } + if nextIndex == -1 || en.nextNode == nil { return nil } diff --git a/util/blueprint/port.go b/util/blueprint/port.go index 42ab9f3..9bcd256 100644 --- a/util/blueprint/port.go +++ b/util/blueprint/port.go @@ -213,7 +213,7 @@ func (em *Port[T]) convertInt64(v any) (int64, bool) { func (em *Port[T]) setAnyVale(v any) error { switch v.(type) { - case int, int64: + case int8,int16,int32,int, int64,uint8,uint16,uint32,uint, uint64: val, ok := em.convertInt64(v) if !ok { return fmt.Errorf("port type is %T, but value is %v", em.PortVal, v) diff --git a/util/blueprint/variables.go b/util/blueprint/variables.go index 40194ef..1260692 100644 --- a/util/blueprint/variables.go +++ b/util/blueprint/variables.go @@ -12,13 +12,11 @@ const globalVariablesPrefix = "g_" type GetVariablesNode struct { BaseExecNode nodeName string - varName string } type SetVariablesNode struct { BaseExecNode nodeName string - varName string } func (g *GetVariablesNode) GetName() string { @@ -27,14 +25,14 @@ func (g *GetVariablesNode) GetName() string { func (g *GetVariablesNode) Exec() (int, error) { var port IPort - if strings.HasPrefix(g.varName, globalVariablesPrefix) { - port = g.gr.globalVariables[g.varName] + if strings.HasPrefix(g.GetVariableName(), globalVariablesPrefix) { + port = g.gr.globalVariables[g.GetVariableName()] } else { - port = g.gr.variables[g.varName] + port = g.gr.variables[g.GetVariableName()] } if port == nil { - return -1, fmt.Errorf("variable %s not found,node name %s", g.varName, g.nodeName) + return -1, fmt.Errorf("variable %s not found,node name %s", g.GetVariableName(), g.nodeName) } if !g.SetOutPort(0, port) { @@ -44,10 +42,7 @@ func (g *GetVariablesNode) Exec() (int, error) { return 0, nil } -func (g *GetVariablesNode) setVariableName(name string) bool { - g.varName = name - return true -} + func (g *SetVariablesNode) GetName() string { return g.nodeName @@ -60,10 +55,10 @@ func (g *SetVariablesNode) Exec() (int, error) { } varPort := port.Clone() - if strings.HasPrefix(g.varName, globalVariablesPrefix) { - g.gr.globalVariables[g.varName] = varPort + if strings.HasPrefix(g.GetVariableName(), globalVariablesPrefix) { + g.gr.globalVariables[g.GetVariableName()] = varPort } else { - g.gr.variables[g.varName] = varPort + g.gr.variables[g.GetVariableName()] = varPort } if !g.SetOutPort(1, varPort) { @@ -73,7 +68,3 @@ func (g *SetVariablesNode) Exec() (int, error) { return 0, nil } -func (g *SetVariablesNode) setVariableName(name string) bool { - g.varName = name - return true -}