epc request/response barebones

This commit is contained in:
Simon Hafner 2015-04-26 08:37:55 +05:00
commit 58570a4a30

View file

@ -80,9 +80,20 @@ proc sexp(s: seq[Suggest]): SexpNode =
proc listEPC(): SexpNode = proc listEPC(): SexpNode =
discard discard
proc executeEPC(body: SexpNode) = proc executeEPC(section: Section, args: SexpNode) =
let
file = args[0].getStr
line = args[1].getNum
column = args[2].getNum
dirtyfile = args[3].getStr(nil)
discard discard
proc returnEPC(socket: var Socket, uid: string, s: SexpNode) =
let response = $convertSexp([newSSymbol("return"), [uid, s]])
socket.send(toHex(len(response), 6))
socket.send(response)
socket.close()
proc action(cmd: string) = proc action(cmd: string) =
template toggle(sw) = template toggle(sw) =
if sw in gGlobalOptions: if sw in gGlobalOptions:
@ -194,11 +205,12 @@ proc serve() =
let body = message[1] let body = message[1]
case messageType: case messageType:
of "call": of "call":
executeEPC(body) let
let response = $sexp(results) uid = body[0].getStr
client.send(toHex(len(response), 6)) section = parseEnum[Section](body[1].getStr)
client.send(response) args = body[2]
client.close() executeEPC(section, args)
returnEPC(client, uid, sexp(results))
of "return": of "return":
raise newException(ValueError, "no return expected") raise newException(ValueError, "no return expected")
of "return-error": of "return-error":
@ -207,10 +219,7 @@ proc serve() =
stderr.writeln("recieved epc error: " & $messageBuffer) stderr.writeln("recieved epc error: " & $messageBuffer)
raise newException(ValueError, "epc error") raise newException(ValueError, "epc error")
of "methods": of "methods":
let response = $listEPC() returnEPC(client, body[0].getStr, listEPC())
client.send(toHex(len(response), 6))
client.send(response)
client.close()
else: else:
raise newException(ValueError, "unexpected call: " & messageType) raise newException(ValueError, "unexpected call: " & messageType)