mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-01-07 16:33:08 +00:00
feat(c-bindings): add function to dealloc nodes (#2499)
This commit is contained in:
parent
132bb0bbf2
commit
eb80891c1e
@ -35,6 +35,11 @@ int waku_stop(void* ctx,
|
|||||||
WakuCallBack callback,
|
WakuCallBack callback,
|
||||||
void* userData);
|
void* userData);
|
||||||
|
|
||||||
|
// Destroys an instance of a waku node created with waku_new
|
||||||
|
int waku_destroy(void* ctx,
|
||||||
|
WakuCallBack callback,
|
||||||
|
void* userData);
|
||||||
|
|
||||||
int waku_version(void* ctx,
|
int waku_version(void* ctx,
|
||||||
WakuCallBack callback,
|
WakuCallBack callback,
|
||||||
void* userData);
|
void* userData);
|
||||||
|
|||||||
@ -100,6 +100,20 @@ proc waku_new(configJson: cstring,
|
|||||||
|
|
||||||
return ctx
|
return ctx
|
||||||
|
|
||||||
|
proc waku_destroy(ctx: ptr Context,
|
||||||
|
callback: WakuCallBack,
|
||||||
|
userData: pointer): cint {.dynlib, exportc.} =
|
||||||
|
|
||||||
|
if isNil(callback):
|
||||||
|
return RET_MISSING_CALLBACK
|
||||||
|
|
||||||
|
waku_thread.stopWakuThread(ctx).isOkOr:
|
||||||
|
let msg = $error
|
||||||
|
callback(RET_ERR, unsafeAddr msg[0], cast[csize_t](len(msg)), userData)
|
||||||
|
return RET_ERR
|
||||||
|
|
||||||
|
return RET_OK
|
||||||
|
|
||||||
proc waku_version(ctx: ptr Context,
|
proc waku_version(ctx: ptr Context,
|
||||||
callback: WakuCallBack,
|
callback: WakuCallBack,
|
||||||
userData: pointer): cint {.dynlib, exportc.} =
|
userData: pointer): cint {.dynlib, exportc.} =
|
||||||
|
|||||||
@ -95,12 +95,16 @@ proc createWakuThread*(): Result[ptr Context, string] =
|
|||||||
|
|
||||||
return ok(ctx)
|
return ok(ctx)
|
||||||
|
|
||||||
proc stopWakuNodeThread*(ctx: ptr Context) =
|
proc stopWakuThread*(ctx: ptr Context): Result[void, string] =
|
||||||
running.store(false)
|
running.store(false)
|
||||||
|
let fireRes = ctx.reqSignal.fireSync()
|
||||||
|
if fireRes.isErr():
|
||||||
|
return err("error in stopWakuThread: " & $fireRes.error)
|
||||||
joinThread(ctx.thread)
|
joinThread(ctx.thread)
|
||||||
discard ctx.reqSignal.close()
|
discard ctx.reqSignal.close()
|
||||||
discard ctx.respSignal.close()
|
discard ctx.respSignal.close()
|
||||||
freeShared(ctx)
|
freeShared(ctx)
|
||||||
|
return ok()
|
||||||
|
|
||||||
proc sendRequestToWakuThread*(ctx: ptr Context,
|
proc sendRequestToWakuThread*(ctx: ptr Context,
|
||||||
reqType: RequestType,
|
reqType: RequestType,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user