diff options
Diffstat (limited to 'lib/xdsserver/targets.go')
-rw-r--r-- | lib/xdsserver/targets.go | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/lib/xdsserver/targets.go b/lib/xdsserver/targets.go index 663233d..ded3c1b 100644 --- a/lib/xdsserver/targets.go +++ b/lib/xdsserver/targets.go @@ -27,7 +27,6 @@ import ( common "gerrit.automotivelinux.org/gerrit/src/xds/xds-common.git/golib" "gerrit.automotivelinux.org/gerrit/src/xds/xds-server/lib/xdsconfig" "gerrit.automotivelinux.org/gerrit/src/xds/xds-server/lib/xsapiv1" - socketio "github.com/googollee/go-socket.io" "github.com/syncthing/syncthing/lib/sync" ) @@ -80,7 +79,7 @@ func (t *Targets) LoadConfig() error { // Update targets t.Log.Infof("Loading initial targets config: %d targets found", len(tgts)) for _, tc := range tgts { - if _, err := t.createUpdate(tc, false, true); err != nil { + if _, err := t.createUpdate(tc, false, true, nil); err != nil { return err } } @@ -149,12 +148,12 @@ func (t *Targets) getConfigArrUnsafe() []xsapiv1.TargetConfig { } // Add adds a new target -func (t *Targets) Add(newT xsapiv1.TargetConfig) (*xsapiv1.TargetConfig, error) { - return t.createUpdate(newT, true, false) +func (t *Targets) Add(newT xsapiv1.TargetConfig, sess *ClientSession) (*xsapiv1.TargetConfig, error) { + return t.createUpdate(newT, true, false, sess) } // CreateUpdate creates or update a target -func (t *Targets) createUpdate(newT xsapiv1.TargetConfig, create bool, initial bool) (*xsapiv1.TargetConfig, error) { +func (t *Targets) createUpdate(newT xsapiv1.TargetConfig, create bool, initial bool, sess *ClientSession) (*xsapiv1.TargetConfig, error) { var err error tcMutex.Lock() @@ -227,6 +226,14 @@ func (t *Targets) createUpdate(newT xsapiv1.TargetConfig, create bool, initial b // Add to folders list t.tgts[newT.ID] = &tgt + // Notify target Add + newTgt := tgt.GetConfig() + if !initial { + if err = t.events.Emit(xsapiv1.EVTTargetAdd, &newTgt, sess.ID); err != nil { + t.Log.Errorf("WS Emit EVTTargetAdd : %v", err) + } + } + // Save config on disk if !initial { if err := t.SaveConfig(); err != nil { @@ -234,12 +241,11 @@ func (t *Targets) createUpdate(newT xsapiv1.TargetConfig, create bool, initial b } } - newTgt := tgt.GetConfig() return &newTgt, nil } // Delete deletes a specific target -func (t *Targets) Delete(id string) (xsapiv1.TargetConfig, error) { +func (t *Targets) Delete(id string, sess *ClientSession) (xsapiv1.TargetConfig, error) { var err error tcMutex.Lock() @@ -262,6 +268,11 @@ func (t *Targets) Delete(id string) (xsapiv1.TargetConfig, error) { // Save config on disk err = t.SaveConfig() + // Notify target remove + if err = t.events.Emit(xsapiv1.EVTTargetRemove, &tgc, sess.ID); err != nil { + t.Log.Errorf("WS Emit EVTTargetRemove : %v", err) + } + return tgc, err } @@ -341,10 +352,8 @@ func (t *Targets) CreateUpdateTerminal(targetID string, tmCfg xsapiv1.TerminalCo } } - term.Status = xsapiv1.StatusTermEnable - - // Save config on disk if !initial { + // Save config on disk if err := t.SaveConfig(); err != nil { return term, err } @@ -374,30 +383,31 @@ func (t *Targets) DeleteTerminal(targetID, termID string) (*xsapiv1.TerminalConf } // OpenTerminal Open a target terminal -func (t *Targets) OpenTerminal(targetID, termID string, sock *socketio.Socket, sessID string) (*xsapiv1.TerminalConfig, error) { +func (t *Targets) OpenTerminal(targetID, termID string, sess *ClientSession) (*xsapiv1.TerminalConfig, error) { terms, exist := t.terminals[targetID] if !exist { return nil, fmt.Errorf("unknown target id") } - return (*terms).Open(termID, sock, sessID) + + return (*terms).Open(termID, sess) } // CloseTerminal Close a target terminal -func (t *Targets) CloseTerminal(targetID, termID string) (*xsapiv1.TerminalConfig, error) { +func (t *Targets) CloseTerminal(targetID, termID string, sess *ClientSession) (*xsapiv1.TerminalConfig, error) { terms, exist := t.terminals[targetID] if !exist { return nil, fmt.Errorf("unknown target id") } - return (*terms).Close(termID) + return (*terms).Close(termID, sess) } // ResizeTerminal Set size (row+col) of a target terminal -func (t *Targets) ResizeTerminal(targetID, termID string, cols, rows uint16) (*xsapiv1.TerminalConfig, error) { +func (t *Targets) ResizeTerminal(targetID, termID string, cols, rows uint16, sess *ClientSession) (*xsapiv1.TerminalConfig, error) { terms, exist := t.terminals[targetID] if !exist { return nil, fmt.Errorf("unknown target id") } - return (*terms).Resize(termID, cols, rows) + return (*terms).Resize(termID, cols, rows, sess) } // SignalTerminal Send a signal to a target terminal |