From b90387799a83958a4fae2ea3a7ec70886740c2ed Mon Sep 17 00:00:00 2001 From: Gabriel mermelstein Date: Wed, 9 Apr 2025 17:58:42 +0300 Subject: [PATCH] adding NewReliabilityManager --- library/libsds.h | 7 +------ library/libsds.nim | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/library/libsds.h b/library/libsds.h index f34daf4..aa2909a 100644 --- a/library/libsds.h +++ b/library/libsds.h @@ -28,12 +28,7 @@ typedef void (*SdsCallBack) (int callerRet, const char* msg, size_t len, void* u * @param channelId A unique identifier for the communication channel. * @return An opaque handle (void*) representing the instance, or NULL on failure. */ -void* sds_reliability_manager_new(char* channelId); - -/* void* waku_new( - const char* configJson, - WakuCallBack callback, - void* userData); */ +void* NewReliabilityManager(char* channelId); #ifdef __cplusplus diff --git a/library/libsds.nim b/library/libsds.nim index 1671b53..81e8362 100644 --- a/library/libsds.nim +++ b/library/libsds.nim @@ -13,6 +13,7 @@ import ./alloc, ./ffi_types, ./sds_thread/inter_thread_communication/sds_thread_request, + ./sds_thread/inter_thread_communication/requests/sds_lifecycle_request, ../src/[reliability, reliability_utils, message] ################################################################################ @@ -102,3 +103,42 @@ proc initializeLibrary() {.exported.} = ### End of library setup ################################################################################ + +################################################################################ +### Exported procs + +proc NewReliabilityManager( + channelId: cstring, callback: SdsCallback, userData: pointer +): pointer {.dynlib, exportc, cdecl.} = + initializeLibrary() + + ## Creates a new instance of the WakuNode. + if isNil(callback): + echo "error: missing callback in NewReliabilityManager" + return nil + + ## Create the SDS thread that will keep waiting for req from the main thread. + var ctx = sds_thread.createSdsThread().valueOr: + let msg = "Error in createSdsThread: " & $error + callback(RET_ERR, unsafeAddr msg[0], cast[csize_t](len(msg)), userData) + return nil + + ctx.userData = userData + + let retCode = handleRequest( + ctx, + RequestType.LIFECYCLE, + SdsLifecycleRequest.createShared( + SdsLifecycleMsgType.CREATE_RELIABILITY_MANAGER, channelId + ), + callback, + userData, + ) + + if retCode == RET_ERR: + return nil + + return ctx + +### End of exported procs +################################################################################