From e84dd58a96c80847a18b4674f3ebb600d94227e1 Mon Sep 17 00:00:00 2001
From: Christian Pointner <equinox@helsinki.at>
Date: Wed, 30 Dec 2015 20:23:52 +0100
Subject: some cleanup


diff --git a/src/helsinki.at/rhimport/session.go b/src/helsinki.at/rhimport/session.go
index 94ce66a..36e7938 100644
--- a/src/helsinki.at/rhimport/session.go
+++ b/src/helsinki.at/rhimport/session.go
@@ -67,9 +67,9 @@ type SessionDoneCB struct {
 }
 
 type ProgressData struct {
-	step      int
-	step_name string
-	progress  float64
+	Step     int
+	StepName string
+	Progress float64
 }
 
 type sessionAddProgressHandlerResponse struct {
@@ -159,7 +159,7 @@ func (self *Session) addDoneHandler(userdata interface{}, cb func(ImportResult,
 func (self *Session) callProgressHandler(p *ProgressData) {
 	for _, cb := range self.progressCBs {
 		if cb.cb != nil {
-			if keep := cb.cb(p.step, p.step_name, p.progress, cb.userdata); !keep {
+			if keep := cb.cb(p.Step, p.StepName, p.Progress, cb.userdata); !keep {
 				cb.cb = nil
 			}
 		}
diff --git a/src/helsinki.at/rhimportd/ctrlWebSocket.go b/src/helsinki.at/rhimportd/ctrlWebSocket.go
index 346dd6a..92e261a 100644
--- a/src/helsinki.at/rhimportd/ctrlWebSocket.go
+++ b/src/helsinki.at/rhimportd/ctrlWebSocket.go
@@ -97,15 +97,15 @@ func sendWebSocketErrorResponse(ws *websocket.Conn, id string, code int, err_str
 }
 
 type webSocketSession struct {
-	id       string
-	session  *rhimport.SessionChan
-	respchan chan webSocketResponseData
-	donechan chan rhimport.ImportResult
+	id           string
+	session      *rhimport.SessionChan
+	progresschan chan rhimport.ProgressData
+	donechan     chan rhimport.ImportResult
 }
 
 func newWebSocketSession() *webSocketSession {
 	session := &webSocketSession{}
-	session.respchan = make(chan webSocketResponseData, 10)
+	session.progresschan = make(chan rhimport.ProgressData, 10)
 	session.donechan = make(chan rhimport.ImportResult, 1)
 	return session
 }
@@ -114,17 +114,17 @@ func webSocketProgress(step int, step_name string, progress float64, userdata in
 	if math.IsNaN(progress) {
 		progress = 0.0
 	}
-	session := userdata.(*webSocketSession)
+	c := userdata.(chan<- rhimport.ProgressData)
 	select {
-	case session.respchan <- webSocketResponseData{http.StatusOK, "PROGRESS", "", session.id, step, step_name, progress * 100, 0, 0}:
+	case c <- rhimport.ProgressData{step, step_name, progress}:
 	default:
 	}
 	return true
 }
 
 func webSocketDone(res rhimport.ImportResult, userdata interface{}) bool {
-	session := userdata.(*webSocketSession)
-	session.donechan <- res
+	c := userdata.(chan<- rhimport.ImportResult)
+	c <- res
 	return true
 }
 
@@ -150,10 +150,10 @@ func (self *webSocketSession) startNewSession(reqdata *webSocketRequestData, con
 	}
 	self.id = id
 	self.session = s
-	if err := s.AddDoneHandler(self, webSocketDone); err != nil {
+	if err := s.AddDoneHandler((chan<- rhimport.ImportResult)(self.donechan), webSocketDone); err != nil {
 		return http.StatusInternalServerError, err.Error()
 	}
-	if err := s.AddProgressHandler(self, webSocketProgress); err != nil {
+	if err := s.AddProgressHandler((chan<- rhimport.ProgressData)(self.progresschan), webSocketProgress); err != nil {
 		return http.StatusInternalServerError, err.Error()
 	}
 	s.Run(time.Duration(reqdata.Timeout) * time.Second)
@@ -167,10 +167,10 @@ func (self *webSocketSession) reconnectSession(reqdata *webSocketRequestData, se
 	}
 	self.id = reqdata.Id
 	self.session = s
-	if err := s.AddDoneHandler(self, webSocketDone); err != nil {
+	if err := s.AddDoneHandler((chan<- rhimport.ImportResult)(self.donechan), webSocketDone); err != nil {
 		return http.StatusInternalServerError, err.Error()
 	}
-	if err := s.AddProgressHandler(self, webSocketProgress); err != nil {
+	if err := s.AddProgressHandler((chan<- rhimport.ProgressData)(self.progresschan), webSocketProgress); err != nil {
 		return http.StatusInternalServerError, err.Error()
 	}
 	s.Run(time.Duration(reqdata.Timeout) * time.Second)
@@ -222,10 +222,10 @@ func webSocketSessionHandler(reqchan <-chan webSocketRequestData, ws *websocket.
 				sendWebSocketErrorResponse(ws, "", http.StatusBadRequest, fmt.Sprintf("unknown command '%s'", reqdata.Command))
 				return
 			}
-		case respdata := <-session.respchan:
-			sendWebSocketResponse(ws, &respdata)
-		case donedata := <-session.donechan:
-			sendWebSocketResponse(ws, &webSocketResponseData{donedata.ResponseCode, "DONE", donedata.ErrorString, session.id, 0, "", 100.0, donedata.Cart, donedata.Cut})
+		case p := <-session.progresschan:
+			sendWebSocketResponse(ws, &webSocketResponseData{http.StatusOK, "PROGRESS", "", session.id, p.Step, p.StepName, p.Progress * 100, 0, 0})
+		case d := <-session.donechan:
+			sendWebSocketResponse(ws, &webSocketResponseData{d.ResponseCode, "DONE", d.ErrorString, session.id, 0, "", 100.0, d.Cart, d.Cut})
 			// TODO: send close message at this point?
 		}
 	}
-- 
cgit v0.10.2