mirror of
https://github.com/waku-org/nwaku.git
synced 2025-02-25 05:15:53 +00:00
feat(c-bindings): add function to dealloc nodes (#2499)
This commit is contained in:
parent
161a10ecb0
commit
8341864d30
@ -35,6 +35,11 @@ int waku_stop(void* ctx,
|
||||
WakuCallBack callback,
|
||||
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,
|
||||
WakuCallBack callback,
|
||||
void* userData);
|
||||
|
@ -100,6 +100,20 @@ proc waku_new(configJson: cstring,
|
||||
|
||||
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,
|
||||
callback: WakuCallBack,
|
||||
userData: pointer): cint {.dynlib, exportc.} =
|
||||
|
@ -95,12 +95,16 @@ proc createWakuThread*(): Result[ptr Context, string] =
|
||||
|
||||
return ok(ctx)
|
||||
|
||||
proc stopWakuNodeThread*(ctx: ptr Context) =
|
||||
proc stopWakuThread*(ctx: ptr Context): Result[void, string] =
|
||||
running.store(false)
|
||||
let fireRes = ctx.reqSignal.fireSync()
|
||||
if fireRes.isErr():
|
||||
return err("error in stopWakuThread: " & $fireRes.error)
|
||||
joinThread(ctx.thread)
|
||||
discard ctx.reqSignal.close()
|
||||
discard ctx.respSignal.close()
|
||||
freeShared(ctx)
|
||||
return ok()
|
||||
|
||||
proc sendRequestToWakuThread*(ctx: ptr Context,
|
||||
reqType: RequestType,
|
||||
|
Loading…
x
Reference in New Issue
Block a user