From 4087be907a115622a096d790d4a793a506e88669 Mon Sep 17 00:00:00 2001 From: Saxon Milton Date: Mon, 18 Sep 2023 23:25:28 +0000 Subject: [PATCH] vidforward: simplify manager file save/load When saving and loading manager state to and from file, we don't need to worry about the slate exit signals. Now that we have broadcast status i.e. "play" or "slate", we can derive whether we need an exit signal based only on that. Approved-by: Trek Hopton --- cmd/vidforward/file.go | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/cmd/vidforward/file.go b/cmd/vidforward/file.go index 39ab39b1..f026da09 100644 --- a/cmd/vidforward/file.go +++ b/cmd/vidforward/file.go @@ -51,8 +51,7 @@ type BroadcastBasic struct { // ManagerBasic is a crude version of the BroadcastManager struct use to simplify // marshal/unmarshal overriding. type ManagerBasic struct { - Broadcasts map[MAC]*Broadcast - SlateExitSignals []MAC + Broadcasts map[MAC]*Broadcast } // MarshalJSON calls the default marshalling behaviour for the BroadcastBasic @@ -94,14 +93,7 @@ func (b *Broadcast) UnmarshalJSON(data []byte) error { // MarshalJSON calls the default marshaller for a ManagerBasic value using data // from a broadcastManager value. func (m *broadcastManager) MarshalJSON() ([]byte, error) { - var signals []MAC - for k := range m.slateExitSignals { - signals = append(signals, k) - } - return json.Marshal(ManagerBasic{ - Broadcasts: m.broadcasts, - SlateExitSignals: signals, - }) + return json.Marshal(ManagerBasic{Broadcasts: m.broadcasts}) } // UnmarshalJSON populates a ManagerBasic value from the provided data and then @@ -123,20 +115,23 @@ func (m *broadcastManager) UnmarshalJSON(data []byte) error { } m.dogNotifier = notifier - for _, mac := range mb.SlateExitSignals { - sigCh := make(chan struct{}) - m.slateExitSignals[mac] = sigCh - rv := m.getPipeline(mac) - if rv == nil { - panic("no pipeline for MAC") - } - if !inTest { - err := writeSlateAndCheckErrors(rv, sigCh, m.log) - if err != nil { - return fmt.Errorf("couldn't write slate for MAC %v: %w", mac, err) + for mac, b := range m.broadcasts { + if b.status == statusSlate { + sigCh := make(chan struct{}) + m.slateExitSignals[mac] = sigCh + rv := m.getPipeline(mac) + if rv == nil { + panic("no pipeline for MAC") + } + if !inTest { + err := writeSlateAndCheckErrors(rv, sigCh, m.log) + if err != nil { + return fmt.Errorf("couldn't write slate for MAC %v: %w", mac, err) + } } } } + return nil }