Renamed SendSignal to Node.Process

gql_cataclysm
noah metz 2023-07-27 01:15:53 -06:00
parent cc807b3982
commit 81c2e11304
6 changed files with 15 additions and 19 deletions

@ -1053,7 +1053,7 @@ var gql_actions ThreadActions = ThreadActions{
} }
context = NewReadContext(ctx) 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 { if err != nil {
return "", err return "", err
} }

@ -35,7 +35,7 @@ var GQLMutationAbort = NewField(func()*graphql.Field {
if node == nil { if node == nil {
return fmt.Errorf("Failed to find ID: %s as child of server thread", id) 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 { if err != nil {
return nil, err return nil, err
@ -98,7 +98,7 @@ var GQLMutationStartChild = NewField(func()*graphql.Field{
} }
signal = NewStartChildSignal(child_id, action) signal = NewStartChildSignal(child_id, action)
return SendSignal(context, ctx.User, parent, signal) return parent.Process(context, ctx.User, signal)
}) })
if err != nil { if err != nil {
return nil, err return nil, err

@ -54,10 +54,6 @@ func TestGQLDB(t * testing.T) {
ctx.Log.Logf("test", "T1_ID: %s", t1.ID) 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) key, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
fatalErr(t, err) fatalErr(t, err)
@ -86,10 +82,10 @@ func TestGQLDB(t * testing.T) {
fatalErr(t, err) fatalErr(t, err)
context = NewReadContext(ctx) 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) fatalErr(t, err)
context = NewReadContext(ctx) context = NewReadContext(ctx)
err = SendSignal(context, gql, gql, AbortSignal) err = gql.Process(context, gql, AbortSignal)
fatalErr(t, err) fatalErr(t, err)
err = ThreadLoop(ctx, gql, "start") err = ThreadLoop(ctx, gql, "start")
@ -125,7 +121,7 @@ func TestGQLDB(t * testing.T) {
if err != nil { if err != nil {
return err return err
} }
SendSignal(context, gql_loaded, gql_loaded, StopSignal) gql_loaded.Process(context, gql_loaded, StopSignal)
return err return err
}) })

@ -139,7 +139,7 @@ func (ext *LockableExt) Process(context *StateContext, node *Node, signal Signal
owner_sent := false owner_sent := false
for _, dependency := range(ext.Dependencies) { for _, dependency := range(ext.Dependencies) {
context.Graph.Log.Logf("signal", "SENDING_TO_DEPENDENCY: %s -> %s", node.ID, dependency.ID) 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 ext.Owner != nil {
if dependency.ID == ext.Owner.ID { if dependency.ID == ext.Owner.ID {
owner_sent = true 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 != nil && owner_sent == false {
if ext.Owner.ID != node.ID { if ext.Owner.ID != node.ID {
context.Graph.Log.Logf("signal", "SENDING_TO_OWNER: %s -> %s", node.ID, ext.Owner.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 return nil
@ -157,7 +157,7 @@ func (ext *LockableExt) Process(context *StateContext, node *Node, signal Signal
case Down: case Down:
err = UseStates(context, node, NewACLInfo(node, []string{"requirements"}), func(context *StateContext) error { err = UseStates(context, node, NewACLInfo(node, []string{"requirements"}), func(context *StateContext) error {
for _, requirement := range(ext.Requirements) { for _, requirement := range(ext.Requirements) {
err := SendSignal(context, requirement, node, signal) err := requirement.Process(context, node, signal)
if err != nil { if err != nil {
return err return err
} }

@ -205,7 +205,7 @@ func Allowed(context *StateContext, principal *Node, action string, node *Node)
// Check that princ is allowed to signal this action, // Check that princ is allowed to signal this action,
// then send the signal to all the extensions of the node // 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() ser, _ := signal.Serialize()
context.Graph.Log.Logf("signal", "SIGNAL: %s - %s", node.ID, string(ser)) context.Graph.Log.Logf("signal", "SIGNAL: %s - %s", node.ID, string(ser))

@ -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 { err = UseStates(context, node, NewACLInfo(node, []string{"parent"}), func(context *StateContext) error {
if ext.Parent != nil { if ext.Parent != nil {
if ext.Parent.ID != node.ID { if ext.Parent.ID != node.ID {
return SendSignal(context, ext.Parent, node, signal) return ext.Parent.Process(context, node, signal)
} }
} }
return nil return nil
@ -314,7 +314,7 @@ func (ext *ThreadExt) Process(context *StateContext, node *Node, signal Signal)
case Down: case Down:
err = UseStates(context, node, NewACLInfo(node, []string{"children"}), func(context *StateContext) error { err = UseStates(context, node, NewACLInfo(node, []string{"children"}), func(context *StateContext) error {
for _, info := range(ext.Children) { for _, info := range(ext.Children) {
err := SendSignal(context, info.Child, node, signal) err := info.Child.Process(context, node, signal)
if err != nil { if err != nil {
return err return err
} }
@ -659,7 +659,7 @@ func ThreadStart(ctx * Context, thread *Node, thread_ext *ThreadExt) (string, er
} }
context = NewReadContext(ctx) 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) { 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 // 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) { func ThreadAbort(ctx * Context, thread *Node, thread_ext *ThreadExt, signal Signal) (string, error) {
context := NewReadContext(ctx) context := NewReadContext(ctx)
err := SendSignal(context, thread, thread, NewStatusSignal("aborted", thread.ID)) err := thread.Process(context, thread, NewStatusSignal("aborted", thread.ID))
if err != nil { if err != nil {
return "", err 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 // 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) { func ThreadStop(ctx * Context, thread *Node, thread_ext *ThreadExt, signal Signal) (string, error) {
context := NewReadContext(ctx) context := NewReadContext(ctx)
err := SendSignal(context, thread, thread, NewStatusSignal("stopped", thread.ID)) err := thread.Process(context, thread, NewStatusSignal("stopped", thread.ID))
return "finish", err return "finish", err
} }