the ugliest code on earth...
[goDBhammer.git] / src / benchcontroller.go
1 // the benchmark controller
2
3 package benchcontroller
4
5 import (
6         "./dbconnector";
7         "fmt";
8         "strings";
9         "strconv";
10         "os";
11 )
12
13 type BenchControllerConfig struct {
14         id int;
15         nclients int;
16         datamult int;
17         dbtype string;
18         dbhost string;
19         dbuser string;
20         dbpass string;
21         dbname string;
22 }
23
24 func CreateController()(contConfig *BenchControllerConfig)
25 {
26         bcConfig := new(BenchControllerConfig);
27         
28         return bcConfig;
29 }
30
31 func buildStatus(commOutStatus chan string, commInGoro chan string)
32 {
33         var statusBuffer string;
34         
35         statusBuffer = "none:none";
36         
37         for {
38                 select {
39                         case invar := <- commInGoro:
40                                 fmt.Printf("received a status update\n");
41                                 statusBuffer = invar;
42                         case commOutStatus <- statusBuffer:
43                                 fmt.Printf("send a status buffer\n");
44                                 
45                 }
46         }
47 }
48
49 func MainLoop(conf *BenchControllerConfig, commInChan chan string, commOutChan chan string, commOutStatus chan string)
50 {
51         
52         comInGo := make(chan string);
53         
54         go buildStatus(commOutStatus, comInGo);
55         
56         for {
57                 i := <-commInChan;
58                 
59                 fmt.Printf("coms: %s\n", i);
60                 
61                 calls := strings.Split(i, ":", 0);
62                 
63                 fmt.Printf("stuff 1: %s, stuff 2: %s\n", calls[0], calls[1]);
64                 
65                 switch calls[0] {
66                         case "configure":
67                                 // this means shutdown
68                                 os.Stdout.WriteString("time for a conf\n");
69                                 conf.id = 0;
70                                 
71                                 
72                                 var esink os.Error;
73                                 
74                                 conf.nclients, esink = strconv.Atoi(calls[7]);
75                                 conf.datamult, esink = strconv.Atoi(calls[6]);
76                                 
77                                 if esink != os.ECHILD {
78                                         // i need to do something with esink or the bollocks compiler screws itself
79                                 }
80                                 conf.dbtype = calls[1];
81                                 conf.dbhost = calls[2];
82                                 conf.dbuser = calls[3];
83                                 conf.dbpass = calls[4];
84                                 conf.dbname = calls[5];
85                                 
86                         case "begin":
87                                 // get ready to bench - start the clients
88                                 os.Stdout.WriteString("ready clients\n");
89
90                                 comchan := make(chan int);
91                                 var cont bool;
92                                 
93                                 
94                                 go dbconnector.DBSetup("mysql", conf.dbhost, conf.dbuser, conf.dbpass, conf.dbname, conf.datamult, comchan);
95                                 cont=true;
96                                  
97                                 for cont{
98                                         val := <- comchan;
99                                         fmt.Printf("val: %d\n", val);
100                                         if val == 100 {
101                                                  cont = false;
102                                         }
103                                 }
104                                 
105                                 os.Stdout.WriteString("ok, im done\n");
106                         case "qwer":
107                                 // start the clients
108                                 os.Stdout.WriteString("start clients\n");
109                 }
110         }
111 }