增加待机报文缓存,无网状态也能执行待机任务;投影仪指令结果以设备状态为准

This commit is contained in:
2025-04-29 13:48:35 +08:00
parent 40293e5e9b
commit e1384504f1
13 changed files with 266 additions and 32 deletions

View File

@@ -12,6 +12,7 @@ type Router interface {
RegisterHandler(string, ...HandlerFunc)
UnregisterHandler(string)
Route(*packets.Publish)
HandlerRun(t string, p *paho.Publish) bool
SetDebugLogger(log.Logger)
Use(...HandlerFunc)
}
@@ -92,6 +93,21 @@ func (e *Engine) UnregisterHandler(topic string) {
delete(e.subscriptions, topic)
}
func (e *Engine) HandlerRun(t string, p *paho.Publish) bool {
for route, handlers := range e.subscriptions {
if match(route, t) {
e.debug.Println("found handler for:", route)
e.queueWg.Add(1)
go func() {
defer e.queueWg.Done()
WithLeafContext(e.ctx, p, e, handlers).Next()
}()
return true
}
}
return false
}
func (e *Engine) Route(pb *packets.Publish) {
e.debug.Println("routing message for:", pb.Topic)
e.mu.Lock()
@@ -115,18 +131,7 @@ func (e *Engine) Route(pb *packets.Publish) {
topic = m.Topic
}
handlerCalled := false
for route, handlers := range e.subscriptions {
if match(route, topic) {
e.debug.Println("found handler for:", route)
e.queueWg.Add(1)
go func() {
defer e.queueWg.Done()
WithLeafContext(e.ctx, m, e, handlers).Next()
}()
handlerCalled = true
}
}
handlerCalled := e.HandlerRun(topic, m)
if !handlerCalled && e.defaultHandler != nil {
e.queueWg.Add(1)