1 // Frontend: Connection functions for programs using the safcm library
3 // SPDX-License-Identifier: GPL-3.0-or-later
4 // Copyright (C) 2021-2024 Simon Ruderich
11 "ruderich.org/simon/safcm"
12 "ruderich.org/simon/safcm/rpc"
15 // SendRecv sends a message for host over conn and waits for the response. Any
16 // MsgLog messages received before the final (non MsgLog) response are passed
18 func (l *Loop) SendRecv(host Host, conn *rpc.Conn, msg safcm.Msg) (
30 log, ok := x.(safcm.MsgLog)
32 l.Log(host, log.Level, false, log.Text)
39 // HostInfoMsg sends a MsgInfoReq for host via conn and returns the resulting
41 func (l *Loop) HostInfoMsg(host Host, conn *rpc.Conn, req safcm.MsgInfoReq) (
42 safcm.MsgInfoResp, error) {
44 var empty safcm.MsgInfoResp
45 x, err := l.SendRecv(host, conn, req)
49 resp, ok := x.(safcm.MsgInfoResp)
51 return empty, fmt.Errorf("unexpected response %v", x)
56 // HostSyncMsg sends a MsgSyncReq for host via conn and returns the resulting
58 func (l *Loop) HostSyncMsg(host Host, conn *rpc.Conn, req safcm.MsgSyncReq) (
59 safcm.MsgSyncResp, error) {
61 var empty safcm.MsgSyncResp
62 x, err := l.SendRecv(host, conn, req)
66 resp, ok := x.(safcm.MsgSyncResp)
68 return empty, fmt.Errorf("unexpected response %v", x)