Skip to content

Commit

Permalink
Merge pull request #448 from mstreeter10/adapter-cleanup
Browse files Browse the repository at this point in the history
udb: adapter cleanup
  • Loading branch information
Jafaral authored May 3, 2024
2 parents 4a74fb0 + 16f08dd commit a5c4f6d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 20 deletions.
37 changes: 24 additions & 13 deletions uni/udb/adapter.icn
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ class Adapter(
return cmd
}
every request_body := get_request(sock) do {
#write("command: "||jtou(request_body)["command"]||"\n")
$ifdef VERBOSE
write("client -> udb:\n" || request_body)
$endif
if \waitingForTerminal then {
if jtou(request_body)["command"] ~== "runInTerminal" then {
#write("put "||jtou(request_body)["command"])
Expand Down Expand Up @@ -212,12 +214,12 @@ class Adapter(

responseHeader := "Content-Length:" || *responseBody || "\r\n\r\n"

#write(ximage(responseTable))

#write("udap -> client: " || responseBody)

seq +:= 1

$ifdef VERBOSE
write("udb -> client:\n" || responseBody)
$endif

return responseHeader || responseBody
end

Expand All @@ -235,10 +237,12 @@ class Adapter(
requestBody := tojson(requestTable)
requestHeader := "Content-Length:" || *requestBody || "\r\n\r\n"

#write("udap -> client: " || requestBody)

seq +:= 1

$ifdef VERBOSE
write("udb -> client:\n" || requestBody)
$endif

return requestHeader || requestBody
end

Expand All @@ -260,10 +264,12 @@ class Adapter(
])
eventHeader := "Content-Length:" || *eventBody || "\r\n\r\n"

#write("udap -> client: " || eventBody)

seq +:= 1

$ifdef VERBOSE
write("udb -> client:\n" || eventBody)
$endif

return eventHeader || eventBody
end

Expand Down Expand Up @@ -914,14 +920,15 @@ class Adapter(
writes(sock, event)
end

# Disconnect from client and udb and startup as a fresh session.
# Disconnect from client and udb and end session.
method disconnect()
close(\dapcomSock)
# Kill terminal running dapcom
kill(\shellProcessId, 9)
# End communication with client
close(\sock)
# Restart session
put_cmdQueue("reset")
# End session
exit()
end

# Open a port as a server and block until client connect.
Expand All @@ -934,8 +941,12 @@ class Adapter(
every !5 do
if sock := open(port, "na") then
return sock
else
else {
$ifdef VERBOSE
write("open(",port,") ERROR: ", \&errortext | "Unknown")
$endif
delay(1000)
}

#write("udap failed to open port: " || port)
end
Expand Down
4 changes: 3 additions & 1 deletion uni/udb/console.icn
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ method get_Line()
]
}

writes(PROMPT)
if \mode ~== "--adapter" then {
writes(PROMPT)
}

# if line mode, read a whole line the old fashioned way, skip this function
if \mode == "--line" | \mode == "--adapter" then
Expand Down
6 changes: 0 additions & 6 deletions uni/udb/state.icn
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,10 @@ method Write(Msg)
if member(Msg, "consoleMsg") then
Msg["consoleMsg"] := replacem(\Msg["consoleMsg"], "\"", "\\\"")
Msg["state"] := State
# write(sock, utoj(Msg))
udap.processResult(Msg)
}
else {
output := ["consoleMsg": replacem(Msg, "\"", "\\\""); "state": State]
# write(sock, utoj(output))
write("\nprocess result called\n")
udap.processResult(output)
}
}
Expand All @@ -84,7 +81,6 @@ end
method stateRead()
local msg := ""
if \mode == "--adapter" then {
write("udb reading...")
return udap.getNextCommand()
}
else {
Expand All @@ -106,12 +102,10 @@ method Writes(Msg)
if member(Msg, "consoleMsg") then
Msg["consoleMsg"] := replacem(\Msg["consoleMsg"], "\"", "\\\"")
Msg["state"] := State
#writes(sock, utoj(Msg))
udap.processResult(Msg)
}
else {
output := ["consoleMsg": replacem(Msg, "\"", "\\\""); "state": State]
#writes(sock, utoj(output))
udap.processResult(output)
}
}
Expand Down

0 comments on commit a5c4f6d

Please sign in to comment.