diff --git a/gql.go b/gql.go index 7c00608..004ef4f 100644 --- a/gql.go +++ b/gql.go @@ -1053,7 +1053,7 @@ var gql_actions ThreadActions = ThreadActions{ } context = NewReadContext(ctx) - err = SendSignal(context, thread, thread, NewStatusSignal("server_started", thread.ID)) + err = thread.Process(context, thread, NewStatusSignal("server_started", thread.ID)) if err != nil { return "", err } diff --git a/gql_mutation.go b/gql_mutation.go index 3d7d760..00e5165 100644 --- a/gql_mutation.go +++ b/gql_mutation.go @@ -35,7 +35,7 @@ var GQLMutationAbort = NewField(func()*graphql.Field { if node == nil { return fmt.Errorf("Failed to find ID: %s as child of server thread", id) } - return SendSignal(context, node, ctx.User, AbortSignal) + return node.Process(context, ctx.User, AbortSignal) }) if err != nil { return nil, err @@ -98,7 +98,7 @@ var GQLMutationStartChild = NewField(func()*graphql.Field{ } signal = NewStartChildSignal(child_id, action) - return SendSignal(context, ctx.User, parent, signal) + return parent.Process(context, ctx.User, signal) }) if err != nil { return nil, err diff --git a/gql_test.go b/gql_test.go index 8a9151d..a5efc45 100644 --- a/gql_test.go +++ b/gql_test.go @@ -54,10 +54,6 @@ func TestGQLDB(t * testing.T) { ctx.Log.Logf("test", "T1_ID: %s", t1.ID) - TestGQLNodeType := NodeType("TEST_GQL") - err = ctx.RegisterNodeType(TestGQLNodeType, []ExtType{ACLExtType, ACLPolicyExtType, GroupExtType, GQLExtType, ThreadExtType, LockableExtType}) - fatalErr(t, err) - key, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) fatalErr(t, err) @@ -86,10 +82,10 @@ func TestGQLDB(t * testing.T) { fatalErr(t, err) context = NewReadContext(ctx) - err = SendSignal(context, gql, gql, NewStatusSignal("child_linked", t1.ID)) + err = gql.Process(context, gql, NewStatusSignal("child_linked", t1.ID)) fatalErr(t, err) context = NewReadContext(ctx) - err = SendSignal(context, gql, gql, AbortSignal) + err = gql.Process(context, gql, AbortSignal) fatalErr(t, err) err = ThreadLoop(ctx, gql, "start") @@ -125,7 +121,7 @@ func TestGQLDB(t * testing.T) { if err != nil { return err } - SendSignal(context, gql_loaded, gql_loaded, StopSignal) + gql_loaded.Process(context, gql_loaded, StopSignal) return err }) diff --git a/lockable.go b/lockable.go index ce777f6..9141eb8 100644 --- a/lockable.go +++ b/lockable.go @@ -139,7 +139,7 @@ func (ext *LockableExt) Process(context *StateContext, node *Node, signal Signal owner_sent := false for _, dependency := range(ext.Dependencies) { context.Graph.Log.Logf("signal", "SENDING_TO_DEPENDENCY: %s -> %s", node.ID, dependency.ID) - SendSignal(context, dependency, node, signal) + dependency.Process(context, node, signal) if ext.Owner != nil { if dependency.ID == ext.Owner.ID { owner_sent = true @@ -149,7 +149,7 @@ func (ext *LockableExt) Process(context *StateContext, node *Node, signal Signal if ext.Owner != nil && owner_sent == false { if ext.Owner.ID != node.ID { context.Graph.Log.Logf("signal", "SENDING_TO_OWNER: %s -> %s", node.ID, ext.Owner.ID) - return SendSignal(context, ext.Owner, node, signal) + return ext.Owner.Process(context, node, signal) } } return nil @@ -157,7 +157,7 @@ func (ext *LockableExt) Process(context *StateContext, node *Node, signal Signal case Down: err = UseStates(context, node, NewACLInfo(node, []string{"requirements"}), func(context *StateContext) error { for _, requirement := range(ext.Requirements) { - err := SendSignal(context, requirement, node, signal) + err := requirement.Process(context, node, signal) if err != nil { return err } diff --git a/node.go b/node.go index e49ea48..b8b7dfe 100644 --- a/node.go +++ b/node.go @@ -205,7 +205,7 @@ func Allowed(context *StateContext, principal *Node, action string, node *Node) // Check that princ is allowed to signal this action, // then send the signal to all the extensions of the node -func SendSignal(context *StateContext, node *Node, princ *Node, signal Signal) error { +func (node *Node) Process(context *StateContext, princ *Node, signal Signal) error { ser, _ := signal.Serialize() context.Graph.Log.Logf("signal", "SIGNAL: %s - %s", node.ID, string(ser)) diff --git a/thread.go b/thread.go index 4c804cf..1643054 100644 --- a/thread.go +++ b/thread.go @@ -306,7 +306,7 @@ func (ext *ThreadExt) Process(context *StateContext, node *Node, signal Signal) err = UseStates(context, node, NewACLInfo(node, []string{"parent"}), func(context *StateContext) error { if ext.Parent != nil { if ext.Parent.ID != node.ID { - return SendSignal(context, ext.Parent, node, signal) + return ext.Parent.Process(context, node, signal) } } return nil @@ -314,7 +314,7 @@ func (ext *ThreadExt) Process(context *StateContext, node *Node, signal Signal) case Down: err = UseStates(context, node, NewACLInfo(node, []string{"children"}), func(context *StateContext) error { for _, info := range(ext.Children) { - err := SendSignal(context, info.Child, node, signal) + err := info.Child.Process(context, node, signal) if err != nil { return err } @@ -659,7 +659,7 @@ func ThreadStart(ctx * Context, thread *Node, thread_ext *ThreadExt) (string, er } context = NewReadContext(ctx) - return "wait", SendSignal(context, thread, thread, NewStatusSignal("started", thread.ID)) + return "wait", thread.Process(context, thread, NewStatusSignal("started", thread.ID)) } func ThreadWait(ctx * Context, thread *Node, thread_ext *ThreadExt) (string, error) { @@ -708,7 +708,7 @@ var ThreadAbortedError = errors.New("Thread aborted by signal") // Default thread action function for "abort", sends a signal and returns a ThreadAbortedError func ThreadAbort(ctx * Context, thread *Node, thread_ext *ThreadExt, signal Signal) (string, error) { context := NewReadContext(ctx) - err := SendSignal(context, thread, thread, NewStatusSignal("aborted", thread.ID)) + err := thread.Process(context, thread, NewStatusSignal("aborted", thread.ID)) if err != nil { return "", err } @@ -718,7 +718,7 @@ func ThreadAbort(ctx * Context, thread *Node, thread_ext *ThreadExt, signal Sign // Default thread action for "stop", sends a signal and returns no error func ThreadStop(ctx * Context, thread *Node, thread_ext *ThreadExt, signal Signal) (string, error) { context := NewReadContext(ctx) - err := SendSignal(context, thread, thread, NewStatusSignal("stopped", thread.ID)) + err := thread.Process(context, thread, NewStatusSignal("stopped", thread.ID)) return "finish", err }