summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastien Douheret <sebastien.douheret@iot.bzh>2018-03-12 16:10:40 +0100
committerSebastien Douheret <sebastien.douheret@iot.bzh>2018-03-12 16:10:40 +0100
commit05ecb2f2c82e6da6f0d93644589b8aae660e3ebf (patch)
tree2df4f5ffc85e05e55aa4610fbf1751ea5e9d7795
parent92f718ade3789c1ed33be04d03c3214b6ed8f596 (diff)
Exit xds-cli on XDS-Server disconneciton.
Signed-off-by: Sebastien Douheret <sebastien.douheret@iot.bzh>
-rw-r--r--cmd-exec.go4
-rw-r--r--cmd-sdks.go4
-rw-r--r--cmd-target.go4
-rw-r--r--iosocket-client.go39
4 files changed, 45 insertions, 6 deletions
diff --git a/cmd-exec.go b/cmd-exec.go
index c988f95..819b911 100644
--- a/cmd-exec.go
+++ b/cmd-exec.go
@@ -160,6 +160,10 @@ func execCmd(ctx *cli.Context) error {
// Wait exit
select {
+ case res := <-IOSkClient.ServerDiscoChan:
+ Log.Debugf("XDS Server disconnected %v", res)
+ return cli.NewExitError(res.error, res.code)
+
case res := <-exitChan:
errStr := ""
if res.code == 0 {
diff --git a/cmd-sdks.go b/cmd-sdks.go
index eeebffa..e4012e7 100644
--- a/cmd-sdks.go
+++ b/cmd-sdks.go
@@ -305,6 +305,10 @@ func sdksInstall(ctx *cli.Context) error {
// Wait exit
select {
+ case res := <-IOSkClient.ServerDiscoChan:
+ Log.Debugf("XDS Server disconnected %v", res)
+ return cli.NewExitError(res.error, res.code)
+
case res := <-exitChan:
if res.code == 0 {
Log.Debugln("Exit successfully")
diff --git a/cmd-target.go b/cmd-target.go
index cd96ed4..33b757d 100644
--- a/cmd-target.go
+++ b/cmd-target.go
@@ -437,6 +437,10 @@ func terminalOpen(ctx *cli.Context) error {
// Wait exit - blocking
select {
+ case res := <-IOSkClient.ServerDiscoChan:
+ Log.Debugf("XDS Server disconnected %v", res)
+ return cli.NewExitError(res.error, res.code)
+
case res := <-exitChan:
errStr := ""
if res.code == 0 {
diff --git a/iosocket-client.go b/iosocket-client.go
index 9115b10..cd4b8ba 100644
--- a/iosocket-client.go
+++ b/iosocket-client.go
@@ -22,17 +22,27 @@ import (
"fmt"
"sync"
+ "gerrit.automotivelinux.org/gerrit/src/xds/xds-agent.git/lib/xaapiv1"
+
socketio_client "github.com/sebd71/go-socket.io-client"
)
+// Disconnection Channel used to notify XDS Server disconnection
+type Disconnection struct {
+ error string
+ code int
+ svrConf xaapiv1.ServerCfg
+}
+
// IOSockClient .
type IOSockClient struct {
- URL string
- Conn *socketio_client.Client
- Options *socketio_client.Options
- EmitMutex *sync.Mutex
- Connected bool
- EscapeKeys []byte
+ URL string
+ Conn *socketio_client.Client
+ Options *socketio_client.Options
+ EmitMutex *sync.Mutex
+ Connected bool
+ ServerDiscoChan chan Disconnection
+ EscapeKeys []byte
}
// NewIoSocketClient Create a new IOSockClient
@@ -47,6 +57,7 @@ func NewIoSocketClient(url, clientID string) (*IOSockClient, error) {
Transport: "websocket",
Header: make(map[string][]string),
},
+ ServerDiscoChan: make(chan Disconnection, 1),
}
sCli.Options.Header["XDS-AGENT-SID"] = []string{clientID}
@@ -64,6 +75,22 @@ func NewIoSocketClient(url, clientID string) (*IOSockClient, error) {
sCli.Connected = false
})
+ args := xaapiv1.EventRegisterArgs{Name: xaapiv1.EVTServerConfig}
+ if err := HTTPCli.Post("/events/register", args, nil); err != nil {
+ return sCli, err
+ }
+
+ sCli.Conn.On(xaapiv1.EVTServerConfig, func(ev xaapiv1.EventMsg) {
+ svrCfg, err := ev.DecodeServerCfg()
+ if err == nil && !svrCfg.Connected {
+ sCli.ServerDiscoChan <- Disconnection{
+ error: "\nXDS Server (id " + svrCfg.ID + ") disconnected !",
+ code: 1,
+ svrConf: svrCfg,
+ }
+ }
+ })
+
return sCli, nil
}