1 // Frontend: Connection functions for programs using the safcm library
3 // Copyright (C) 2021 Simon Ruderich
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
23 "ruderich.org/simon/safcm"
24 "ruderich.org/simon/safcm/rpc"
27 // SendRecv sends a message for host over conn and waits for the response. Any
28 // MsgLog messages received before the final (non MsgLog) response are passed
30 func (l *Loop) SendRecv(host Host, conn *rpc.Conn, msg safcm.Msg) (
42 log, ok := x.(safcm.MsgLog)
44 l.Log(host, log.Level, false, log.Text)
51 // HostInfoMsg sends a MsgInfoReq for host via conn and returns the resulting
53 func (l *Loop) HostInfoMsg(host Host, conn *rpc.Conn, req safcm.MsgInfoReq) (
54 safcm.MsgInfoResp, error) {
56 var empty safcm.MsgInfoResp
57 x, err := l.SendRecv(host, conn, req)
61 resp, ok := x.(safcm.MsgInfoResp)
63 return empty, fmt.Errorf("unexpected response %v", x)
68 // HostSyncMsg sends a MsgSyncReq for host via conn and returns the resulting
70 func (l *Loop) HostSyncMsg(host Host, conn *rpc.Conn, req safcm.MsgSyncReq) (
71 safcm.MsgSyncResp, error) {
73 var empty safcm.MsgSyncResp
74 x, err := l.SendRecv(host, conn, req)
78 resp, ok := x.(safcm.MsgSyncResp)
80 return empty, fmt.Errorf("unexpected response %v", x)