From debeed70912a727f3fe8f4005534f1927fe9d385 Mon Sep 17 00:00:00 2001 From: Noah Metz Date: Sat, 3 Jun 2023 21:27:20 -0600 Subject: [PATCH] Updated fake client so that it runs the fake event in main.go --- event.go | 20 ++++++++++++++++---- graph.go | 9 ++++++--- main.go | 20 ++++++++++++++++++-- vex.go | 12 ++++++------ 4 files changed, 46 insertions(+), 15 deletions(-) diff --git a/event.go b/event.go index e232af6..c0d0c2b 100644 --- a/event.go +++ b/event.go @@ -13,11 +13,18 @@ import ( func (event * BaseEvent) update(signal GraphSignal) { event.signal <- signal new_signal := signal.Trace(event.ID()) - if event.parent != nil && signal.Type() != "abort"{ + + if event.parent != nil { SendUpdate(event.parent, new_signal) - } else if signal.Type() == "abort" { - for _, child := range(event.Children()) { - SendUpdate(child, new_signal) + } + + for _, resource := range(event.RequiredResources()) { + source_id := "" + if signal.Source() != nil { + source_id = signal.Source().ID() + } + if source_id != resource.ID() { + SendUpdate(resource, new_signal) } } } @@ -159,6 +166,11 @@ func RunEvent(event Event) error { func AbortEvent(event Event) error { signal := NewSignal(event, "abort") SendUpdate(event, signal) + event.LockChildren() + for _, child := range(event.Children()) { + AbortEvent(child) + } + event.UnlockChildren() return nil } diff --git a/graph.go b/graph.go index c509f75..58b2b87 100644 --- a/graph.go +++ b/graph.go @@ -81,7 +81,7 @@ func NewBaseNode(name string, description string, id string) BaseNode { name: name, description: description, id: id, - signal: make(chan GraphSignal, 100), + signal: make(chan GraphSignal, 1000), listeners: map[chan GraphSignal]chan GraphSignal{}, } log.Printf("NEW_NODE: %s - %s", node.ID(), node.Name()) @@ -112,7 +112,7 @@ func (node * BaseNode) ID() string { } // Create a new listener channel for the node, add it to the nodes listener list, and return the new channel -const listener_buffer = 100 +const listener_buffer = 1000 func (node * BaseNode) UpdateChannel() chan GraphSignal { new_listener := make(chan GraphSignal, listener_buffer) node.RegisterChannel(new_listener) @@ -151,7 +151,10 @@ func (node * BaseNode) UpdateListeners(update GraphSignal) { case listener <- update: default: log.Printf("CLOSED_LISTENER: %s: %p", node.Name(), listener) - close(listener) + go func(node GraphNode, listener chan GraphSignal) { + listener <- NewSignal(node, "listener_closed") + close(listener) + }(node, listener) closed = append(closed, listener) } } diff --git a/main.go b/main.go index 6322b75..024ff08 100644 --- a/main.go +++ b/main.go @@ -126,14 +126,30 @@ func fake_data() (* EventManager, *Arena, *Arena) { } func process_fake_arena(update GraphSignal, arena * Arena) { + if update.Source() != nil { + log.Printf("FAKE_CLIENT_UPDATE: %s -> %+v", update.Source().ID(), update) + } else { + log.Printf("FAKE_CLIENT_UPDATE: %s -> %+v", update.Source(), update) + } if update.Type() == "event_start" { - log.Printf("FAKE_ARENA_ACTION: Match started on %s, queuing autonomous automatically", arena.Name()) + log.Printf("FAKE_CLIENT_ACTION: Match started on %s, queuing autonomous automatically", arena.Name()) SendUpdate(arena, NewSignal(nil, "queue_autonomous")) } else if update.Type() == "autonomous_queued" { - log.Printf("FAKE_ARENA_ACTION: Autonomous queued on %s for %s, starting automatically at requested time", arena.Name(), update.Time()) + log.Printf("FAKE_CLIENT_ACTION: Autonomous queued on %s for %s, starting automatically at requested time", arena.Name(), update.Time()) signal := NewSignal(nil, "start_autonomous") signal.time = update.Time() SendUpdate(arena, signal) + } else if update.Type() == "autonomous_done" { + log.Printf("FAKE_CLIENT_ACTION: Autonomous done on %s for %s, queueing driver automatically", arena.Name(), update.Time()) + signal := NewSignal(nil, "queue_driver") + SendUpdate(arena, signal) + } else if update.Type() == "driver_queued" { + log.Printf("FAKE_CLIENT_ACTION: Driver queueud on %s for %s, starting driver automatically at requested time", arena.Name(), update.Time()) + signal := NewSignal(nil, "start_driver") + signal.time = update.Time() + SendUpdate(arena, signal) + } else if update.Type() == "driver_done" { + log.Printf("FAKE_CLIENT_ACTION: Driver done on %s for %s", arena.Name(), update.Time()) } } diff --git a/vex.go b/vex.go index 705994b..283192a 100644 --- a/vex.go +++ b/vex.go @@ -108,7 +108,7 @@ func (arena * Arena) Connect(abort chan error) bool { log.Printf("Virtual arena %s aborting", arena.Name()) break case update := <- arena.signal: - log.Printf("FAKE_ARENA_ACTION: %s : %+v", arena.Name(), update) + log.Printf("VIRTUAL_ARENA_ACTION: %s : %+v", arena.Name(), update) } } }(arena, abort) @@ -130,9 +130,6 @@ type Match struct { func (match * Match) update(signal GraphSignal) { new_signal := signal.Trace(match.ID()) match.BaseEvent.update(new_signal) - if match.arena.ID() != signal.Last() { - SendUpdate(match.arena, new_signal) - } } func NewMatch(alliance0 * Alliance, alliance1 * Alliance, arena * Arena) * Match { @@ -156,9 +153,10 @@ func NewMatch(alliance0 * Alliance, alliance1 * Alliance, arena * Arena) * Match match.handlers["queue_autonomous"] = func(signal GraphSignal) (string, error) { if match.state != "scheduled" { - log.Printf("BAD_STATE: %s: %s", signal.Type(), match.state) + log.Printf("BAD_STATE: %s: %s - %s", signal.Type(), match.state, match.Name()) return "wait", nil } + log.Printf("AUTONOMOUS_QUEUED: %s", match.Name()) match.control = "none" match.state = "autonomous_queued" match.control_start = time.Now().Add(start_slack) @@ -170,9 +168,10 @@ func NewMatch(alliance0 * Alliance, alliance1 * Alliance, arena * Arena) * Match match.handlers["start_autonomous"] = func(signal GraphSignal) (string, error) { if match.state != "autonomous_queued" { - log.Printf("BAD_STATE: %s: %s", signal.Type(), match.state) + log.Printf("BAD_STATE: %s: %s - %s", signal.Type(), match.state, match.Name()) return "wait", nil } + log.Printf("AUTONOMOUS_RUNNING: %s", match.Name()) match.control = "program" match.state = "autonomous_running" // TODO replace with typed protobuf @@ -191,6 +190,7 @@ func NewMatch(alliance0 * Alliance, alliance1 * Alliance, arena * Arena) * Match log.Printf("BAD_STATE: %s: %s", signal.Type(), match.state) return "wait", nil } + log.Printf("AUTONOMOUS_DONE: %s", match.Name()) match.control = "none" match.state = "autonomous_done"