summaryrefslogtreecommitdiffstats
path: root/lib/xdsserver/terminals.go
diff options
context:
space:
mode:
authorSebastien Douheret <sebastien.douheret@iot.bzh>2018-03-15 14:50:27 +0100
committerSebastien Douheret <sebastien.douheret@iot.bzh>2018-04-05 01:30:28 +0200
commit08095aa9a0d7b9b7636cdf36a5a5b6df2592bc05 (patch)
treea62f59e6b0116d31b7ad9ec85974129d9698765b /lib/xdsserver/terminals.go
parent17812a0a4388ab0c87084ef7e8118d87e8fadcf7 (diff)
Added Target and Terminal events through WS.
Signed-off-by: Sebastien Douheret <sebastien.douheret@iot.bzh>
Diffstat (limited to 'lib/xdsserver/terminals.go')
-rw-r--r--lib/xdsserver/terminals.go53
1 files changed, 46 insertions, 7 deletions
diff --git a/lib/xdsserver/terminals.go b/lib/xdsserver/terminals.go
index 36623ab..b52b351 100644
--- a/lib/xdsserver/terminals.go
+++ b/lib/xdsserver/terminals.go
@@ -21,7 +21,6 @@ import (
"fmt"
"gerrit.automotivelinux.org/gerrit/src/xds/xds-server/lib/xsapiv1"
- socketio "github.com/googollee/go-socket.io"
"github.com/syncthing/syncthing/lib/sync"
)
@@ -62,6 +61,13 @@ func (t *Terminals) New(cfg xsapiv1.TerminalConfig, targetID string) (*xsapiv1.T
t.terms[termCfg.ID] = &newT
+ termCfg.Status = xsapiv1.StatusTermEnable
+
+ // Notify terminal add
+ if err := t.events.Emit(xsapiv1.EVTTargetTerminalAdd, &termCfg, ""); err != nil {
+ t.Log.Errorf("WS Emit EVTTargetTerminalAdd : %v", err)
+ }
+
return &termCfg, nil
}
@@ -84,6 +90,11 @@ func (t *Terminals) Free(id string) (*xsapiv1.TerminalConfig, error) {
delete(t.terms, id)
+ // Notify terminal state change or add
+ if err := t.events.Emit(xsapiv1.EVTTargetTerminalRemove, &resTerm, ""); err != nil {
+ t.Log.Errorf("WS Emit EVTTargetTerminalRemove : %v", err)
+ }
+
return &resTerm, nil
}
@@ -117,25 +128,45 @@ func (t *Terminals) getConfigArrUnsafe() []xsapiv1.TerminalConfig {
}
// Open adds a new terminal
-func (t *Terminals) Open(id string, sock *socketio.Socket, sessID string) (*xsapiv1.TerminalConfig, error) {
+func (t *Terminals) Open(id string, sess *ClientSession) (*xsapiv1.TerminalConfig, error) {
tc := t.Get(id)
if tc == nil {
return nil, fmt.Errorf("Unknown id")
}
- return (*tc).Open(sock, sessID)
+
+ if sess.IOSocket == nil {
+ return nil, fmt.Errorf("Websocket not established")
+ }
+
+ term, err := (*tc).Open(sess.IOSocket, sess.ID)
+
+ // Notify term state change
+ if errEmit := t.events.Emit(xsapiv1.EVTTargetTerminalStateChange, &term, sess.ID); errEmit != nil {
+ t.Log.Errorf("WS Emit EVTTargetTerminalStateChange : %v", errEmit)
+ }
+
+ return term, err
}
// Close a specific terminal
-func (t *Terminals) Close(id string) (*xsapiv1.TerminalConfig, error) {
+func (t *Terminals) Close(id string, sess *ClientSession) (*xsapiv1.TerminalConfig, error) {
tc := t.Get(id)
if tc == nil {
return nil, fmt.Errorf("Unknown id")
}
- return (*tc).Close()
+
+ term, err := (*tc).Close()
+
+ // Notify term state change
+ if errEmit := t.events.Emit(xsapiv1.EVTTargetTerminalStateChange, &term, sess.ID); errEmit != nil {
+ t.Log.Errorf("WS Emit EVTTargetTerminalStateChange : %v", errEmit)
+ }
+
+ return term, err
}
// Resize a specific terminal
-func (t *Terminals) Resize(id string, cols, rows uint16) (*xsapiv1.TerminalConfig, error) {
+func (t *Terminals) Resize(id string, cols, rows uint16, sess *ClientSession) (*xsapiv1.TerminalConfig, error) {
tmMutex.Lock()
defer tmMutex.Unlock()
@@ -143,7 +174,15 @@ func (t *Terminals) Resize(id string, cols, rows uint16) (*xsapiv1.TerminalConfi
if tc == nil {
return nil, fmt.Errorf("Unknown id")
}
- return (*tc).Resize(cols, rows)
+
+ term, err := (*tc).Resize(cols, rows)
+
+ // Notify term state change
+ if errEmit := t.events.Emit(xsapiv1.EVTTargetTerminalStateChange, &term, sess.ID); errEmit != nil {
+ t.Log.Errorf("WS Emit EVTTargetTerminalStateChange : %v", errEmit)
+ }
+
+ return term, err
}
// Signal Send a Signal a specific terminal