diff options
Diffstat (limited to 'lib/xdsserver/terminals.go')
-rw-r--r-- | lib/xdsserver/terminals.go | 53 |
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 |