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