esc-printer-actor: use gatekeeper protocol
This commit is contained in:
parent
12ed9cd35b
commit
59ca3d2443
|
@ -45,6 +45,8 @@ PostgreArguments = <postgre {
|
||||||
}>.
|
}>.
|
||||||
PostgreConnectionParameter = [@key string @val string].
|
PostgreConnectionParameter = [@key string @val string].
|
||||||
|
|
||||||
|
PrinterStep = <printer {}> .
|
||||||
|
|
||||||
PulseArguments = <pulse {
|
PulseArguments = <pulse {
|
||||||
dataspace: #:any
|
dataspace: #:any
|
||||||
}>.
|
}>.
|
||||||
|
|
|
@ -7,6 +7,7 @@ import
|
||||||
std/[cmdline, oserrors, posix, sets],
|
std/[cmdline, oserrors, posix, sets],
|
||||||
preserves, preserves/sugar,
|
preserves, preserves/sugar,
|
||||||
syndicate, syndicate/relays,
|
syndicate, syndicate/relays,
|
||||||
|
syndicate/protocols/[gatekeeper, sturdy],
|
||||||
./private/esc_p
|
./private/esc_p
|
||||||
|
|
||||||
proc echo(args: varargs[string, `$`]) {.used.} =
|
proc echo(args: varargs[string, `$`]) {.used.} =
|
||||||
|
@ -67,18 +68,18 @@ 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)
|
||||||
|
|
||||||
proc openPrinter(turn: Turn; devicePath: string): Printer =
|
let devicePath = paramStr(1)
|
||||||
|
|
||||||
|
proc openPrinter(turn: Turn): Printer =
|
||||||
new result
|
new result
|
||||||
result.facet = turn.facet
|
result.facet = turn.facet
|
||||||
result.device = posix.open(devicePath, O_WRONLY, 0)
|
result.device = posix.open(devicePath, O_WRONLY, 0)
|
||||||
result.write(InitializePrinter)
|
result.write(InitializePrinter)
|
||||||
|
|
||||||
proc main =
|
runActor(devicePath) do (turn: Turn):
|
||||||
let devicePath = paramStr(1)
|
let printer = turn.newCap openPrinter(turn)
|
||||||
runActor(devicePath) do (turn: Turn):
|
resolveEnvironment(turn) do (turn: Turn; relay: Cap):
|
||||||
let printer = turn.newCap openPrinter(turn, devicePath)
|
during(turn, relay, grabWithinType(Resolve)) do (step: Value; cont: Cap):
|
||||||
resolveEnvironment(turn) do (turn: Turn; ds: Cap):
|
if step.isRecord("printer"):
|
||||||
publish(turn, ds, initRecord(
|
# Publish for any <printer> step.
|
||||||
toSymbol"printer", printer.embed, %devicePath))
|
discard publish(turn, cont, ResolvedAccepted(responderSession: printer))
|
||||||
|
|
||||||
main()
|
|
||||||
|
|
|
@ -119,6 +119,11 @@ type
|
||||||
UnixAddress* {.preservesRecord: "unix".} = object
|
UnixAddress* {.preservesRecord: "unix".} = object
|
||||||
`path`*: string
|
`path`*: string
|
||||||
|
|
||||||
|
PrinterStepField0* {.preservesDictionary.} = object
|
||||||
|
|
||||||
|
PrinterStep* {.preservesRecord: "printer".} = object
|
||||||
|
`field0`*: PrinterStepField0
|
||||||
|
|
||||||
Tcp* {.preservesRecord: "tcp".} = object
|
Tcp* {.preservesRecord: "tcp".} = object
|
||||||
`host`*: string
|
`host`*: string
|
||||||
`port`*: BiggestInt
|
`port`*: BiggestInt
|
||||||
|
@ -140,6 +145,7 @@ proc `$`*(x: WebsocketArguments | HttpClientArguments | JsonTranslatorArguments
|
||||||
PostgreArguments |
|
PostgreArguments |
|
||||||
PulseArguments |
|
PulseArguments |
|
||||||
UnixAddress |
|
UnixAddress |
|
||||||
|
PrinterStep |
|
||||||
Tcp): string =
|
Tcp): string =
|
||||||
`$`(toPreserves(x))
|
`$`(toPreserves(x))
|
||||||
|
|
||||||
|
@ -161,5 +167,6 @@ proc encode*(x: WebsocketArguments | HttpClientArguments |
|
||||||
PostgreArguments |
|
PostgreArguments |
|
||||||
PulseArguments |
|
PulseArguments |
|
||||||
UnixAddress |
|
UnixAddress |
|
||||||
|
PrinterStep |
|
||||||
Tcp): seq[byte] =
|
Tcp): seq[byte] =
|
||||||
encode(toPreserves(x))
|
encode(toPreserves(x))
|
||||||
|
|
Loading…
Reference in New Issue