| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- package main
- import (
- "time"
- "hnyfkj.com.cn/rtu/linux/utils/shell"
- )
- var (
- rpc_ping = "executor.ping"
- rpc_exec = "executor.exec"
- rpc_stop = "executor.interrupt"
- rpc_quit = "executor.close"
- )
- // 串行执行
- func (c *MQTTCoupler) needSerialize(method string) bool {
- switch method {
- case rpc_ping, rpc_stop:
- return false
- case rpc_exec, rpc_quit:
- return true
- default:
- return true
- }
- }
- // 超时结束
- func (c *MQTTCoupler) needTimeoutEnd(method string) bool {
- switch method {
- case rpc_exec:
- return false
- case rpc_ping, rpc_stop, rpc_quit:
- return true
- default:
- return true
- }
- }
- // 心跳检测
- func (c *MQTTCoupler) Ping() (shell.ExecuteResult, error) {
- params := struct {
- ClientID string `json:"client_id"`
- }{
- ClientID: c.clientID,
- }
- return c.doCmd(rpc_ping, params)
- }
- // 执行命令
- func (c *MQTTCoupler) Exec(
- cmd string) (shell.ExecuteResult, error) {
- params := struct {
- ClientID string `json:"client_id"`
- shell.ExecuteParams
- }{
- ClientID: c.clientID,
- ExecuteParams: shell.ExecuteParams{
- Cmd: cmd,
- Timeout: int(shell.DefaultTimeout / time.Second),
- },
- }
- timeout := getCmdTimeoutByPrefix(cmd)
- if timeout > 0 {
- params.Timeout = timeout
- }
- return c.doCmd(rpc_exec, params)
- }
- // 中断执行
- func (c *MQTTCoupler) Stop() (shell.ExecuteResult, error) {
- params := struct {
- ClientID string `json:"client_id"`
- }{
- ClientID: c.clientID,
- }
- return c.doCmd(rpc_stop, params)
- }
- // 关闭退出
- func (c *MQTTCoupler) Quit() (shell.ExecuteResult, error) {
- params := struct {
- ClientID string `json:"client_id"`
- }{
- ClientID: c.clientID,
- }
- return c.doCmd(rpc_quit, params)
- }
|