34 lines
1.2 KiB
Nim
34 lines
1.2 KiB
Nim
# SPDX-FileCopyrightText: ☭ Emery Hemingway
|
|
# SPDX-License-Identifier: Unlicense
|
|
|
|
const withLibrrd* {.booldefine.}: bool = true
|
|
|
|
when withLibrrd:
|
|
import preserves, syndicate, syndicate/relays
|
|
import ../schema/[config, rrd]
|
|
|
|
{.passC: staticExec("pkg-config --cflags librrd").}
|
|
{.passL: staticExec("pkg-config --libs librrd").}
|
|
|
|
{.pragma: librrd, header: "rrd.h", importc.}
|
|
|
|
proc rrd_update(a1: cint; a2: cstringArray): cint {.librrd.}
|
|
proc rrd_get_error(): cstring {.librrd.}
|
|
proc rrd_clear_error() {.librrd.}
|
|
|
|
proc spawnRrdActor*(turn: var Turn; root: Cap): Actor {.discardable.} =
|
|
spawn("rrd-actor", turn) do (turn: var Turn):
|
|
during(turn, root, ?:RrdArguments) do (ds: Cap):
|
|
let updatePattern = RRDaction ?: {0: ?Symbol"update", 1: grab()}
|
|
onMessage(turn, ds, updatePattern) do (args: seq[string]):
|
|
var argv = allocCStringArray(args)
|
|
if rrd_update(args.len.cint, argv) != 0:
|
|
stderr.writeLine(rrd_get_error())
|
|
rrd_clear_error()
|
|
deallocCStringArray(argv)
|
|
|
|
when isMainModule:
|
|
runActor("main") do (turn: var Turn; root: Cap):
|
|
connectStdio(turn, root)
|
|
spawnRrdActor(turn, root)
|