adding NewReliabilityManager

This commit is contained in:
Gabriel mermelstein 2025-04-09 17:58:42 +03:00
parent cff4062410
commit b90387799a
No known key found for this signature in database
GPG Key ID: 82B8134785FEAE0D
2 changed files with 41 additions and 6 deletions

View File

@ -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

View File

@ -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
################################################################################