Add storage API abstraction

This commit is contained in:
Jonathan Leibiusky @xetorthio
2017-06-22 09:16:49 -03:00
committed by Marcos Lilljedahl
19 changed files with 277 additions and 83 deletions

View File

@@ -2,6 +2,7 @@ package pwd
import (
"log"
"sync/atomic"
"time"
"github.com/play-with-docker/play-with-docker/pwd/types"
@@ -11,6 +12,7 @@ func (p *pwd) ClientNew(id string, session *types.Session) *types.Client {
defer observeAction("ClientNew", time.Now())
c := &types.Client{Id: id, Session: session}
session.Clients = append(session.Clients, c)
p.clientCount = atomic.AddInt32(&p.clientCount, 1)
return c
}
@@ -29,6 +31,7 @@ func (p *pwd) ClientClose(client *types.Client) {
for i, cl := range session.Clients {
if cl.Id == client.Id {
session.Clients = append(session.Clients[:i], session.Clients[i+1:]...)
p.clientCount = atomic.AddInt32(&p.clientCount, -1)
break
}
}
@@ -38,6 +41,10 @@ func (p *pwd) ClientClose(client *types.Client) {
p.setGauges()
}
func (p *pwd) ClientCount() int {
return int(atomic.LoadInt32(&p.clientCount))
}
func (p *pwd) notifyClientSmallestViewPort(session *types.Session) {
vp := p.SessionGetSmallestViewPort(session)
// Resize all terminals in the session