diff --git a/Makefile b/Makefile index 3ef8ecd..0b078f6 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,8 @@ push: git pull git add --all -git commit -a -s - git push + git push --all + git push --tags # should update every go dependancy (?) update: diff --git a/channel.go b/channel.go new file mode 100644 index 0000000..88ac442 --- /dev/null +++ b/channel.go @@ -0,0 +1,69 @@ +package main + +import "fmt" +import "log" +import "net" +import "os" +import "io" +import "bytes" + +import "github.com/golang/protobuf/proto" +import pb "git.wit.com/jcarr/witProtobuf" + +var mychannel chan *pb.Event + +func initChannel() { + mychannel = make(chan *pb.Event) +} + +// func processEvents(mychannel chan *pb.Event) { +func processEvents() { + for { + message := <-mychannel + log.Println("processEvents() on channel recieved a message") + ReadReceivedData(message) + } +} + +func ReadReceivedData(data *pb.Event) { + msgItems := data.GetResults() + fmt.Println("Receiving data...") + for _, item := range msgItems { + fmt.Println(item) + } +} + +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 := new(pb.Event) + err = proto.Unmarshal(buf.Bytes(), pdata) + if err != nil { + fmt.Fprintf(os.Stderr, "Fatal error: %s", err.Error()) + return + } + mychannel <- pdata +} + +func addEvent() { + msg := new(pb.Event) + msg.Name = "hello jeff" + + // var mybuf bytes.Buffer + + data, err := proto.Marshal(msg) + if (err != nil) { + log.Printf("something fucked up happened") + } + pdata := new(pb.Event) + // err = proto.Unmarshal(data.Bytes(), pdata) + err = proto.Unmarshal(data, pdata) + mychannel <- pdata + // sendDataToDest(data) +} diff --git a/infoTabUI.go b/infoTabUI.go index 4e90f6b..caa2ba6 100644 --- a/infoTabUI.go +++ b/infoTabUI.go @@ -53,6 +53,15 @@ func makeCloudInfoBox() ui.Control { }) vbox.Append(add2button, false) // ATTEMPT TO ADD THE TABLE HERE END + hbox.Append(ui.NewVerticalSeparator(), false) + + add3button := ui.NewButton("Add buf to chann") + add3button.OnClicked(func(*ui.Button) { + log.Println("add protobuf event to the channel") + addEvent() + }) + vbox.Append(add3button, false) + hbox.Append(ui.NewVerticalSeparator(), false) @@ -106,7 +115,6 @@ func setupCloudUI() { jwcmaintab.Append("Cloud Info", makeCloudInfoBox()) jwcmaintab.SetMargined(tabcount, true) - jwcmainwin.Show() } diff --git a/main.go b/main.go index 2340ae1..6f464c2 100644 --- a/main.go +++ b/main.go @@ -36,6 +36,9 @@ func main() { onExit() } + initChannel() + go processEvents() + go retrySocket() // make this the main loop in an attempt to figure out the crashes