mirror of
https://github.com/logos-messaging/logos-delivery.git
synced 2026-02-28 06:03:39 +00:00
34 lines
932 B
Nim
34 lines
932 B
Nim
import ffi
|
|
import std/locks
|
|
import waku/factory/waku
|
|
|
|
declareLibrary("logosdelivery")
|
|
|
|
var eventCallbackLock: Lock
|
|
initLock(eventCallbackLock)
|
|
|
|
template requireInitializedNode*(
|
|
ctx: ptr FFIContext[Waku], opName: string, onError: untyped
|
|
) =
|
|
if isNil(ctx):
|
|
let errMsg {.inject.} = opName & " failed: invalid context"
|
|
onError
|
|
elif isNil(ctx.myLib) or isNil(ctx.myLib[]):
|
|
let errMsg {.inject.} = opName & " failed: node is not initialized"
|
|
onError
|
|
|
|
proc logosdelivery_set_event_callback(
|
|
ctx: ptr FFIContext[Waku], callback: FFICallBack, userData: pointer
|
|
) {.dynlib, exportc, cdecl.} =
|
|
if isNil(ctx):
|
|
echo "error: invalid context in logosdelivery_set_event_callback"
|
|
return
|
|
|
|
# prevent race conditions that might happen due incorrect usage.
|
|
eventCallbackLock.acquire()
|
|
defer:
|
|
eventCallbackLock.release()
|
|
|
|
ctx[].eventCallback = cast[pointer](callback)
|
|
ctx[].eventUserData = userData
|