mirror of
https://github.com/wavetermdev/waveterm.git
synced 2025-01-02 18:39:05 +01:00
40 lines
942 B
Go
40 lines
942 B
Go
// Copyright 2024, Command Line Inc.
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package blockservice
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/wavetermdev/thenextwave/pkg/blockcontroller"
|
|
"github.com/wavetermdev/thenextwave/pkg/tsgen/tsgenmeta"
|
|
)
|
|
|
|
type BlockService struct{}
|
|
|
|
const DefaultTimeout = 2 * time.Second
|
|
|
|
var BlockServiceInstance = &BlockService{}
|
|
|
|
func (bs *BlockService) SendCommand_Meta() tsgenmeta.MethodMeta {
|
|
return tsgenmeta.MethodMeta{
|
|
Desc: "send command to block",
|
|
ArgNames: []string{"blockid", "cmd"},
|
|
}
|
|
}
|
|
|
|
func (bs *BlockService) SendCommand(blockId string, cmd blockcontroller.BlockCommand) error {
|
|
if strings.HasPrefix(cmd.GetCommand(), "controller:") {
|
|
bc := blockcontroller.GetBlockController(blockId)
|
|
if bc == nil {
|
|
return fmt.Errorf("block controller not found for block %q", blockId)
|
|
}
|
|
bc.InputCh <- cmd
|
|
} else {
|
|
blockcontroller.ProcessStaticCommand(blockId, cmd)
|
|
}
|
|
return nil
|
|
}
|