From 68b1f1a404e23172beb069afc6bcfc7812830c86 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Thu, 12 Sep 2024 15:16:17 +0200 Subject: [PATCH] removed modified callback and instead passing by reference instead of value to the oriignal receiver data callback --- slsReceiverSoftware/include/sls/Receiver.h | 20 +------ slsReceiverSoftware/src/ClientInterface.cpp | 13 +---- slsReceiverSoftware/src/ClientInterface.h | 13 +---- slsReceiverSoftware/src/DataProcessor.cpp | 26 ++------- slsReceiverSoftware/src/DataProcessor.h | 23 +------- slsReceiverSoftware/src/Implementation.cpp | 18 +----- slsReceiverSoftware/src/Implementation.h | 13 +---- slsReceiverSoftware/src/MultiReceiverApp.cpp | 58 ++++++-------------- slsReceiverSoftware/src/Receiver.cpp | 9 +-- 9 files changed, 32 insertions(+), 161 deletions(-) diff --git a/slsReceiverSoftware/include/sls/Receiver.h b/slsReceiverSoftware/include/sls/Receiver.h index b11015baff..f3389c80ec 100644 --- a/slsReceiverSoftware/include/sls/Receiver.h +++ b/slsReceiverSoftware/include/sls/Receiver.h @@ -63,28 +63,14 @@ class Receiver : private virtual slsDetectorDefs { * - sls_receiver_header frame metadata, * - dataCallbackHeader metadata * - pointer to data - * - image size in bytes + * - image size in bytes. Can be modified to the new size to be + * written/streamed. (only smaller value allowed). */ void registerCallBackRawDataReady(void (*func)(sls_receiver_header &, const dataCallbackHeader, - char *, size_t, void *), + char *, size_t &, void *), void *arg); - /** - * Call back for raw data (modified) - * args to raw data ready callback are: - * - sls_receiver_header frame metadata, - * - dataCallbackHeader metadata - * - pointer to data - * - revDatasize is the reference of data size in bytes. - * Can be modified to the new size to be written/streamed. (only smaller - * value allowed). - */ - void registerCallBackRawDataModifyReady( - void (*func)(sls_receiver_header &, const dataCallbackHeader, char *, - size_t &, void *), - void *arg); - private: std::unique_ptr tcpipInterface; }; diff --git a/slsReceiverSoftware/src/ClientInterface.cpp b/slsReceiverSoftware/src/ClientInterface.cpp index a9921d4204..ce87021516 100644 --- a/slsReceiverSoftware/src/ClientInterface.cpp +++ b/slsReceiverSoftware/src/ClientInterface.cpp @@ -66,18 +66,10 @@ void ClientInterface::registerCallBackAcquisitionFinished( } void ClientInterface::registerCallBackRawDataReady( - void (*func)(sls_receiver_header &, dataCallbackHeader, char *, size_t, - void *), - void *arg) { - rawDataReadyCallBack = func; - pRawDataReady = arg; -} - -void ClientInterface::registerCallBackRawDataModifyReady( void (*func)(sls_receiver_header &, dataCallbackHeader, char *, size_t &, void *), void *arg) { - rawDataModifyReadyCallBack = func; + rawDataReadyCallBack = func; pRawDataReady = arg; } @@ -478,9 +470,6 @@ void ClientInterface::setDetectorType(detectorType arg) { if (rawDataReadyCallBack != nullptr) impl()->registerCallBackRawDataReady(rawDataReadyCallBack, pRawDataReady); - if (rawDataModifyReadyCallBack != nullptr) - impl()->registerCallBackRawDataModifyReady(rawDataModifyReadyCallBack, - pRawDataReady); impl()->setThreadIds(parentThreadId, tcpThreadId); } diff --git a/slsReceiverSoftware/src/ClientInterface.h b/slsReceiverSoftware/src/ClientInterface.h index d53e377f8e..8bde90c641 100644 --- a/slsReceiverSoftware/src/ClientInterface.h +++ b/slsReceiverSoftware/src/ClientInterface.h @@ -45,15 +45,9 @@ class ClientInterface : private virtual slsDetectorDefs { /** params: sls_receiver_header, pointer to data, image size */ void registerCallBackRawDataReady(void (*func)(sls_receiver_header &, const dataCallbackHeader, - char *, size_t, void *), + char *, size_t &, void *), void *arg); - /** params: sls_receiver_header, pointer to data, reference to image size */ - void registerCallBackRawDataModifyReady( - void (*func)(sls_receiver_header &, const dataCallbackHeader, char *, - size_t &, void *), - void *arg); - private: void startTCPServer(); int functionTable(); @@ -193,10 +187,7 @@ class ClientInterface : private virtual slsDetectorDefs { void *) = nullptr; void *pAcquisitionFinished{nullptr}; void (*rawDataReadyCallBack)(sls_receiver_header &, dataCallbackHeader, - char *, size_t, void *) = nullptr; - void (*rawDataModifyReadyCallBack)(sls_receiver_header &, - dataCallbackHeader, char *, size_t &, - void *) = nullptr; + char *, size_t &, void *) = nullptr; void *pRawDataReady{nullptr}; pid_t parentThreadId{0}; diff --git a/slsReceiverSoftware/src/DataProcessor.cpp b/slsReceiverSoftware/src/DataProcessor.cpp index d2712459d4..e5702389d6 100644 --- a/slsReceiverSoftware/src/DataProcessor.cpp +++ b/slsReceiverSoftware/src/DataProcessor.cpp @@ -385,8 +385,7 @@ void DataProcessor::ProcessAnImage(sls_receiver_header &header, size_t &size, try { // callbacks - if (rawDataReadyCallBack != nullptr || - rawDataModifyReadyCallBack != nullptr) { + if (rawDataReadyCallBack != nullptr) { uint64_t frameIndex = fnum - firstIndex; // update local copy only if it was updated (to prevent locking each @@ -408,17 +407,8 @@ void DataProcessor::ProcessAnImage(sls_receiver_header &header, size_t &size, flipRows, localAdditionalJsonHeader}; - // normal call back - if (rawDataReadyCallBack != nullptr) { - rawDataReadyCallBack(header, callbackHeader, data, size, - pRawDataReady); - } - - // call back with modified size - else if (rawDataModifyReadyCallBack != nullptr) { - rawDataModifyReadyCallBack(header, callbackHeader, data, size, - pRawDataReady); - } + rawDataReadyCallBack(header, callbackHeader, data, size, + pRawDataReady); } } catch (const std::exception &e) { throw RuntimeError("Get Data Callback Error: " + std::string(e.what())); @@ -477,18 +467,10 @@ bool DataProcessor::CheckCount() { } void DataProcessor::registerCallBackRawDataReady( - void (*func)(sls_receiver_header &, dataCallbackHeader, char *, size_t, - void *), - void *arg) { - rawDataReadyCallBack = func; - pRawDataReady = arg; -} - -void DataProcessor::registerCallBackRawDataModifyReady( void (*func)(sls_receiver_header &, dataCallbackHeader, char *, size_t &, void *), void *arg) { - rawDataModifyReadyCallBack = func; + rawDataReadyCallBack = func; pRawDataReady = arg; } diff --git a/slsReceiverSoftware/src/DataProcessor.h b/slsReceiverSoftware/src/DataProcessor.h index 3d00000a79..29ea9e84c9 100644 --- a/slsReceiverSoftware/src/DataProcessor.h +++ b/slsReceiverSoftware/src/DataProcessor.h @@ -88,16 +88,9 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject { /** params: sls_receiver_header, pointer to data, image size */ void registerCallBackRawDataReady(void (*func)(sls_receiver_header &, dataCallbackHeader, char *, - size_t, void *), + size_t &, void *), void *arg); - /** params: sls_receiver_header, pointer to data, reference to image size */ - void registerCallBackRawDataModifyReady(void (*func)(sls_receiver_header &, - dataCallbackHeader, - char *, size_t &, - void *), - void *arg); - private: void RecordFirstIndex(uint64_t fnum); @@ -210,19 +203,7 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject { * dataSize in bytes is the size of the data in bytes. */ void (*rawDataReadyCallBack)(sls_receiver_header &, dataCallbackHeader, - char *, size_t, void *) = nullptr; - - /** - * Call back for raw data (modified) - * args to raw data ready callback are - * sls_receiver_header frame metadata - * dataPointer is the pointer to the data - * revDatasize is the reference of data size in bytes. Can be modified to - * the new size to be written/streamed. (only smaller value). - */ - void (*rawDataModifyReadyCallBack)(sls_receiver_header &, - dataCallbackHeader, char *, size_t &, - void *) = nullptr; + char *, size_t &, void *) = nullptr; void *pRawDataReady{nullptr}; }; diff --git a/slsReceiverSoftware/src/Implementation.cpp b/slsReceiverSoftware/src/Implementation.cpp index 8e242af324..3d5940127f 100644 --- a/slsReceiverSoftware/src/Implementation.cpp +++ b/slsReceiverSoftware/src/Implementation.cpp @@ -1128,11 +1128,6 @@ void Implementation::setNumberofUDPInterfaces(const int n) { it->registerCallBackRawDataReady(rawDataReadyCallBack, pRawDataReady); } - if (rawDataModifyReadyCallBack) { - for (const auto &it : dataProcessor) - it->registerCallBackRawDataModifyReady( - rawDataModifyReadyCallBack, pRawDataReady); - } // test socket buffer size with current set up setUDPSocketBufferSize(0); @@ -1813,7 +1808,7 @@ void Implementation::registerCallBackAcquisitionFinished( } void Implementation::registerCallBackRawDataReady( - void (*func)(sls_receiver_header &, dataCallbackHeader, char *, size_t, + void (*func)(sls_receiver_header &, dataCallbackHeader, char *, size_t &, void *), void *arg) { rawDataReadyCallBack = func; @@ -1822,15 +1817,4 @@ void Implementation::registerCallBackRawDataReady( it->registerCallBackRawDataReady(rawDataReadyCallBack, pRawDataReady); } -void Implementation::registerCallBackRawDataModifyReady( - void (*func)(sls_receiver_header &, dataCallbackHeader, char *, size_t &, - void *), - void *arg) { - rawDataModifyReadyCallBack = func; - pRawDataReady = arg; - for (const auto &it : dataProcessor) - it->registerCallBackRawDataModifyReady(rawDataModifyReadyCallBack, - pRawDataReady); -} - } // namespace sls diff --git a/slsReceiverSoftware/src/Implementation.h b/slsReceiverSoftware/src/Implementation.h index 0391b95751..671f6deb2a 100644 --- a/slsReceiverSoftware/src/Implementation.h +++ b/slsReceiverSoftware/src/Implementation.h @@ -274,14 +274,8 @@ class Implementation : private virtual slsDetectorDefs { /** params: sls_receiver_header, pointer to data, image size */ void registerCallBackRawDataReady(void (*func)(sls_receiver_header &, dataCallbackHeader, char *, - size_t, void *), + size_t &, void *), void *arg); - /** params: sls_receiver_header, pointer to data, reference to image size */ - void registerCallBackRawDataModifyReady(void (*func)(sls_receiver_header &, - dataCallbackHeader, - char *, size_t &, - void *), - void *arg); private: void SetLocalNetworkParameters(); @@ -386,10 +380,7 @@ class Implementation : private virtual slsDetectorDefs { void *){nullptr}; void *pAcquisitionFinished{nullptr}; void (*rawDataReadyCallBack)(sls_receiver_header &, dataCallbackHeader, - char *, size_t, void *){nullptr}; - void (*rawDataModifyReadyCallBack)(sls_receiver_header &, - dataCallbackHeader, char *, size_t &, - void *){nullptr}; + char *, size_t &, void *){nullptr}; void *pRawDataReady{nullptr}; // class objects diff --git a/slsReceiverSoftware/src/MultiReceiverApp.cpp b/slsReceiverSoftware/src/MultiReceiverApp.cpp index 812cadb0f4..125c49b36d 100644 --- a/slsReceiverSoftware/src/MultiReceiverApp.cpp +++ b/slsReceiverSoftware/src/MultiReceiverApp.cpp @@ -84,10 +84,15 @@ void AcquisitionFinished( << "\n\t]"; } -void printDataCallBackHeader(slsDetectorDefs::sls_receiver_header &header, - slsDetectorDefs::dataCallbackHeader callbackHeader, - char *dataPointer, size_t imageSize, - void *objectPointer) { +/** + * Get Receiver Data Call back + * Prints in different colors(for each receiver process) the different headers + * for each image call back. + */ +void GetData(slsDetectorDefs::sls_receiver_header &header, + slsDetectorDefs::dataCallbackHeader callbackHeader, + char *dataPointer, size_t &imageSize, void *objectPointer) { + slsDetectorDefs::sls_detector_header detectorHeader = header.detHeader; PRINT_IN_COLOR( @@ -136,36 +141,9 @@ void printDataCallBackHeader(slsDetectorDefs::sls_receiver_header &header, detectorHeader.version, // header->packetsMask.to_string().c_str(), ((uint8_t)(*((uint8_t *)(dataPointer)))), imageSize); -} - -/** - * Get Receiver Data Call back - * Prints in different colors(for each receiver process) the different headers - * for each image call back. - */ -void GetData(slsDetectorDefs::sls_receiver_header &header, - slsDetectorDefs::dataCallbackHeader callbackHeader, - char *dataPointer, size_t imageSize, void *objectPointer) { - printDataCallBackHeader(header, callbackHeader, dataPointer, imageSize, - objectPointer); -} - -/** - * Get Receiver Data Call back (modified) - * Prints in different colors(for each receiver process) the different headers - * for each image call back. - * @param modifiedImageSize new data size in bytes after the callback. - * This will be the size written/streamed. (only smaller value is allowed). - */ -void GetData(slsDetectorDefs::sls_receiver_header &header, - slsDetectorDefs::dataCallbackHeader callbackHeader, - char *dataPointer, size_t &modifiedImageSize, - void *objectPointer) { - printDataCallBackHeader(header, callbackHeader, dataPointer, - modifiedImageSize, objectPointer); // if data is modified, eg ROI and size is reduced - modifiedImageSize = 26000; + imageSize = 26000; } /** @@ -254,26 +232,22 @@ int main(int argc, char *argv[]) { throw; } /** - register callbacks. remember to set file write enable to 0 - (using the client) if we should not write files and you will write data - using the callbacks */ + * (using the client) if we should not write files and you will + * write data using the callbacks */ if (withCallback) { /** - Call back for start acquisition */ - cprintf(BLUE, "Registering StartAcq()\n"); + cprintf(BLUE, "Registering StartAcq()\n"); receiver->registerCallBackStartAcquisition(StartAcq, nullptr); /** - Call back for acquisition finished */ - cprintf(BLUE, "Registering AcquisitionFinished()\n"); + cprintf(BLUE, "Registering AcquisitionFinished()\n"); receiver->registerCallBackAcquisitionFinished( AcquisitionFinished, nullptr); /* - Call back for raw data */ - cprintf(BLUE, "Registering GetData() \n"); - if (withCallback == 1) - receiver->registerCallBackRawDataReady(GetData, nullptr); - else if (withCallback == 2) - receiver->registerCallBackRawDataModifyReady(GetData, - nullptr); + cprintf(BLUE, "Registering GetData() \n"); + receiver->registerCallBackRawDataReady(GetData, nullptr); } /** - as long as no Ctrl+C */ diff --git a/slsReceiverSoftware/src/Receiver.cpp b/slsReceiverSoftware/src/Receiver.cpp index ce91e97e71..d7c6763667 100644 --- a/slsReceiverSoftware/src/Receiver.cpp +++ b/slsReceiverSoftware/src/Receiver.cpp @@ -144,17 +144,10 @@ void Receiver::registerCallBackAcquisitionFinished( } void Receiver::registerCallBackRawDataReady( - void (*func)(sls_receiver_header &, const dataCallbackHeader, char *, - size_t, void *), - void *arg) { - tcpipInterface->registerCallBackRawDataReady(func, arg); -} - -void Receiver::registerCallBackRawDataModifyReady( void (*func)(sls_receiver_header &, const dataCallbackHeader, char *, size_t &, void *), void *arg) { - tcpipInterface->registerCallBackRawDataModifyReady(func, arg); + tcpipInterface->registerCallBackRawDataReady(func, arg); } } // namespace sls \ No newline at end of file