diff options
author | Christian Pointner <equinox@helsinki.at> | 2015-12-30 19:58:28 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2015-12-30 19:58:28 (GMT) |
commit | b44f626200669a57a2bc012d2203c36f587b425b (patch) | |
tree | ebab1722aa041c75dd7535bb9841c28af8b3f2a4 /src/helsinki.at/rhimportd | |
parent | e84dd58a96c80847a18b4674f3ebb600d94227e1 (diff) |
session store and web socket interface now support to set a reference id
Diffstat (limited to 'src/helsinki.at/rhimportd')
-rw-r--r-- | src/helsinki.at/rhimportd/ctrlWebSocket.go | 46 |
1 files changed, 24 insertions, 22 deletions
diff --git a/src/helsinki.at/rhimportd/ctrlWebSocket.go b/src/helsinki.at/rhimportd/ctrlWebSocket.go index 92e261a..ea7bf24 100644 --- a/src/helsinki.at/rhimportd/ctrlWebSocket.go +++ b/src/helsinki.at/rhimportd/ctrlWebSocket.go @@ -37,6 +37,7 @@ import ( type webSocketRequestData struct { Command string `json:"COMMAND"` Id string `json:"ID"` + RefId string `json:"REFERENCE_ID"` UserName string `json:"LOGIN_NAME"` Password string `json:"PASSWORD"` ShowId uint `json:"SHOW_ID"` @@ -79,6 +80,7 @@ type webSocketResponseData struct { Type string `json:"TYPE"` ErrorString string `json:"ERROR_STRING"` Id string `json:"ID"` + RefId string `json:"REFERENCE_ID"` ProgressStep int `json:"PROGRESS_STEP"` ProgressStepName string `json:"PROGRESS_STEP_NAME"` Progress float64 `json:"PROGRESS"` @@ -98,6 +100,7 @@ func sendWebSocketErrorResponse(ws *websocket.Conn, id string, code int, err_str type webSocketSession struct { id string + refId string session *rhimport.SessionChan progresschan chan rhimport.ProgressData donechan chan rhimport.ImportResult @@ -131,7 +134,7 @@ func webSocketDone(res rhimport.ImportResult, userdata interface{}) bool { func (self *webSocketSession) startNewSession(reqdata *webSocketRequestData, conf *rhimport.Config, rddb *rhimport.RdDbChan, sessions *rhimport.SessionStoreChan) (int, string) { ctx := rhimport.NewImportContext(conf, rddb, reqdata.UserName) ctx.Password = reqdata.Password - ctx.Trusted = true // set this to false as soon as the interface is working + ctx.Trusted = true // TODO: set this to false as soon as the interface is working ctx.ShowId = reqdata.ShowId ctx.ClearShowCarts = reqdata.ClearShowCarts ctx.GroupName = reqdata.MusicPoolGroup @@ -144,11 +147,12 @@ func (self *webSocketSession) startNewSession(reqdata *webSocketRequestData, con ctx.UseMetaData = reqdata.UseMetaData ctx.SourceUri = reqdata.SourceUri - id, s, code, errstring := sessions.New(ctx) + id, s, code, errstring := sessions.New(ctx, reqdata.RefId) if code != http.StatusOK { return code, errstring } self.id = id + self.refId = reqdata.RefId self.session = s if err := s.AddDoneHandler((chan<- rhimport.ImportResult)(self.donechan), webSocketDone); err != nil { return http.StatusInternalServerError, err.Error() @@ -161,11 +165,12 @@ func (self *webSocketSession) startNewSession(reqdata *webSocketRequestData, con } func (self *webSocketSession) reconnectSession(reqdata *webSocketRequestData, sessions *rhimport.SessionStoreChan) (int, string) { - s, code, errstring := sessions.Get(reqdata.UserName, reqdata.Id) + s, refId, code, errstring := sessions.Get(reqdata.UserName, reqdata.Id) if code != http.StatusOK { return code, errstring } self.id = reqdata.Id + self.refId = refId self.session = s if err := s.AddDoneHandler((chan<- rhimport.ImportResult)(self.donechan), webSocketDone); err != nil { return http.StatusInternalServerError, err.Error() @@ -191,41 +196,38 @@ func webSocketSessionHandler(reqchan <-chan webSocketRequestData, ws *websocket. case "new": if session.id != "" { sendWebSocketErrorResponse(ws, "", http.StatusBadRequest, "This connection already handles a session") - return - } - code, errstring := session.startNewSession(&reqdata, conf, rddb, sessions) - if code != http.StatusOK { - sendWebSocketErrorResponse(ws, "", code, errstring) - return } else { - sendWebSocketResponse(ws, &webSocketResponseData{ResponseCode: code, Type: "ACK", Id: session.id}) + code, errstring := session.startNewSession(&reqdata, conf, rddb, sessions) + if code != http.StatusOK { + sendWebSocketErrorResponse(ws, "", code, errstring) + } else { + sendWebSocketResponse(ws, &webSocketResponseData{ResponseCode: code, Type: "ACK", Id: session.id, RefId: session.refId}) + } } case "cancel": if session.id == "" { sendWebSocketErrorResponse(ws, "", http.StatusBadRequest, "This connection doesn't handle any session") - return + } else { + session.session.Cancel() } - session.session.Cancel() case "reconnect": if session.id != "" { sendWebSocketErrorResponse(ws, "", http.StatusBadRequest, "This connection already handles a session") - return - } - code, errstring := session.reconnectSession(&reqdata, sessions) - if code != http.StatusOK { - sendWebSocketErrorResponse(ws, "", code, errstring) - return } else { - sendWebSocketResponse(ws, &webSocketResponseData{ResponseCode: code, Type: "ACK", Id: session.id}) + code, errstring := session.reconnectSession(&reqdata, sessions) + if code != http.StatusOK { + sendWebSocketErrorResponse(ws, "", code, errstring) + } else { + sendWebSocketResponse(ws, &webSocketResponseData{ResponseCode: code, Type: "ACK", Id: session.id, RefId: session.refId}) + } } default: sendWebSocketErrorResponse(ws, "", http.StatusBadRequest, fmt.Sprintf("unknown command '%s'", reqdata.Command)) - return } case p := <-session.progresschan: - sendWebSocketResponse(ws, &webSocketResponseData{http.StatusOK, "PROGRESS", "", session.id, p.Step, p.StepName, p.Progress * 100, 0, 0}) + sendWebSocketResponse(ws, &webSocketResponseData{http.StatusOK, "PROGRESS", "", session.id, session.refId, 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}) + sendWebSocketResponse(ws, &webSocketResponseData{d.ResponseCode, "DONE", d.ErrorString, session.id, session.refId, 0, "", 100.0, d.Cart, d.Cut}) // TODO: send close message at this point? } } |