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",
|
"bom-ref": "pkg:nim/syndicate_utils",
|
||||||
"name": "syndicate_utils",
|
"name": "syndicate_utils",
|
||||||
"description": "Utilites for Syndicated Actors and Synit",
|
"description": "Utilites for Syndicated Actors and Synit",
|
||||||
"version": "20240606",
|
"version": "20240610",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
"name": "Emery Hemingway"
|
"name": "Emery Hemingway"
|
||||||
|
|
|
@ -30,7 +30,7 @@ proc flush(printer: Printer) {.asyncio.} =
|
||||||
while printer.buffer.len > 0:
|
while printer.buffer.len > 0:
|
||||||
let n = printer.device.write(printer.buffer)
|
let n = printer.device.write(printer.buffer)
|
||||||
if n > 0:
|
if n > 0:
|
||||||
printer.buffer.delete(0, n)
|
printer.buffer.delete(0..<n)
|
||||||
elif n < 0:
|
elif n < 0:
|
||||||
osLastError().osErrorMsg().quit()
|
osLastError().osErrorMsg().quit()
|
||||||
printer.isBusy = false
|
printer.isBusy = false
|
||||||
|
@ -85,20 +85,27 @@ method retract(printer: Printer; t: Turn; h: Handle) =
|
||||||
elif printer.subscriptHandles.contains h:
|
elif printer.subscriptHandles.contains h:
|
||||||
printer.retract(printer.subscriptHandles, CancelAltScript, 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 =
|
proc openPrinter(turn: Turn): Printer =
|
||||||
new result
|
new result
|
||||||
result.facet = turn.facet
|
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()
|
if fd < 0: osLastError().osErrorMsg().quit()
|
||||||
result.device = newAsyncFile(FD fd)
|
result.device = newAsyncFile(FD fd)
|
||||||
result.write(InitializePrinter)
|
result.write(InitializePrinter)
|
||||||
|
|
||||||
runActor(devicePath) do (turn: Turn):
|
runActor(devicePath()) do (turn: Turn):
|
||||||
let printer = turn.newCap openPrinter(turn)
|
let printer = openPrinter(turn)
|
||||||
resolveEnvironment(turn) do (turn: Turn; relay: Cap):
|
resolveEnvironment(turn) do (turn: Turn; relay: Cap):
|
||||||
during(turn, relay, grabWithinType(Resolve)) do (step: Value; cont: Cap):
|
let pat = Resolve?:{0: matchRecord("printer"), 1: grab()}
|
||||||
if step.isRecord("printer"):
|
during(turn, relay, pat) do (cont: Cap):
|
||||||
# Publish for any <printer> step.
|
# 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