From 315e1de72e924f3fce0cd2ac20427da2a5bc216b Mon Sep 17 00:00:00 2001 From: Prem Chaitanya Prathi Date: Tue, 5 Mar 2024 20:36:35 +0530 Subject: [PATCH] chore: callback integration in progress --- cpp/negentropy_wrapper.c | 15 +++++++++------ cpp/negentropy_wrapper.h | 4 ++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/cpp/negentropy_wrapper.c b/cpp/negentropy_wrapper.c index a155c49..f624a7f 100644 --- a/cpp/negentropy_wrapper.c +++ b/cpp/negentropy_wrapper.c @@ -126,7 +126,7 @@ void transform(std::vector &from_ids, buffer* to_ids) } } -int reconcile_with_ids(void* negentropy, buffer* query,reconcile_cbk cbk){ +int reconcile_with_ids(void* negentropy, buffer* query,reconcile_cbk cbk, char* outptr){ Negentropy *ngn_inst; ngn_inst = reinterpret_cast*>(negentropy); @@ -145,25 +145,28 @@ int reconcile_with_ids(void* negentropy, buffer* query,reconcile_cbk cbk){ need_ids = (buffer*)malloc(need_ids_len*sizeof(buffer)); std::cout << "have_ids_len:" << have_ids_len << "need_ids_len:" << need_ids_len << std::endl; - std::flush(std::cout); transform(haveIds, have_ids); transform(needIds, need_ids); - std::cout << "for debug" << std::endl; } catch(negentropy::err e){ std::cout << "caught error "<< e.what() << std::endl; //TODO:Find a way to return this error and cleanup partially allocated memory if any return -1; } - buffer output; + buffer output = {0,NULL}; if (out) { output.len = out.value().size(); output.data = (unsigned char*)out.value().c_str(); std::cout << "reconcile_with_ids output of reconcile is, len:" << out.value().size() << ", output:"; printHexString(std::string_view(out.value())); - std::cout << "invoking callback" << std::endl; } - cbk(have_ids, have_ids_len, need_ids, need_ids_len, &output); + std::cout << "invoking callback" << std::endl; + std::flush(std::cout); + + cbk(have_ids, have_ids_len, need_ids, need_ids_len, &output, outptr); + std::cout << "invoked callback" << std::endl; + std::flush(std::cout); + free(have_ids); free(need_ids); return 0; diff --git a/cpp/negentropy_wrapper.h b/cpp/negentropy_wrapper.h index 21e897a..f3d0eac 100644 --- a/cpp/negentropy_wrapper.h +++ b/cpp/negentropy_wrapper.h @@ -30,9 +30,9 @@ EXTERNC bool storage_erase(void* storage, uint64_t createdAt, buffer* id); EXTERNC size_t reconcile(void* negentropy, buffer* query, buffer* output); -EXTERNC typedef void (*reconcile_cbk)(buffer* have_ids, uint64_t have_ids_len, buffer* need_ids, uint64_t need_ids_len, buffer* output); +EXTERNC typedef void (*reconcile_cbk)(buffer* have_ids, uint64_t have_ids_len, buffer* need_ids, uint64_t need_ids_len, buffer* output, char* outptr ); -EXTERNC int reconcile_with_ids(void* negentropy, buffer* query, reconcile_cbk cbk); +EXTERNC int reconcile_with_ids(void* negentropy, buffer* query, reconcile_cbk cbk, char* outptr); #endif