|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH RFC 04/59] Controller: Move process worker into its own file
From: George Dunlap <george.dunlap@xxxxxxxxxx>
Also fix Makefile rule to use correct automatic variable.
Signed-off-by: George Dunlap <george.dunlap@xxxxxxxxxx>
---
Makefile | 4 ++--
main.go | 59 --------------------------------------------------
processworker.go | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 68 insertions(+), 61 deletions(-)
create mode 100644 processworker.go
diff --git a/Makefile b/Makefile
index 736d959..00f732a 100644
--- a/Makefile
+++ b/Makefile
@@ -4,8 +4,8 @@ BINALL = $(BIN)
.PHONY: all
all: $(BIN)
-controller: main.go
- go build -o $@ $<
+controller: main.go processworker.go
+ go build -o $@ $^
.PHONY: clean
clean:
diff --git a/main.go b/main.go
index 034e2f2..a4986cf 100644
--- a/main.go
+++ b/main.go
@@ -3,11 +3,7 @@ package main
import (
"fmt"
"os"
- "os/exec"
"os/signal"
- "encoding/json"
- "bufio"
- "io"
)
@@ -25,61 +21,6 @@ type Worker interface {
Process(chan WorkerReport, chan bool)
}
-type ProcessWorker struct {
- id int
- c *exec.Cmd
- stdout io.ReadCloser
- jsonStarted bool
-}
-
-func (w *ProcessWorker) SetId(i int) {
- w.id = i
-}
-
-func (w *ProcessWorker) Init() (err error) {
- w.c = exec.Command("../worker/worker-proc", "burnwait", "20",
"20000000")
-
- w.stdout, err = w.c.StdoutPipe()
- if err != nil {
- fmt.Print("Conneting to stdout: ", err)
- return
- }
-
- return
-}
-
-func (w *ProcessWorker) Shutdown() {
- w.c.Process.Kill()
-}
-
-func (w *ProcessWorker) Process(report chan WorkerReport, done chan bool) {
- w.c.Start()
-
- scanner := bufio.NewScanner(w.stdout)
-
- for scanner.Scan() {
- s := scanner.Text()
-
- //fmt.Println("Got these bytes: ", s);
-
- if w.jsonStarted {
- var r WorkerReport
- json.Unmarshal([]byte(s), &r)
- r.Id = w.id
- report <- r
- } else {
- if s == "START JSON" {
- //fmt.Println("Got token to start parsing json")
- w.jsonStarted = true
- }
- }
- }
-
- done <- true
-
- w.c.Wait()
-}
-
const (
USEC = 1000
MSEC = USEC * 1000
diff --git a/processworker.go b/processworker.go
new file mode 100644
index 0000000..c1d1fd5
--- /dev/null
+++ b/processworker.go
@@ -0,0 +1,66 @@
+package main
+
+import (
+ "fmt"
+ "os/exec"
+ "encoding/json"
+ "bufio"
+ "io"
+
+)
+
+type ProcessWorker struct {
+ id int
+ c *exec.Cmd
+ stdout io.ReadCloser
+ jsonStarted bool
+}
+
+func (w *ProcessWorker) SetId(i int) {
+ w.id = i
+}
+
+func (w *ProcessWorker) Init() (err error) {
+ w.c = exec.Command("../worker/worker-proc", "burnwait", "20",
"20000000")
+
+ w.stdout, err = w.c.StdoutPipe()
+ if err != nil {
+ fmt.Print("Conneting to stdout: ", err)
+ return
+ }
+
+ return
+}
+
+func (w *ProcessWorker) Shutdown() {
+ w.c.Process.Kill()
+}
+
+func (w *ProcessWorker) Process(report chan WorkerReport, done chan bool) {
+ w.c.Start()
+
+ scanner := bufio.NewScanner(w.stdout)
+
+ for scanner.Scan() {
+ s := scanner.Text()
+
+ //fmt.Println("Got these bytes: ", s);
+
+ if w.jsonStarted {
+ var r WorkerReport
+ json.Unmarshal([]byte(s), &r)
+ r.Id = w.id
+ report <- r
+ } else {
+ if s == "START JSON" {
+ //fmt.Println("Got token to start parsing json")
+ w.jsonStarted = true
+ }
+ }
+ }
+
+ done <- true
+
+ w.c.Wait()
+}
+
--
2.7.4
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
https://lists.xen.org/xen-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |