Skip to content

Commit

Permalink
Merge 1adfb48 into beba14d
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-ramos committed Mar 6, 2024
2 parents beba14d + 1adfb48 commit 6a94ea2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
5 changes: 5 additions & 0 deletions library/libwaku.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 14 additions & 0 deletions library/libwaku.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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.} =
Expand Down
6 changes: 5 additions & 1 deletion library/waku_thread/waku_thread.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 6a94ea2

Please sign in to comment.