Skip to content
Snippets Groups Projects
gRPCStatusView.go 1004 B
Newer Older
  • Learn to ignore specific revisions
  • Malte Bauch's avatar
    Malte Bauch committed
    package views
    
    import (
    	"code.fbi.h-da.de/cocsn/gosdn/cmd/gosdn-tview/app"
    	"github.com/rivo/tview"
    	"google.golang.org/grpc"
    	"time"
    )
    
    type GRPCStatusView struct {
    	gRPCStatusView *tview.TextView
    }
    
    //TODO: change to grpcStatusView
    func NewGRPCStatusView(app *app.App, conn *grpc.ClientConn) *GRPCStatusView {
    	//TODO: change to uses FlexBox if there is more to display in the header
    	sv := &GRPCStatusView{
    		gRPCStatusView: tview.NewTextView(),
    	}
    
    	sv.gRPCStatusView.
    		SetRegions(true).
    		SetBorder(true).
    		SetTitle("gRPC")
    
    	sv.gRPCStatusView.SetChangedFunc(func() {
    		app.Draw()
    	})
    
    	go goSDNTicker(sv, conn)
    
    	return sv
    }
    
    func (sv *GRPCStatusView) GetContent() tview.Primitive {
    	return sv.gRPCStatusView
    }
    
    func (sv *GRPCStatusView) SetContent(s string) {
    	sv.gRPCStatusView.Clear()
    	sv.gRPCStatusView.SetText(s)
    }
    
    func goSDNTicker(sv *GRPCStatusView, conn *grpc.ClientConn) {
    	ticker := time.NewTicker(5 * time.Second)
    	for range ticker.C {
    		sv.SetContent(conn.GetState().String())
    	}
    }