Checkpoint

This commit is contained in:
maze authored and maze committed 2026-10-29 17:28:51 +01:00
1 parent 7b6db17870
commit 0295eb1ad2
125 files changed
+59376

No files matched your search

+79
View File
@@ -0,0 +1,79 @@
package mpd
import (
"strings"
"github.com/sirupsen/logrus"
)
func (c *Player) idleLoop(conn *clientConn) {
defer func() {
_ = conn.Close()
}()
log := conn.log()
log.Debug("starting loop")
var (
subsystems []interface{}
err error
)
subsystems = make([]interface{}, len(c.idleSubsystems))
for i, subsystem := range c.idleSubsystems {
subsystems[i] = subsystem
}
loop:
for {
/*
var kv map[string]string
log.WithField("subsystems", c.idleSubsystems).Debug("sending idle command")
if kv, err = c.commandMap(conn, "idle", subsystems...); err != nil {
log.WithError(err).Error("error sending idle command")
break loop
} else if subsystem, ok := kv["changed"]; ok {
if err = c.idleChanged(subsystem); err != nil {
break loop
}
}
*/
var id uint
log.Debug("enter idle mode")
if id, err = conn.Cmd("idle"); err != nil {
break loop
}
log.WithField("id", id).Debug("idle mode ready")
conn.StartResponse(id)
for {
var line string
if line, err = conn.ReadLine(); err != nil {
break loop
} else if line == "OK" {
break
} else if i := strings.Index(line, ": "); i > 0 && line[:i] == "changed" {
if err = c.idleChanged(line[i+2:]); err != nil {
break loop
}
} else {
log.WithField("data", line).Warn("unexpected idle response")
break
}
}
conn.EndResponse(id)
}
if err != nil {
log.WithError(err).Error("idle loop terminating")
} else {
log.Info("idle loop terminating")
}
}
func (c *Player) idleChanged(subsystem string) (err error) {
logrus.WithFields(logrus.Fields{
"protocol": "mpd",
"addr": c.addr,
"subsystem": subsystem,
}).Debug("subsystem changed")
return
}