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
This commit is contained in:
Saxon Milton 2023-09-18 23:25:28 +00:00
parent db84c5bfcf
commit 4087be907a
1 changed files with 16 additions and 21 deletions

View File

@ -51,8 +51,7 @@ type BroadcastBasic struct {
// ManagerBasic is a crude version of the BroadcastManager struct use to simplify // ManagerBasic is a crude version of the BroadcastManager struct use to simplify
// marshal/unmarshal overriding. // marshal/unmarshal overriding.
type ManagerBasic struct { type ManagerBasic struct {
Broadcasts map[MAC]*Broadcast Broadcasts map[MAC]*Broadcast
SlateExitSignals []MAC
} }
// MarshalJSON calls the default marshalling behaviour for the BroadcastBasic // 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 // MarshalJSON calls the default marshaller for a ManagerBasic value using data
// from a broadcastManager value. // from a broadcastManager value.
func (m *broadcastManager) MarshalJSON() ([]byte, error) { func (m *broadcastManager) MarshalJSON() ([]byte, error) {
var signals []MAC return json.Marshal(ManagerBasic{Broadcasts: m.broadcasts})
for k := range m.slateExitSignals {
signals = append(signals, k)
}
return json.Marshal(ManagerBasic{
Broadcasts: m.broadcasts,
SlateExitSignals: signals,
})
} }
// UnmarshalJSON populates a ManagerBasic value from the provided data and then // 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 m.dogNotifier = notifier
for _, mac := range mb.SlateExitSignals { for mac, b := range m.broadcasts {
sigCh := make(chan struct{}) if b.status == statusSlate {
m.slateExitSignals[mac] = sigCh sigCh := make(chan struct{})
rv := m.getPipeline(mac) m.slateExitSignals[mac] = sigCh
if rv == nil { rv := m.getPipeline(mac)
panic("no pipeline for MAC") if rv == nil {
} panic("no pipeline for MAC")
if !inTest { }
err := writeSlateAndCheckErrors(rv, sigCh, m.log) if !inTest {
if err != nil { err := writeSlateAndCheckErrors(rv, sigCh, m.log)
return fmt.Errorf("couldn't write slate for MAC %v: %w", mac, err) if err != nil {
return fmt.Errorf("couldn't write slate for MAC %v: %w", mac, err)
}
} }
} }
} }
return nil return nil
} }