gus/event.gui.pb.go

395 lines
8.5 KiB
Go

// Code generated by go.wit.com/apps/autogenpb DO NOT EDIT.
// This file was autogenerated with autogenpb v0.0.65 2025-03-12_15:38:32_UTC
// go install go.wit.com/apps/autogenpb@latest
//
// define which structs (messages) you want to use in the .proto file
// Then sort.pb.go and marshal.pb.go files are autogenerated
//
// autogenpb uses it and has an example .proto file with instructions
//
package main
import (
"time"
"github.com/google/uuid"
"go.wit.com/gui"
"go.wit.com/lib/protobuf/guipb"
"go.wit.com/log"
timestamppb "google.golang.org/protobuf/types/known/timestamppb"
)
// START GUI
func (x *Events) NewTable(title string) *EventsTable {
t := new(EventsTable)
t.x = x
pb := new(guipb.Table)
pb.Title = title
t.pb = pb
return t
}
func (t *EventsTable) AddStringFunc(title string, f func(*Event) string) *EventStringFunc {
t.pb.Order = append(t.pb.Order, title)
sf := new(EventStringFunc)
sf.title = title
sf.f = f
sf.order = t.order
t.order += 1
t.stringFuncs = append(t.stringFuncs, sf)
return sf
}
func (t *EventsTable) AddButtonFunc(title string, f func(*Event) string) *EventButtonFunc {
t.pb.Order = append(t.pb.Order, title)
sf := new(EventButtonFunc)
sf.title = title
sf.f = f
sf.order = t.order
t.order += 1
t.buttonFuncs = append(t.buttonFuncs, sf)
return sf
}
func (t *EventsTable) AddIntFunc(title string, f func(*Event) int) *EventIntFunc {
t.pb.Order = append(t.pb.Order, title)
sf := new(EventIntFunc)
sf.title = title
sf.f = f
sf.order = t.order
t.order += 1
t.intFuncs = append(t.intFuncs, sf)
return sf
}
func (t *EventsTable) AddTimeFunc(title string, f func(*Event) time.Time) *EventTimeFunc {
t.pb.Order = append(t.pb.Order, title)
sf := new(EventTimeFunc)
sf.title = title
sf.f = f
sf.order = t.order
t.order += 1
t.timeFuncs = append(t.timeFuncs, sf)
return sf
}
func (sf *EventStringFunc) SetTitle(title string) {
sf.title = title
}
func (sf *EventIntFunc) SetTitle(title string) {
sf.title = title
}
func (sf *EventTimeFunc) SetTitle(title string) {
sf.title = title
}
func (mt *EventsTable) SetParent(p *gui.Node) {
mt.parent = p
}
func (mt *EventsTable) ShowTable() {
// log.Info("ShowTable() SENDING TO GUI")
mt.MakeTable()
mt.parent.ShowTable(mt.pb)
}
type EventStringFunc struct {
title string
f func(*Event) string
Custom func(*Event)
order int
}
type EventButtonFunc struct {
title string
f func(*Event) string
Custom func(*Event)
order int
}
type EventIntFunc struct {
title string
f func(*Event) int
Custom func(*Event)
order int
}
type EventTimeFunc struct {
title string
f func(*Event) time.Time
Custom func(*Event)
order int
}
type EventsTable struct {
pb *guipb.Table
parent *gui.Node
x *Events
hostnames []string
stringFuncs []*EventStringFunc
intFuncs []*EventIntFunc
timeFuncs []*EventTimeFunc
buttonFuncs []*EventButtonFunc
CustomFunc func(*Event)
order int
}
func (mt *EventsTable) doStringFunc(name string) bool {
for _, sf := range mt.stringFuncs {
if sf.title != name {
continue
}
// log.Info("main: found stringfunc name:", name)
r := new(guipb.StringRow)
r.Header = new(guipb.Widget)
r.Header.Name = name
all := mt.x.All()
for all.Scan() {
m := all.Next()
r.Vals = append(r.Vals, sf.f(m))
// log.Info("main: adding", name, r.Vals)
}
mt.pb.StringRows = append(mt.pb.StringRows, r)
return true
}
return false
}
func (mt *EventsTable) doButtonFunc(name string) bool {
for _, sf := range mt.buttonFuncs {
if sf.title != name {
continue
}
// log.Info("main: found stringfunc name:", name)
r := new(guipb.ButtonRow)
r.Header = new(guipb.Widget)
r.Header.Name = name
all := mt.x.All()
for all.Scan() {
m := all.Next()
r.Vals = append(r.Vals, sf.f(m))
// log.Info("main: adding", name, r.Vals)
}
mt.pb.ButtonRows = append(mt.pb.ButtonRows, r)
return true
}
return false
}
func (mt *EventsTable) doIntFunc(name string) bool {
for _, sf := range mt.intFuncs {
if sf.title != name {
continue
}
// log.Info("main: found intfunc name:", name)
r := new(guipb.IntRow)
r.Header = new(guipb.Widget)
r.Header.Name = name
all := mt.x.All()
for all.Scan() {
m := all.Next()
r.Vals = append(r.Vals, int64(sf.f(m)))
// log.Info("main: adding", name, r.Vals)
}
mt.pb.IntRows = append(mt.pb.IntRows, r)
return true
}
return false
}
func (mt *EventsTable) doTimeFunc(name string) bool {
for _, sf := range mt.timeFuncs {
if sf.title != name {
continue
}
// log.Info("main: found timefunc name:", name)
r := new(guipb.TimeRow)
r.Header = new(guipb.Widget)
r.Header.Name = name
all := mt.x.All()
for all.Scan() {
m := all.Next()
t := sf.f(m)
r.Vals = append(r.Vals, timestamppb.New(t)) // convert to protobuf time
// log.Info("main: adding", name, r.Vals)
}
mt.pb.TimeRows = append(mt.pb.TimeRows, r)
return true
}
return false
}
func (mt *EventsTable) MakeTable() {
for _, name := range mt.pb.Order {
// log.Info("main: looking for row name()", name)
if mt.doStringFunc(name) {
continue
}
if mt.doIntFunc(name) {
continue
}
if mt.doTimeFunc(name) {
continue
}
if mt.doButtonFunc(name) {
continue
}
}
}
func (t *EventsTable) AddHostname() *EventStringFunc {
sf := t.AddStringFunc("Hostname", func(m *Event) string {
return m.Hostname
})
return sf
}
func (t *EventsTable) AddLocalPort() {
t.AddIntFunc("LocalPort", func(m *Event) int {
return int(m.LocalPort)
})
}
func (mt *EventsTable) NewUuid() {
mt.pb.Uuid = uuid.New().String()
}
// START TABLE UPDATE
func (mt *EventsTable) todoUpdate() {
for _, name := range mt.pb.Order {
// log.Info("Eventpb: trying to update row()", name)
if mt.updateStringFunc(name) {
continue
}
if mt.updateTimeFunc(name) {
continue
}
/*
if mt.updateIntFunc(name) {
continue
}
*/
}
// mt.dumpStringFunc("Hostname")
mt.parent.UpdateTable(mt.pb)
}
func (mt *EventsTable) dumpStringFunc(name string) {
for i, r := range mt.pb.StringRows {
// log.Info("could use", i, r.Header.Name, "for name =", name)
if r.Header.Name == name {
log.Info("dump Strings row", i, r.Header.Name, r.Vals)
break
}
}
}
func (mt *EventsTable) updateStringFunc(name string) bool {
// log.Info("LOOKING FOR STRING row", name)
var found *guipb.StringRow
for _, r := range mt.pb.StringRows {
// log.Info("could use", i, r.Header.Name, "for name =", name)
if r.Header.Name == name {
// log.Info("found row", i, r.Header.Name)
found = r
break
}
}
if found == nil {
log.Info("did not find string row", name)
return false
}
for _, sf := range mt.stringFuncs {
if sf.title != name {
continue
}
// log.Info("Eventpb: starting", name, found.Vals)
for i, _ := range found.Vals {
tmp := sf.f(mt.x.Events[i])
if tmp == "www.wit.com" {
log.Info("virtpb: FOUND WWW", i)
tmp = "new.www"
}
found.Vals[i] = tmp
}
// log.Info("Eventpb: ending", name, found.Vals)
return true
}
return false
}
func (mt *EventsTable) updateTimeFunc(name string) bool {
log.Info("LOOKING FOR TIME row", name)
var found *guipb.TimeRow
for i, r := range mt.pb.TimeRows {
// log.Info("could use", i, r.Header.Name, "for name =", name)
if r.Header.Name == name {
log.Info("found row", i, r.Header.Name)
found = r
break
}
}
if found == nil {
log.Info("did not find time row", name)
return false
}
for _, sf := range mt.timeFuncs {
if sf.title != name {
continue
}
// log.Info("updateTimeFunc() has row len =", len(mt.x.Events))
// log.Info("virtpb: starting", name, found.Vals)
for i, _ := range found.Vals {
newt := sf.f(mt.x.Events[i])
found.Vals[i] = timestamppb.New(newt) // convert to protobuf time
}
// log.Info("virtpb: ending", name, found.Vals)
return true
}
return false
}
func (mt *EventsTable) Delete() {
if mt == nil {
log.Info("mt == nil table already deleted")
return
}
// log.Info("table Delete here")
mt.parent.DeleteTable(mt.pb)
}
func (mt *EventsTable) eventsCustom(w *guipb.Widget) {
row := mt.x.Events[w.Location.Y-1]
// log.Info("got to eventsCustom() with", w.Location.X, w.Location.Y-1)
for _, sf := range mt.buttonFuncs {
if sf.order == int(w.Location.X) {
// log.Info("found order", sf.order)
if sf.Custom != nil {
log.Info("doing Custom() func for button")
sf.Custom(row)
return
}
}
}
mt.CustomFunc(row)
}
func (mt *EventsTable) Custom(f func(*Event)) {
mt.pb.RegisterCustom(mt.eventsCustom)
mt.CustomFunc = f
}
func (mt *EventsTable) GetUuid() string {
return mt.pb.Uuid
}
// END TABLE UPDATE
// END GUI