lots of code refactoring
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
049dbdac72
commit
d207507bc3
|
@ -24,10 +24,11 @@ func processEvents() {
|
|||
for {
|
||||
message := <-mychannel
|
||||
log.Println("processEvents() on channel recieved a message = ", message)
|
||||
mh := addVmsTab(30)
|
||||
ReadReceivedData(message, mh)
|
||||
if (message.Type == pb.Event_DEMO) {
|
||||
log.Println("processEvents() do Event DEMO")
|
||||
} else {
|
||||
mh := addVmsTab(30)
|
||||
ReadReceivedData(message, mh)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -60,22 +61,11 @@ func ReadReceivedData(data *pb.Event, mh *gui.TableData) {
|
|||
}
|
||||
}
|
||||
|
||||
func handleProtoClient(conn net.Conn) {
|
||||
fmt.Println("Connected!")
|
||||
defer conn.Close()
|
||||
var buf bytes.Buffer
|
||||
_, err := io.Copy(&buf, conn)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Fatal error: %s", err.Error())
|
||||
return
|
||||
}
|
||||
pdata := pb.CreateSampleEvent()
|
||||
err = proto.Unmarshal(buf.Bytes(), pdata)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Fatal error: %s", err.Error())
|
||||
return
|
||||
}
|
||||
mychannel <- pdata
|
||||
func addSampleEvent() {
|
||||
msg := pb.CreateSampleEvent()
|
||||
msg.Name = "generated in addSampleEvent()"
|
||||
|
||||
addEvent(msg)
|
||||
}
|
||||
|
||||
// Marshal & Unmarshal just to see if it ever fails
|
||||
|
@ -94,24 +84,6 @@ func addEvent(msg *pb.Event) {
|
|||
mychannel <- pdata
|
||||
}
|
||||
|
||||
func addSampleEvent() {
|
||||
msg := pb.CreateSampleEvent()
|
||||
msg.Name = "generated in addSampleEvent()"
|
||||
|
||||
data, err := proto.Marshal(msg)
|
||||
if (err != nil) {
|
||||
log.Printf("addSampleEvent() something fucked up happened in Marshal")
|
||||
}
|
||||
|
||||
pdata := new(pb.Event)
|
||||
err = proto.Unmarshal(data, pdata)
|
||||
if (err != nil) {
|
||||
log.Printf("addSampleEvent() something fucked up happened in Unmarshal")
|
||||
}
|
||||
|
||||
mychannel <- pdata
|
||||
}
|
||||
|
||||
func sendDataToDest() {
|
||||
msg := pb.CreateSampleEvent()
|
||||
msg.Name = "from dnssecsockettest()"
|
||||
|
@ -138,3 +110,21 @@ func sendDataToDest() {
|
|||
// time.Sleep(3 * 1000 * 1000 * 1000)
|
||||
conn.Close()
|
||||
}
|
||||
|
||||
func handleProtoClient(conn net.Conn) {
|
||||
fmt.Println("Connected!")
|
||||
defer conn.Close()
|
||||
var buf bytes.Buffer
|
||||
_, err := io.Copy(&buf, conn)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Fatal error: %s", err.Error())
|
||||
return
|
||||
}
|
||||
pdata := pb.CreateSampleEvent()
|
||||
err = proto.Unmarshal(buf.Bytes(), pdata)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Fatal error: %s", err.Error())
|
||||
return
|
||||
}
|
||||
mychannel <- pdata
|
||||
}
|
||||
|
|
14
infoTabUI.go
14
infoTabUI.go
|
@ -10,9 +10,10 @@ import "github.com/gookit/config"
|
|||
|
||||
import "github.com/andlabs/ui"
|
||||
import _ "github.com/andlabs/ui/winmanifest"
|
||||
|
||||
import "git.wit.com/wit/gui"
|
||||
|
||||
import pb "git.wit.com/wit/witProtobuf"
|
||||
|
||||
// import "github.com/davecgh/go-spew/spew"
|
||||
|
||||
var cloudwin *ui.Window
|
||||
|
@ -50,6 +51,16 @@ func makeCloudInfoBox() ui.Control {
|
|||
})
|
||||
vbox.Append(add3button, false)
|
||||
|
||||
add4button := ui.NewButton("Add Demo Event")
|
||||
add4button.OnClicked(func(*ui.Button) {
|
||||
log.Println("add demo protobuf event to the channel")
|
||||
msg := pb.CreateSampleEvent()
|
||||
msg.Name = "generated in addSampleEvent()"
|
||||
msg.Type = pb.Event_DEMO
|
||||
addEvent(msg)
|
||||
})
|
||||
vbox.Append(add4button, false)
|
||||
|
||||
// Send a protobuf Event over the WIT socket
|
||||
add5button := ui.NewButton("Send protobuf to localhost")
|
||||
add5button.OnClicked(func(*ui.Button) {
|
||||
|
@ -109,6 +120,7 @@ func makeCloudInfoBox() ui.Control {
|
|||
return hbox
|
||||
}
|
||||
|
||||
// can not pass any args to this (?)
|
||||
func setupCloudUI() {
|
||||
cloudwin = ui.NewWindow("Cloud Control Panel", config.Int("width"), config.Int("height"), false)
|
||||
cloudwin.OnClosing(func(*ui.Window) bool {
|
||||
|
|
Loading…
Reference in New Issue