Ivan FB c64d156f2a
FFI: migrate liblogosdelivery root to nim-ffi v0.2.0-rc.3
Rewrite the FFI root over the new per-layer APIs using nim-ffi v0.2.0 typed
{.ffiCtor.}/{.ffiDtor.}/{.ffi.}/{.ffiEvent.} + CBOR, replacing the
hand-written cstring/JSON bridge. Events are fed by internal nim-broker
listeners (no AppCallbacks). Adds the messaging_api/channels_api groups and
the broker-listener event modules, and drops the v0.1 scaffolding
(declare_lib, node_api, node_lifecycle_api, logos_delivery_api/*, json_*).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-25 04:18:35 +02:00

34 lines
1.1 KiB
Nim

## Reliable-channel events: per-channel message received / sent / errored,
## fed by the channel-layer broker events.
proc onChannelMessageReceived*(
channelId: string, senderId: string, payload: seq[byte]
) {.ffiEvent: "on_channel_message_received".}
proc onChannelMessageSent*(
channelId: string, requestId: string
) {.ffiEvent: "on_channel_message_sent".}
proc onChannelMessageError*(
channelId: string, requestId: string, error: string
) {.ffiEvent: "on_channel_message_error".}
proc listenChannelEvents(self: LogosDelivery) =
let brokerCtx = self.waku.brokerCtx
discard ChannelMessageReceivedEvent.listen(
brokerCtx,
proc(e: ChannelMessageReceivedEvent) {.async: (raises: []).} =
onChannelMessageReceived(string(e.channelId), $e.senderId, e.payload),
)
discard ChannelMessageSentEvent.listen(
brokerCtx,
proc(e: ChannelMessageSentEvent) {.async: (raises: []).} =
onChannelMessageSent(string(e.channelId), $e.requestId),
)
discard ChannelMessageErrorEvent.listen(
brokerCtx,
proc(e: ChannelMessageErrorEvent) {.async: (raises: []).} =
onChannelMessageError(string(e.channelId), $e.requestId, e.error),
)