esc-printer-driver: fresh caps for clients
This commit is contained in:
parent
9b670d2c24
commit
6a4b34afcb
|
@ -7,7 +7,7 @@
|
|||
"bom-ref": "pkg:nim/syndicate_utils",
|
||||
"name": "syndicate_utils",
|
||||
"description": "Utilites for Syndicated Actors and Synit",
|
||||
"version": "20240606",
|
||||
"version": "20240610",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Emery Hemingway"
|
||||
|
|
|
@ -30,7 +30,7 @@ proc flush(printer: Printer) {.asyncio.} =
|
|||
while printer.buffer.len > 0:
|
||||
let n = printer.device.write(printer.buffer)
|
||||
if n > 0:
|
||||
printer.buffer.delete(0, n)
|
||||
printer.buffer.delete(0..<n)
|
||||
elif n < 0:
|
||||
osLastError().osErrorMsg().quit()
|
||||
printer.isBusy = false
|
||||
|
@ -85,20 +85,27 @@ method retract(printer: Printer; t: Turn; h: Handle) =
|
|||
elif printer.subscriptHandles.contains h:
|
||||
printer.retract(printer.subscriptHandles, CancelAltScript, h)
|
||||
|
||||
let devicePath = paramStr(1)
|
||||
|
||||
proc devicePath: string =
|
||||
if paramCount() < 1:
|
||||
quit "missing path to printer device file"
|
||||
if paramCount() > 1:
|
||||
quit "too many command line parameters"
|
||||
paramStr(1)
|
||||
|
||||
proc openPrinter(turn: Turn): Printer =
|
||||
new result
|
||||
result.facet = turn.facet
|
||||
let fd = posix.open(devicePath, O_WRONLY or O_NONBLOCK, 0)
|
||||
let fd = posix.open(devicePath(), O_WRONLY or O_NONBLOCK, 0)
|
||||
if fd < 0: osLastError().osErrorMsg().quit()
|
||||
result.device = newAsyncFile(FD fd)
|
||||
result.write(InitializePrinter)
|
||||
|
||||
runActor(devicePath) do (turn: Turn):
|
||||
let printer = turn.newCap openPrinter(turn)
|
||||
runActor(devicePath()) do (turn: Turn):
|
||||
let printer = openPrinter(turn)
|
||||
resolveEnvironment(turn) do (turn: Turn; relay: Cap):
|
||||
during(turn, relay, grabWithinType(Resolve)) do (step: Value; cont: Cap):
|
||||
if step.isRecord("printer"):
|
||||
let pat = Resolve?:{0: matchRecord("printer"), 1: grab()}
|
||||
during(turn, relay, pat) do (cont: Cap):
|
||||
# Publish for any <printer> step.
|
||||
discard publish(turn, cont, ResolvedAccepted(responderSession: printer))
|
||||
discard publish(turn, cont, ResolvedAccepted(
|
||||
responderSession: turn.newCap(printer)))
|
||||
|
|
Loading…
Reference in New Issue