fixed a problem where bytes and strings are the suck
[goDBhammer.git] / src / benchcontroller.go
index 6bd48a3..4d68235 100644 (file)
@@ -3,14 +3,17 @@
 package benchcontroller
 
 import (
-       //"./dbconnector";
+       "./dbconnector";
        "fmt";
-       "time";
+       "strings";
+       "strconv";
+       "os";
 )
 
 type BenchControllerConfig struct {
        id int;
        nclients int;
+       datamult int;
        dbtype string;
        dbhost string;
        dbuser string;
@@ -25,25 +28,84 @@ 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 {
-               time.Sleep(1000000000);
                i := <-commInChan;
                
                fmt.Printf("coms: %s\n", i);
                
-               /*switch i {
-                       case 1:
+               calls := strings.Split(i, ":", 0);
+               
+               fmt.Printf("stuff 1: %s, stuff 2: %s\n", calls[0], calls[1]);
+               
+               switch calls[0] {
+                       case "configure":
                                // this means shutdown
-                               os.Stdout.WriteString("shutdown\n");
-                               return;
-                       case 2:
+                               os.Stdout.WriteString("time for a conf\n");
+                               conf.id = 0;
+                               
+                               
+                               var esink os.Error;
+                               
+                               conf.nclients, esink = strconv.Atoi(calls[7]);
+                               conf.datamult, esink = strconv.Atoi(calls[6]);
+                               
+                               if esink != os.ECHILD {
+                                       // i need to do something with esink or the bollocks compiler screws itself
+                               }
+                               conf.dbtype = calls[1];
+                               conf.dbhost = calls[2];
+                               conf.dbuser = calls[3];
+                               conf.dbpass = calls[4];
+                               conf.dbname = calls[5];
+                               
+                       case "begin":
                                // get ready to bench - start the clients
                                os.Stdout.WriteString("ready clients\n");
-                       case 3:
+
+                               comchan := make(chan int);
+                               var cont bool;
+                               
+                               
+                               go dbconnector.DBSetup("mysql", conf.dbhost, conf.dbuser, conf.dbpass, conf.dbname, conf.datamult, comchan);
+                               cont=true;
+                                
+                               for cont{
+                                       val := <- comchan;
+                                       fmt.Printf("val: %d\n", val);
+                                       if val == 100 {
+                                                cont = false;
+                                       }
+                               }
+                               
+                               os.Stdout.WriteString("ok, im done\n");
+                       case "qwer":
                                // start the clients
                                os.Stdout.WriteString("start clients\n");
-               }*/
+               }
        }
 }
\ No newline at end of file