2019-05-11 09:53:32 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import "log"
|
|
|
|
|
|
|
|
import "github.com/golang/protobuf/proto"
|
2019-05-11 14:45:17 -05:00
|
|
|
import pb "git.wit.com/wit/witProtobuf"
|
2019-05-28 19:00:56 -05:00
|
|
|
import "git.wit.com/wit/gui"
|
2019-05-26 19:42:44 -05:00
|
|
|
|
2019-05-11 09:53:32 -05:00
|
|
|
var mychannel chan *pb.Event
|
2019-05-23 00:33:16 -05:00
|
|
|
var currentMessage *pb.Event
|
|
|
|
|
2019-05-11 09:53:32 -05:00
|
|
|
func initChannel() {
|
|
|
|
mychannel = make(chan *pb.Event)
|
|
|
|
}
|
|
|
|
|
2019-05-23 20:04:00 -05:00
|
|
|
// Marshal & Unmarshal just to see if it ever fails
|
|
|
|
func addEvent(msg *pb.Event) {
|
|
|
|
data, err := proto.Marshal(msg)
|
|
|
|
if (err != nil) {
|
|
|
|
log.Printf("addEvent() something fucked up happened in Marshal")
|
|
|
|
}
|
|
|
|
|
|
|
|
pdata := new(pb.Event)
|
|
|
|
err = proto.Unmarshal(data, pdata)
|
|
|
|
if (err != nil) {
|
|
|
|
log.Printf("addEvent() something fucked up happened in Unmarshal")
|
|
|
|
}
|
|
|
|
|
|
|
|
mychannel <- pdata
|
|
|
|
}
|
|
|
|
|
2019-05-11 09:53:32 -05:00
|
|
|
// func processEvents(mychannel chan *pb.Event) {
|
|
|
|
func processEvents() {
|
2019-05-26 04:58:29 -05:00
|
|
|
defer r() // a golang trick to try to not crash on certain errors
|
2019-05-11 09:53:32 -05:00
|
|
|
for {
|
2019-05-23 00:33:16 -05:00
|
|
|
currentMessage = <-mychannel
|
2019-05-26 04:19:23 -05:00
|
|
|
log.Println("processEvents() RECIEVED msg = ", currentMessage)
|
2019-05-23 00:33:16 -05:00
|
|
|
if (currentMessage.Type == pb.Event_DEMO) {
|
2019-05-12 20:36:31 -05:00
|
|
|
log.Println("processEvents() do Event DEMO")
|
2019-05-12 20:49:59 -05:00
|
|
|
} else {
|
2019-05-23 21:36:20 -05:00
|
|
|
log.Println("processEvents() NEW PROTOBUF")
|
2019-05-23 18:38:51 -05:00
|
|
|
gui.Data.State = "NEW PROTOBUF"
|
2019-05-12 20:36:31 -05:00
|
|
|
}
|
2019-05-21 20:18:59 -05:00
|
|
|
log.Println("processEvents() END on channel")
|
2019-05-11 09:53:32 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-15 12:02:47 -05:00
|
|
|
func countVMS(data *pb.Event) int {
|
|
|
|
vms := data.GetVms()
|
|
|
|
log.Println("NUMBER OF vms=", len(vms))
|
|
|
|
// os.Exit(-1)
|
|
|
|
return len(vms)
|
|
|
|
}
|
|
|
|
|
2019-06-02 17:19:36 -05:00
|
|
|
func ReadReceivedData(data *pb.Event, mh *gui.TableData, box *gui.GuiBox) {
|
2019-05-11 09:53:32 -05:00
|
|
|
msgItems := data.GetResults()
|
2019-05-11 14:45:17 -05:00
|
|
|
log.Println("ReadReceivedData() Event msgItems=", msgItems)
|
2019-05-11 09:53:32 -05:00
|
|
|
for _, item := range msgItems {
|
2019-05-11 14:45:17 -05:00
|
|
|
log.Println(item)
|
2019-05-12 14:55:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
nets := data.GetNetworks()
|
|
|
|
log.Println("ReadReceivedData() Event networks=", nets)
|
|
|
|
for _, item := range nets {
|
|
|
|
log.Println(item)
|
|
|
|
}
|
|
|
|
|
|
|
|
vms := data.GetVms()
|
|
|
|
log.Println("ReadReceivedData() Event vms=", vms)
|
2019-05-28 19:00:56 -05:00
|
|
|
for row, vm := range vms {
|
|
|
|
setRowValues(mh, row, vm)
|
2019-05-12 23:00:55 -05:00
|
|
|
|
2019-06-02 17:19:36 -05:00
|
|
|
// create entries for the mouse clicks within tables
|
2019-05-30 10:55:46 -05:00
|
|
|
var newGuiButton gui.GuiButton
|
2019-06-02 17:19:36 -05:00
|
|
|
newGuiButton.Action = "SHOW VM WAS HERE"
|
|
|
|
newGuiButton.Custom = showVmMouseClick
|
2019-05-30 10:55:46 -05:00
|
|
|
newGuiButton.VM = vm // set the button to this VM
|
2019-06-02 17:19:36 -05:00
|
|
|
// newGuiButton.GW = box
|
|
|
|
if (box.Window == nil) {
|
|
|
|
newGuiButton.Action = "SHOW VM WAS HERE NIL"
|
|
|
|
panic("ReadReceivedData() box == nil")
|
|
|
|
}
|
2019-05-30 10:55:46 -05:00
|
|
|
newGuiButton.Account = data.Account
|
2019-05-31 22:46:23 -05:00
|
|
|
newGuiButton.Box = mh.Box
|
|
|
|
gui.Data.AllButtons = append(gui.Data.AllButtons, &newGuiButton)
|
2019-05-30 10:55:46 -05:00
|
|
|
mh.Rows[row].HumanData[6].Button = &newGuiButton
|
2019-06-02 21:56:14 -05:00
|
|
|
// mh.Rows[row].HumanData[6].VM = vm
|
2019-05-26 16:48:46 -05:00
|
|
|
|
2019-06-02 21:56:14 -05:00
|
|
|
// mh.Rows[row].VM = vm
|
2019-05-24 13:32:26 -05:00
|
|
|
|
2019-05-28 19:00:56 -05:00
|
|
|
log.Println("\tvm=", vm)
|
|
|
|
log.Println("\tvm.Name=", vm.Name)
|
2019-05-12 23:00:55 -05:00
|
|
|
log.Println("\tRows[row]=", mh.Rows[row])
|
|
|
|
log.Println("\tRows[row]=", row)
|
|
|
|
log.Println("\tRows[row].Name=", mh.Rows[row].Name)
|
2019-05-28 19:00:56 -05:00
|
|
|
log.Println(vm)
|
2019-05-12 17:32:38 -05:00
|
|
|
row += 1
|
|
|
|
}
|
2019-05-12 20:49:59 -05:00
|
|
|
}
|