2025-12-19 17:00:43 +01:00
|
|
|
import ffi
|
2026-07-09 15:57:16 -03:00
|
|
|
import results
|
2026-06-23 01:20:09 +02:00
|
|
|
import logos_delivery
|
2025-12-19 17:00:43 +01:00
|
|
|
|
2026-08-06 23:53:38 -03:00
|
|
|
declareLibrary("logosdelivery", LogosDelivery, defaultABIFormat = "c")
|
2026-07-31 13:50:59 -03:00
|
|
|
|
|
|
|
|
template emitEvent*(eventName: string, body: untyped) =
|
|
|
|
|
## Enqueues `body`'s payload for nim-ffi's event thread to fan out to listeners.
|
|
|
|
|
## Callers are `{.async: (raises: []).}` broker listeners, and the payload
|
|
|
|
|
## builders infer an `Exception` effect, so nothing narrower than `Exception`
|
|
|
|
|
## compiles here. That also swallows `Defect`, which is why the handler only
|
|
|
|
|
## logs: a defect raised while rendering one event must not take the node down,
|
|
|
|
|
## and it cannot be re-raised without breaking the `raises: []` contract.
|
|
|
|
|
try:
|
|
|
|
|
dispatchFFIEvent(eventName):
|
|
|
|
|
body
|
|
|
|
|
except Exception as e:
|
|
|
|
|
chronicles.error "failed to emit FFI event", event = eventName, err = e.msg
|
2026-06-15 13:03:44 +02:00
|
|
|
|
2026-08-06 23:53:38 -03:00
|
|
|
template requireMessaging*(self: LogosDelivery, opName: string, onError: untyped) =
|
|
|
|
|
## Fails if the node has no messaging client (a kernel-only / fleet node).
|
|
|
|
|
self.ensureMessaging().isOkOr:
|
2026-07-09 15:57:16 -03:00
|
|
|
let errMsg {.inject.} = opName & " failed: " & error
|
|
|
|
|
onError
|
|
|
|
|
|
2026-08-06 23:53:38 -03:00
|
|
|
template requireChannels*(self: LogosDelivery, opName: string, onError: untyped) =
|
|
|
|
|
## Fails if the node has no reliable channel manager (a kernel-only / fleet node).
|
|
|
|
|
self.ensureChannels().isOkOr:
|
2026-07-09 15:57:16 -03:00
|
|
|
let errMsg {.inject.} = opName & " failed: " & error
|
|
|
|
|
onError
|