the ugliest code on earth...
authorPaul J R <me@pjr.cc>
Mon, 16 Nov 2009 06:28:14 +0000 (17:28 +1100)
committerPaul J R <me@pjr.cc>
Mon, 16 Nov 2009 06:28:14 +0000 (17:28 +1100)
src/benchcontroller.go
src/web/index.html
src/webconnector.go

index 21150e1..4d68235 100644 (file)
@@ -28,8 +28,31 @@ func CreateController()(contConfig *BenchControllerConfig)
        return bcConfig;
 }
 
-func MainLoop(conf *BenchControllerConfig, commInChan chan string, commOutChan chan string)
+func buildStatus(commOutStatus chan string, commInGoro chan string)
 {
+       var statusBuffer string;
+       
+       statusBuffer = "none:none";
+       
+       for {
+               select {
+                       case invar := <- commInGoro:
+                               fmt.Printf("received a status update\n");
+                               statusBuffer = invar;
+                       case commOutStatus <- statusBuffer:
+                               fmt.Printf("send a status buffer\n");
+                               
+               }
+       }
+}
+
+func MainLoop(conf *BenchControllerConfig, commInChan chan string, commOutChan chan string, commOutStatus chan string)
+{
+       
+       comInGo := make(chan string);
+       
+       go buildStatus(commOutStatus, comInGo);
+       
        for {
                i := <-commInChan;
                
index b499243..850d74f 100644 (file)
@@ -1,6 +1,7 @@
 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 <html>
 <head>
+<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 <title>Insert title here</title>
 </head>
index fa814f3..4b7b60b 100644 (file)
@@ -10,11 +10,37 @@ import (
        "./benchcontroller";
        //"dbconnector";
        "fmt";
+       "json";
 )
 
+type JSONdata struct {
+       currentJob int; // 1 = nothing, 2 = have database login, 3 = createing data, 4 = running test, 5 = finished
+       currentStatus int; // percent complete
+}
+
 var comin chan string;
+var cominstatus chan string;
 var comout chan string;
 
+func JSONResponder(c *http.Conn, req *http.Request)
+{
+       //stat := <- cominstatus;
+       
+       j, _, _ := json.StringToJson("{\"somestring\":\"somevalue\"}");
+       
+       io.WriteString(c, fmt.Sprintf("%s\n", json.JsonToString(j)));
+       
+       /*if ret {
+               fmt.Printf("err was true\n");
+       } else {
+               fmt.Printf("err was false\n");
+       }*/
+       
+       //fmt.Printf("errto %s\n", errto); 
+       
+}
+
+
 // hello world, the web server
 func ServerResponder(c *http.Conn, req *http.Request) {
        //comout <- 2;
@@ -129,14 +155,15 @@ func footer(c *http.Conn)
 func main()
 {
        comin = make(chan string);
+       cominstatus = make(chan string);
        comout = make(chan string);
        
        
        bc := benchcontroller.CreateController();
-       go benchcontroller.MainLoop(bc, comout, comin);
+       go benchcontroller.MainLoop(bc, comout, comin, cominstatus);
        
        http.Handle("/", http.FileServer("./web", "/web"));
-       http.Handle("/json", http.HandlerFunc(ServerResponder));
+       http.Handle("/json", http.HandlerFunc(JSONResponder));
        err := http.ListenAndServe(":22222", nil);
        if err != nil {
                panic("ListenAndServe: ", err.String())