feat(waiter,devicebridge): 设备桥连接带授权态,命令处理器类型统一

- `runDeviceBridgeLoop`/`connectDeviceBridge` 增加 `authorized` 入参(未授权不再尝试建立桥连);
- `Bridge.OnCmd` 的处理器类型改为具名 `BridgeCmdHandler`,与 waiter 侧签名对齐。
This commit is contained in:
JianFeeeee
2026-09-12 20:19:05 +08:00
parent 8f40b91dea
commit 07e08352b9
3 changed files with 27 additions and 18 deletions

View File

@ -10,10 +10,12 @@ import (
"time"
)
// CmdHandler 是命令处理回调类型。
// 当收到 remotedevice 下发的 cmd 时调用reqID 用于回执command 是命令内容。
// CmdHandler 是本地命令路由回调类型。
type CmdHandler func(reqID, command string)
// BridgeCmdHandler 接收服务端明确下发的路由信号shell 或 homeagent
type BridgeCmdHandler func(reqID, command, cmdType string)
// CmdResult 是命令执行结果回调(用于异步通知 GUI 层)。
type CmdResultHandler func(reqID, status, output, errMsg string)
@ -41,7 +43,7 @@ type Bridge struct {
started bool
// 回调
cmdHandler CmdHandler
cmdHandler BridgeCmdHandler
resultHandler CmdResultHandler
dataHandler DataHandler
@ -135,7 +137,7 @@ func (b *Bridge) Authorized() bool {
}
// OnCmd 注册命令处理器。当收到 remotedevice 下发的 cmd 时调用。
func (b *Bridge) OnCmd(handler CmdHandler) {
func (b *Bridge) OnCmd(handler BridgeCmdHandler) {
b.mu.Lock()
defer b.mu.Unlock()
b.cmdHandler = handler
@ -436,7 +438,7 @@ func (b *Bridge) handleMessage(msg map[string]interface{}) {
log.Printf("[devicebridge] cmd req=%s type=%s cmd=%s", reqID, cmdType, truncateString(command, 60))
if handler != nil {
handler(reqID, command)
handler(reqID, command, cmdType)
}
case "hello_ack", "bind_ack":