Merge pull request #1165 from slsdetectorgroup/910/multirxr_proper_cleanup_on_ctrlc

910: multirxr dirty destruct leaving arping thread hanging + versioning (multi and framesync)
This commit is contained in:
maliakal_d 2025-03-25 16:54:19 +01:00 committed by GitHub
commit f29ef9e345
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 65 additions and 28 deletions

View File

@ -110,6 +110,14 @@ This document describes the differences between v9.1.0 and v9.0.0
* Removed potentially unsafe str().c_str() calls. * Removed potentially unsafe str().c_str() calls.
* slsMultiReceiver Ctrl + C
Now cleans up properly upon Ctrl + C, including exiting the Arping thread.
* slsMultiReceiver version
--version or -v now gives the version of slsMultiReceiver.
ZMQ ZMQ
--- ---

View File

@ -10,6 +10,7 @@
#include "sls/container_utils.h" #include "sls/container_utils.h"
#include "sls/logger.h" #include "sls/logger.h"
#include "sls/sls_detector_defs.h" #include "sls/sls_detector_defs.h"
#include "sls/versionAPI.h"
#include <csignal> //SIGINT #include <csignal> //SIGINT
#include <cstdio> #include <cstdio>
@ -92,7 +93,9 @@ void cleanup() {
std::string getHelpMessage() { std::string getHelpMessage() {
std::ostringstream os; std::ostringstream os;
os << "\nUsage:\n" os << "\nUsage:\n"
"./slsFrameSynchronizer [start tcp port] [num recevers] [print " << "./slsFrameSynchronizer --version or -v\n"
<< "\t - Gets the slsFrameSynchronizer version\n\n"
<< "./slsFrameSynchronizer [start tcp port] [num recevers] [print "
"callback headers (optional)]\n" "callback headers (optional)]\n"
<< "\t - tcp port has to be non-zero and 16 bit\n" << "\t - tcp port has to be non-zero and 16 bit\n"
<< "\t - print callback headers option is 0 (disabled) by default\n"; << "\t - print callback headers option is 0 (disabled) by default\n";
@ -506,6 +509,16 @@ void GetDataCallback(slsDetectorDefs::sls_receiver_header &header,
*/ */
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
// version
if (argc == 2) {
std::string sargv1 = std::string(argv[1]);
if (sargv1 == "--version" || sargv1 == "-v") {
std::cout << "slsFrameSynchronizer Version: " << APIRECEIVER
<< std::endl;
exit(EXIT_SUCCESS);
}
}
/** - set default values */ /** - set default values */
int numReceivers = 1; int numReceivers = 1;
uint16_t startTCPPort = DEFAULT_TCP_RX_PORTNO; uint16_t startTCPPort = DEFAULT_TCP_RX_PORTNO;

View File

@ -7,6 +7,7 @@
#include "sls/container_utils.h" #include "sls/container_utils.h"
#include "sls/logger.h" #include "sls/logger.h"
#include "sls/sls_detector_defs.h" #include "sls/sls_detector_defs.h"
#include "sls/versionAPI.h"
#include <csignal> //SIGINT #include <csignal> //SIGINT
#include <cstring> #include <cstring>
@ -39,7 +40,9 @@ void sigInterruptHandler(int p) { sem_post(&semaphore); }
*/ */
std::string getHelpMessage() { std::string getHelpMessage() {
std::ostringstream os; std::ostringstream os;
os << "\nUsage:\n" os << "\nUsage:\n\n"
<< "./slsMultiReceiver --version or -v\n"
<< "\t - Gets the slsMultiReceiver version\n\n"
<< "./slsMultiReceiver [start tcp port] [num recevers] [call back " << "./slsMultiReceiver [start tcp port] [num recevers] [call back "
"option (optional)]\n" "option (optional)]\n"
<< "\t - tcp port has to be non-zero and 16 bit\n" << "\t - tcp port has to be non-zero and 16 bit\n"
@ -160,6 +163,16 @@ void GetData(slsDetectorDefs::sls_receiver_header &header,
*/ */
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
// version
if (argc == 2) {
std::string sargv1 = std::string(argv[1]);
if (sargv1 == "--version" || sargv1 == "-v") {
std::cout << "slsMultiReceiver Version: " << APIRECEIVER
<< std::endl;
exit(EXIT_SUCCESS);
}
}
/** - set default values */ /** - set default values */
int numReceivers = 1; int numReceivers = 1;
uint16_t startTCPPort = DEFAULT_TCP_RX_PORTNO; uint16_t startTCPPort = DEFAULT_TCP_RX_PORTNO;
@ -242,40 +255,43 @@ int main(int argc, char *argv[]) {
else if (pid == 0) { else if (pid == 0) {
cprintf(BLUE, "Child process %d [ Tid: %ld ]\n", i, (long)gettid()); cprintf(BLUE, "Child process %d [ Tid: %ld ]\n", i, (long)gettid());
std::unique_ptr<sls::Receiver> receiver = nullptr;
try { try {
receiver = sls::make_unique<sls::Receiver>(startTCPPort + i); uint16_t port = startTCPPort + i;
} catch (...) { sls::Receiver receiver(port);
LOG(sls::logINFOBLUE)
<< "Exiting Child Process [ Tid: " << gettid() << " ]"; /** - register callbacks. remember to set file write enable
throw; * to 0 (using the client) if we should not write files and you
} * will write data using the callbacks */
/** - 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 */
if (withCallback) { if (withCallback) {
/** - Call back for start acquisition */ /** - Call back for start acquisition */
cprintf(BLUE, "Registering StartAcq()\n"); cprintf(BLUE, "Registering StartAcq()\n");
receiver->registerCallBackStartAcquisition(StartAcq, nullptr); receiver.registerCallBackStartAcquisition(StartAcq,
nullptr);
/** - Call back for acquisition finished */ /** - Call back for acquisition finished */
cprintf(BLUE, "Registering AcquisitionFinished()\n"); cprintf(BLUE, "Registering AcquisitionFinished()\n");
receiver->registerCallBackAcquisitionFinished( receiver.registerCallBackAcquisitionFinished(
AcquisitionFinished, nullptr); AcquisitionFinished, nullptr);
/* - Call back for raw data */ /* - Call back for raw data */
cprintf(BLUE, "Registering GetData() \n"); cprintf(BLUE, "Registering GetData() \n");
receiver->registerCallBackRawDataReady(GetData, nullptr); receiver.registerCallBackRawDataReady(GetData, nullptr);
} }
/** - as long as no Ctrl+C */ /** - as long as no Ctrl+C */
sem_wait(&semaphore); sem_wait(&semaphore);
sem_destroy(&semaphore); sem_destroy(&semaphore);
} catch (...) {
LOG(sls::logINFOBLUE)
<< "Exiting Child Process [ Tid: " << gettid() << " ]";
throw;
}
cprintf(BLUE, "Exiting Child Process [ Tid: %ld ]\n", cprintf(BLUE, "Exiting Child Process [ Tid: %ld ]\n",
(long)gettid()); (long)gettid());
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
break;
} }
} }

View File

@ -62,7 +62,7 @@ Receiver::Receiver(int argc, char *argv[]) : tcpipInterface(nullptr) {
"\t started with privileges. \n\n"; "\t started with privileges. \n\n";
while (c != -1) { while (c != -1) {
c = getopt_long(argc, argv, "hvf:t:u:", long_options, &option_index); c = getopt_long(argc, argv, "hvt:u:", long_options, &option_index);
// Detect the end of the options. // Detect the end of the options.
if (c == -1) if (c == -1)
@ -87,7 +87,7 @@ Receiver::Receiver(int argc, char *argv[]) : tcpipInterface(nullptr) {
break; break;
case 'v': case 'v':
std::cout << "SLS Receiver Version: " << APIRECEIVER << std::endl; std::cout << "slsReceiver Version: " << APIRECEIVER << std::endl;
LOG(logINFOBLUE) << "Exiting [ Tid: " << gettid() << " ]"; LOG(logINFOBLUE) << "Exiting [ Tid: " << gettid() << " ]";
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);