From 1bd0b33806d2341913277f68f4a01be72f332e46 Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Fri, 11 Jan 2019 11:27:48 +0100 Subject: [PATCH 1/3] functions not overriding base and unitialized use --- slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp | 4 ++-- slsReceiverSoftware/include/BinaryFile.h | 2 +- slsReceiverSoftware/src/BinaryFile.cpp | 4 ++-- slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp index 1f2451146..14baf8860 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp @@ -2606,7 +2606,7 @@ std::string slsDetectorCommand::helpThreaded(int action) { std::string slsDetectorCommand::cmdImage(int narg, char *args[], int action, int detPos) { std::string sval; - int retval; + int retval = FAIL; if (action == HELP_ACTION) return helpImage(HELP_ACTION); else if (action == GET_ACTION) @@ -2643,7 +2643,7 @@ std::string slsDetectorCommand::cmdCounter(int narg, char *args[], int action, i int ival; char answer[100]; std::string sval; - int retval; + int retval = FAIL; if (action == HELP_ACTION) return helpCounter(HELP_ACTION); else if (action == PUT_ACTION) diff --git a/slsReceiverSoftware/include/BinaryFile.h b/slsReceiverSoftware/include/BinaryFile.h index 98f7d2a22..8d9324df7 100644 --- a/slsReceiverSoftware/include/BinaryFile.h +++ b/slsReceiverSoftware/include/BinaryFile.h @@ -47,7 +47,7 @@ class BinaryFile : private virtual slsDetectorDefs, public File, public BinaryFi /** * Print all member values */ - void PrintMembers(); + void PrintMembers(TLogLevel level = logDEBUG1); /** * Create file diff --git a/slsReceiverSoftware/src/BinaryFile.cpp b/slsReceiverSoftware/src/BinaryFile.cpp index 47af53f20..d64c6745a 100644 --- a/slsReceiverSoftware/src/BinaryFile.cpp +++ b/slsReceiverSoftware/src/BinaryFile.cpp @@ -31,8 +31,8 @@ BinaryFile::~BinaryFile() { CloseAllFiles(); } -void BinaryFile::PrintMembers() { - File::PrintMembers(); +void BinaryFile::PrintMembers(TLogLevel level) { + File::PrintMembers(level); FILE_LOG(logINFO) << "Max Frames Per File: " << *maxFramesPerFile; FILE_LOG(logINFO) << "Number of Frames in File: " << numFramesInFile; } diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index 34ec324b1..abd9573cf 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -705,8 +705,8 @@ int slsReceiverTCPIPInterface::set_roi() { int slsReceiverTCPIPInterface::setup_udp(){ ret = OK; memset(mess, 0, sizeof(mess)); - char args[3][MAX_STR_LENGTH] = {0}; - char retvals[MAX_STR_LENGTH] = {0}; + char args[3][MAX_STR_LENGTH] = {{""}, {""}, {""}}; + char retvals[MAX_STR_LENGTH] = {""}; // get args, return if socket crashed, ret is fail if receiver is not null if (interface->Server_ReceiveArg(ret, mess, args, sizeof(args), true, receiver) == FAIL) From b46fb5e9c4ba1e987d8186f2087172092230a8d0 Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Fri, 11 Jan 2019 12:33:11 +0100 Subject: [PATCH 2/3] deduce parallel call only on function signature and some const& --- .../multiSlsDetector/multiSlsDetector.cpp | 6 ++- .../multiSlsDetector/multiSlsDetector.h | 6 ++- .../slsDetector/slsDetector.cpp | 42 +++++++++---------- slsDetectorSoftware/slsDetector/slsDetector.h | 28 ++++++------- 4 files changed, 43 insertions(+), 39 deletions(-) diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index 20f2d1afd..a865a7ed0 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -45,9 +45,11 @@ void multiSlsDetector::setupMultiDetector(bool verify, bool update) { updateUserdetails(); } + + template std::vector multiSlsDetector::serialCall(RT (slsDetector::*somefunc)(CT...), - CT... Args) { + typename NonDeduced::type... Args) { std::vector result; result.reserve(detectors.size()); for (auto &d : detectors) @@ -57,7 +59,7 @@ std::vector multiSlsDetector::serialCall(RT (slsDetector::*somefunc)(CT...), template std::vector -multiSlsDetector::parallelCall(RT (slsDetector::*somefunc)(CT...), CT... Args) { +multiSlsDetector::parallelCall(RT (slsDetector::*somefunc)(CT...), typename NonDeduced::type... Args) { std::vector> futures; for (auto &d : detectors) futures.push_back( diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h index 022bbfc9d..23ff2acb1 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h @@ -141,8 +141,10 @@ class multiSlsDetector : public virtual slsDetectorDefs, * Loop through the detectors serially * and return a vector of results */ + template + struct NonDeduced { using type = CT; }; template - std::vector serialCall(RT (slsDetector::*somefunc)(CT...), CT... Args); + std::vector serialCall(RT (slsDetector::*somefunc)(CT...), typename NonDeduced::type... Args); /** * Loop through the detectors in parallel threads @@ -150,7 +152,7 @@ class multiSlsDetector : public virtual slsDetectorDefs, */ template std::vector parallelCall(RT (slsDetector::*somefunc)(CT...), - CT... Args); + typename NonDeduced::type... Args); /** * If specific position, then provide result with that detector at position diff --git a/slsDetectorSoftware/slsDetector/slsDetector.cpp b/slsDetectorSoftware/slsDetector/slsDetector.cpp index 136c72142..1618ac7ab 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetector.cpp @@ -1511,7 +1511,7 @@ std::string slsDetector::getSettingsFile() { } -int slsDetector::writeSettingsFile(std::string fname) { +int slsDetector::writeSettingsFile(const std::string& fname) { return writeSettingsFile(fname, detectorModules[0]); } @@ -3066,7 +3066,7 @@ std::string slsDetector::setClientStreamingPort(std::string port) { } -std::string slsDetector::setReceiverStreamingPort(std::string port) { +std::string slsDetector::setReceiverStreamingPort(const std::string& port) { // copy now else it is lost if rx_hostname not set yet thisDetector->receiver_zmqport = stoi(port); @@ -3094,7 +3094,7 @@ std::string slsDetector::setReceiverStreamingPort(std::string port) { } -std::string slsDetector::setClientStreamingIP(std::string sourceIP) { +std::string slsDetector::setClientStreamingIP(const std::string& sourceIP) { struct addrinfo *result; // on failure to convert to a valid ip if (dataSocket->ConvertHostnameToInternetAddress(sourceIP.c_str(), &result)) { @@ -3167,7 +3167,7 @@ std::string slsDetector::setReceiverStreamingIP(std::string sourceIP) { } -std::string slsDetector::setAdditionalJsonHeader(std::string jsonheader) { +std::string slsDetector::setAdditionalJsonHeader(const std::string& jsonheader) { int fnum = F_ADDITIONAL_JSON_HEADER; int ret = FAIL; char args[MAX_STR_LENGTH] = {0}; @@ -3331,7 +3331,7 @@ int slsDetector::digitalTest( digitalTestMode mode, int ival) { } -int slsDetector::loadImageToDetector(imageType index,std::string const fname) { +int slsDetector::loadImageToDetector(imageType index, const std::string& fname) { int ret = FAIL; int nChan = getTotalNumberOfChannels(); short int args[nChan]; @@ -3374,7 +3374,7 @@ int slsDetector::sendImageToDetector(imageType index,short int imageVals[]) { } -int slsDetector::writeCounterBlockFile(std::string const fname,int startACQ) { +int slsDetector::writeCounterBlockFile(const std::string& fname,int startACQ) { int ret = FAIL; int nChan = getTotalNumberOfChannels(); short int retvals[nChan]; @@ -3961,7 +3961,7 @@ int slsDetector::setStoragecellStart(int pos) { } -int slsDetector::programFPGA(std::string fname) { +int slsDetector::programFPGA(const std::string& fname) { // only jungfrau implemented (client processing, so check now) if (thisDetector->myDetectorType != JUNGFRAU && thisDetector->myDetectorType != CHIPTESTBOARD) { FILE_LOG(logERROR) << "Not implemented for this detector"; @@ -4524,7 +4524,7 @@ std::string slsDetector::checkReceiverOnline() { } -int slsDetector::setReceiverTCPSocket(std::string const name, int const receiver_port) { +int slsDetector::setReceiverTCPSocket(const std::string& name, int const receiver_port) { char thisName[MAX_STR_LENGTH] = {0}; int thisRP = 0; int ret = OK; @@ -4652,7 +4652,7 @@ int slsDetector::exitReceiver() { } -int slsDetector::execReceiverCommand(std::string cmd) { +int slsDetector::execReceiverCommand(const std::string& cmd) { int fnum = F_EXEC_RECEIVER_COMMAND; int ret = FAIL; char arg[MAX_STR_LENGTH] = {0}; @@ -4859,13 +4859,13 @@ std::string slsDetector::getFilePath() { } -std::string slsDetector::setFilePath(std::string s) { - if (!s.empty()) { +std::string slsDetector::setFilePath(const std::string& path) { + if (!path.empty()) { int fnum = F_SET_RECEIVER_FILE_PATH; int ret = FAIL; char args[MAX_STR_LENGTH] = {0}; char retvals[MAX_STR_LENGTH] = {0}; - strcpy(args, s.c_str()); + strcpy(args, path.c_str()); FILE_LOG(logDEBUG1) << "Sending file path to receiver: " << args; if (thisDetector->receiverOnlineFlag == ONLINE_FLAG && connectData() == OK) { @@ -4874,7 +4874,7 @@ std::string slsDetector::setFilePath(std::string s) { // handle ret if (ret == FAIL) { - if (!s.empty()) { + if (!path.empty()) { FILE_LOG(logERROR) << "file path does not exist"; setErrorMask((getErrorMask())|(FILE_PATH_DOES_NOT_EXIST)); } else @@ -4896,13 +4896,13 @@ std::string slsDetector::getFileName() { } -std::string slsDetector::setFileName(std::string s) { - if (!s.empty()) { +std::string slsDetector::setFileName(const std::string& fname) { + if (!fname.empty()) { int fnum = F_SET_RECEIVER_FILE_NAME; int ret = FAIL; - char args[MAX_STR_LENGTH] = {0}; - char retvals[MAX_STR_LENGTH] = {0}; - strcpy(args, s.c_str()); + char args[MAX_STR_LENGTH] = {""}; + char retvals[MAX_STR_LENGTH] = {""}; + strcpy(args, fname.c_str()); FILE_LOG(logDEBUG1) << "Sending file name to receiver: " << args; if (thisDetector->receiverOnlineFlag == ONLINE_FLAG && connectData() == OK) { @@ -5462,7 +5462,7 @@ int slsDetector::restreamStopFromReceiver() { -int slsDetector::setCTBPattern(std::string fname) { +int slsDetector::setCTBPattern(const std::string& fname) { uint64_t word; int addr = 0; FILE *fd = fopen(fname.c_str(),"r"); @@ -5644,7 +5644,7 @@ slsDetectorDefs::sls_detector_module* slsDetector::interpolateTrim( } -slsDetectorDefs::sls_detector_module* slsDetector::readSettingsFile(std::string fname, +slsDetectorDefs::sls_detector_module* slsDetector::readSettingsFile(const std::string& fname, sls_detector_module* myMod, int tb) { FILE_LOG(logDEBUG1) << "Read settings file " << fname; @@ -5789,7 +5789,7 @@ slsDetectorDefs::sls_detector_module* slsDetector::readSettingsFile(std::string } -int slsDetector::writeSettingsFile(std::string fname, sls_detector_module mod) { +int slsDetector::writeSettingsFile(const std::string& fname, sls_detector_module mod) { FILE_LOG(logDEBUG1) << "Write settings file " << fname; diff --git a/slsDetectorSoftware/slsDetector/slsDetector.h b/slsDetectorSoftware/slsDetector/slsDetector.h index 19c7a35cc..d1f05a45e 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.h +++ b/slsDetectorSoftware/slsDetector/slsDetector.h @@ -608,7 +608,7 @@ public: * @returns OK or FAIL if the file could not be written * \sa ::sls_detector_module sharedSlsDetector mythenDetector::writeSettingsFile(string, int) */ - int writeSettingsFile(std::string fname); + int writeSettingsFile(const std::string& fname); /** * Get detector settings @@ -1004,14 +1004,14 @@ public: * calculate individual ports) * @returns the receiver zmq port */ - std::string setReceiverStreamingPort(std::string port); + std::string setReceiverStreamingPort(const std::string& port); /** * Sets the client zmq ip\sa sharedSlsDetector * @param sourceIP client zmq ip * @returns the client zmq ip, returns "none" if default setting and no custom ip set */ - std::string setClientStreamingIP(std::string sourceIP); + std::string setClientStreamingIP(const std::string& sourceIP); /** * Sets the receiver zmq ip\sa sharedSlsDetector @@ -1034,7 +1034,7 @@ public: * @param fname file name from which to load image * @returns OK or FAIL */ - int loadImageToDetector(imageType index,std::string const fname); + int loadImageToDetector(imageType index, const std::string& fname); /** * Called from loadImageToDetector to send the image to detector @@ -1050,7 +1050,7 @@ public: * @param startACQ is 1 to start acquisition after reading counter * @returns OK or FAIL */ - int writeCounterBlockFile(std::string const fname,int startACQ=0); + int writeCounterBlockFile(const std::string& fname,int startACQ=0); /** * Gets counter memory block in detector (Gotthard) @@ -1233,7 +1233,7 @@ public: * @param fname file name * @returns OK or FAIL */ - int programFPGA(std::string fname); + int programFPGA(const std::string& fname); /** * Resets FPGA (Jungfrau) @@ -1323,7 +1323,7 @@ public: * @returns OK is connection succeded, FAIL otherwise * \sa sharedSlsDetector */ - int setReceiverTCPSocket(std::string const name="", int const receiver_port=-1); + int setReceiverTCPSocket(const std::string& name="", int const receiver_port=-1); /** * Locks/Unlocks the connection to the receiver @@ -1350,7 +1350,7 @@ public: * @param cmd command to be executed * @returns OK or FAIL */ - int execReceiverCommand(std::string cmd); + int execReceiverCommand(const std::string& cmd); /** updates the shared memory receiving the data from the detector (without asking and closing the connection @@ -1394,7 +1394,7 @@ public: * @param s file directory * @returns file dir */ - std::string setFilePath(std::string s); + std::string setFilePath(const std::string& path); /** * Returns file name prefix @@ -1407,7 +1407,7 @@ public: * @param s file name prefix * @returns file name prefix */ - std::string setFileName(std::string s); + std::string setFileName(const std::string& fname); /** * Sets the max frames per file in receiver @@ -1574,7 +1574,7 @@ public: * @param fname pattern file to open * @returns OK/FAIL */ - int setCTBPattern(std::string fname); + int setCTBPattern(const std::string& fname); /** * Writes a pattern word to the CTB @@ -1723,7 +1723,7 @@ private: * @param jsonheader additional json header * @returns additional json header, returns "none" if default setting and no custom ip set */ - std::string setAdditionalJsonHeader(std::string jsonheader); + std::string setAdditionalJsonHeader(const std::string& jsonheader); /** * Sets the receiver UDP socket buffer size @@ -1782,7 +1782,7 @@ private: * @returns the pointer to myMod or NULL if reading the file failed */ - sls_detector_module* readSettingsFile(std::string fname, sls_detector_module* myMod=nullptr, int tb=1); + sls_detector_module* readSettingsFile(const std::string& fname, sls_detector_module* myMod=nullptr, int tb=1); /** * writes a trim/settings file @@ -1790,7 +1790,7 @@ private: * @param mod module structure which has to be written to file * @returns OK or FAIL if the file could not be written */ - int writeSettingsFile(std::string fname, sls_detector_module mod); + int writeSettingsFile(const std::string& fname, sls_detector_module mod); /** slsDetector Id or position in the detectors list */ From 5ea5e8323658a67d2687a73a3bd4e39f7b301d63 Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Fri, 11 Jan 2019 14:38:56 +0100 Subject: [PATCH 3/3] removing local variable in slsDetector::setTCPSocket and adding some const string& --- .../slsDetector/slsDetector.cpp | 54 +++++++++---------- slsDetectorSoftware/slsDetector/slsDetector.h | 26 ++++----- 2 files changed, 38 insertions(+), 42 deletions(-) diff --git a/slsDetectorSoftware/slsDetector/slsDetector.cpp b/slsDetectorSoftware/slsDetector/slsDetector.cpp index 1618ac7ab..474066edf 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetector.cpp @@ -1003,18 +1003,14 @@ std::string slsDetector::checkOnline() { } -int slsDetector::setTCPSocket(std::string const name, int const control_port, int const stop_port) { - char thisName[MAX_STR_LENGTH] = {0}; +int slsDetector::setTCPSocket(const std::string& hostname, int control_port, int stop_port) { int thisCP = 0, thisSP = 0; int ret = OK; // hostname - if (name.empty()) { - strcpy(thisName,thisDetector->hostname); - } else { + if (!hostname.empty()) { FILE_LOG(logDEBUG1) << "Setting hostname"; - strcpy(thisName, name.c_str()); - strcpy(thisDetector->hostname, thisName); + sls::strcpy_safe(thisDetector->hostname, hostname.c_str()); if (controlSocket) { delete controlSocket; controlSocket = nullptr; @@ -1054,10 +1050,10 @@ int slsDetector::setTCPSocket(std::string const name, int const control_port, in // create control socket if (!controlSocket) { try { - controlSocket = new MySocketTCP(thisName, thisCP); - FILE_LOG(logDEBUG1) << "Control socket connected " << thisName << " " << thisCP; + controlSocket = new MySocketTCP(thisDetector->hostname, thisCP); + FILE_LOG(logDEBUG1) << "Control socket connected " << thisDetector->hostname << " " << thisCP; } catch(...) { - FILE_LOG(logERROR) << "Could not connect control socket " << thisName << " " << thisCP; + FILE_LOG(logERROR) << "Could not connect control socket " << thisDetector->hostname << " " << thisCP; controlSocket = nullptr; ret = FAIL; } @@ -1067,10 +1063,10 @@ int slsDetector::setTCPSocket(std::string const name, int const control_port, in // create stop socket if (!stopSocket) { try { - stopSocket = new MySocketTCP(thisName, thisSP); - FILE_LOG(logDEBUG1) << "Stop socket connected " << thisName << " " << thisSP; + stopSocket = new MySocketTCP(thisDetector->hostname, thisSP); + FILE_LOG(logDEBUG1) << "Stop socket connected " << thisDetector->hostname << " " << thisSP; } catch(...) { - FILE_LOG(logERROR) << "Could not connect Stop socket " << thisName << " " << thisSP; + FILE_LOG(logERROR) << "Could not connect Stop socket " << thisDetector->hostname << " " << thisSP; stopSocket = nullptr; ret = FAIL; } @@ -1312,12 +1308,12 @@ int slsDetector::exitServer() { } -int slsDetector::execCommand(std::string cmd) { +int slsDetector::execCommand(const std::string& cmd) { int fnum = F_EXEC_COMMAND; int ret = FAIL; char arg[MAX_STR_LENGTH] = {0}; char retval[MAX_STR_LENGTH] = {0}; - strcpy(arg, cmd.c_str()); + sls::strcpy_safe(arg, cmd.c_str()); FILE_LOG(logDEBUG1) << "Sending command to detector " << arg; if (thisDetector->onlineFlag == ONLINE_FLAG && connectControl() == OK) { @@ -1419,7 +1415,7 @@ int slsDetector::updateDetector() { } -int slsDetector::writeConfigurationFile(std::string const fname, multiSlsDetector* m) { +int slsDetector::writeConfigurationFile(const std::string& fname, multiSlsDetector* m) { int iline = 0; std::ofstream outfile; outfile.open(fname.c_str(),std::ios_base::out); @@ -1770,13 +1766,13 @@ std::string slsDetector::getSettingsDir() { } -std::string slsDetector::setSettingsDir(std::string s) { - sls::strcpy_safe(thisDetector->settingsDir, s.c_str()); +std::string slsDetector::setSettingsDir(const std::string& dir) { + sls::strcpy_safe(thisDetector->settingsDir, dir.c_str()); return thisDetector->settingsDir; } -int slsDetector::loadSettingsFile(std::string fname) { +int slsDetector::loadSettingsFile(const std::string& fname) { std::string fn = fname; std::ostringstream ostfn; ostfn << fname; @@ -1807,7 +1803,7 @@ int slsDetector::loadSettingsFile(std::string fname) { } -int slsDetector::saveSettingsFile(std::string fname) { +int slsDetector::saveSettingsFile(const std::string& fname) { std::string fn = fname; std::ostringstream ostfn; ostfn << fname; @@ -2666,7 +2662,7 @@ uint32_t slsDetector::clearBit(uint32_t addr, int n) { } -std::string slsDetector::setNetworkParameter(networkParameter index, std::string value) { +std::string slsDetector::setNetworkParameter(networkParameter index, const std::string& value) { switch (index) { case DETECTOR_MAC: return setDetectorMAC(value); @@ -2844,7 +2840,7 @@ std::string slsDetector::getReceiverRealUDPSocketBufferSize() { } -std::string slsDetector::setDetectorMAC(std::string detectorMAC) { +std::string slsDetector::setDetectorMAC(const std::string& detectorMAC) { // invalid format if ((detectorMAC.length() != 17) || @@ -2866,7 +2862,7 @@ std::string slsDetector::setDetectorMAC(std::string detectorMAC) { } -std::string slsDetector::setDetectorIP(std::string detectorIP) { +std::string slsDetector::setDetectorIP(const std::string& detectorIP) { struct sockaddr_in sa; if (detectorIP.length() && detectorIP.length() < 16) { int result = inet_pton(AF_INET, detectorIP.c_str(), &(sa.sin_addr)); @@ -2890,12 +2886,12 @@ std::string slsDetector::setDetectorIP(std::string detectorIP) { } -std::string slsDetector::setReceiver(std::string receiverIP) { +std::string slsDetector::setReceiver(const std::string& receiverIP) { FILE_LOG(logDEBUG1) << "Setting up Receiver with " << receiverIP; // recieverIP is none if (receiverIP == "none") { memset(thisDetector->receiver_hostname, 0, MAX_STR_LENGTH); - strcpy(thisDetector->receiver_hostname, "none"); + sls::strcpy_safe(thisDetector->receiver_hostname, "none"); thisDetector->receiverOnlineFlag = OFFLINE_FLAG; return std::string(thisDetector->receiver_hostname); } @@ -2991,7 +2987,7 @@ std::string slsDetector::setReceiver(std::string receiverIP) { } -std::string slsDetector::setReceiverUDPIP(std::string udpip) { +std::string slsDetector::setReceiverUDPIP(const std::string& udpip) { struct sockaddr_in sa; if (udpip.length() && udpip.length() < 16) { int result = inet_pton(AF_INET, udpip.c_str(), &(sa.sin_addr)); @@ -3003,7 +2999,7 @@ std::string slsDetector::setReceiverUDPIP(std::string udpip) { } // valid format else { - strcpy(thisDetector->receiverUDPIP,udpip.c_str()); + sls::strcpy_safe(thisDetector->receiverUDPIP,udpip.c_str()); if (!strcmp(thisDetector->receiver_hostname, "none")) { FILE_LOG(logDEBUG1) << "Receiver hostname not set yet"; } else if (setUDPConnection() == FAIL) { @@ -3015,7 +3011,7 @@ std::string slsDetector::setReceiverUDPIP(std::string udpip) { } -std::string slsDetector::setReceiverUDPMAC(std::string udpmac) { +std::string slsDetector::setReceiverUDPMAC(const std::string& udpmac) { // invalid format if ((udpmac.length() != 17) || (udpmac[2] != ':') || (udpmac[5] != ':') || (udpmac[8] != ':') || @@ -3060,7 +3056,7 @@ int slsDetector::setReceiverUDPPort2(int udpport) { } -std::string slsDetector::setClientStreamingPort(std::string port) { +std::string slsDetector::setClientStreamingPort(const std::string& port) { thisDetector->zmqport = stoi(port); return getClientStreamingPort(); } diff --git a/slsDetectorSoftware/slsDetector/slsDetector.h b/slsDetectorSoftware/slsDetector/slsDetector.h index d1f05a45e..cbacbc1cf 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.h +++ b/slsDetectorSoftware/slsDetector/slsDetector.h @@ -510,7 +510,7 @@ public: * @returns OK or FAIL * \sa sharedSlsDetector */ - int setTCPSocket(std::string const name="", int const control_port=-1, int const stop_port=-1); + int setTCPSocket(const std::string& hostname="", int control_port=-1, int stop_port=-1); /** * Set/Gets TCP Port of detector or receiver @@ -563,7 +563,7 @@ public: * @param cmd command to be executed * @returns OK or FAIL */ - int execCommand(std::string cmd); + int execCommand(const std::string& cmd); /** * Updates some of the shared memory receiving the data from the detector @@ -585,7 +585,7 @@ public: * @param m multiSlsDetector reference to parse commands * @returns OK or FAIL */ - int writeConfigurationFile(std::string const fname, multiSlsDetector* m); + int writeConfigurationFile(const std::string& fname, multiSlsDetector* m); /** * Write current configuration to a stream @@ -672,7 +672,7 @@ public: * @param s trimbits/settings directory * @returns the trimbit/settings directory */ - std::string setSettingsDir(std::string s); + std::string setSettingsDir(const std::string& dir); /** * Loads the modules settings/trimbits reading from a specific file @@ -680,7 +680,7 @@ public: * @param fname specific settings/trimbits file * returns OK or FAIL */ - int loadSettingsFile(std::string fname); + int loadSettingsFile(const std::string& fname); /** * Saves the modules settings/trimbits to a specific file @@ -688,7 +688,7 @@ public: * @param fname specific settings/trimbits file * returns OK or FAIL */ - int saveSettingsFile(std::string fname); + int saveSettingsFile(const std::string& fname); /** * Get run status of the detector @@ -864,7 +864,7 @@ public: * @param value network parameter value * @returns network parameter value set (from getNetworkParameter) */ - std::string setNetworkParameter(networkParameter index, std::string value); + std::string setNetworkParameter(networkParameter index, const std::string& value); /** * Get network parameter @@ -944,14 +944,14 @@ public: * @param detectorMAC detector MAC address * @returns the detector MAC address */ - std::string setDetectorMAC(std::string detectorMAC); + std::string setDetectorMAC(const std::string& detectorMAC); /** * Validates the format of the detector IP address and sets it \sa sharedSlsDetector * @param detectorIP detector IP address * @returns the detector IP address */ - std::string setDetectorIP(std::string detectorIP); + std::string setDetectorIP(const std::string& detectorIP); /** * Validates and sets the receiver. @@ -960,21 +960,21 @@ public: * @param receiver receiver hostname or IP address * @returns the receiver IP address from shared memory */ - std::string setReceiver(std::string receiver); + std::string setReceiver(const std::string& receiver); /** * Validates the format of the receiver UDP IP address and sets it \sa sharedSlsDetector * @param udpip receiver UDP IP address * @returns the receiver UDP IP address */ - std::string setReceiverUDPIP(std::string udpip); + std::string setReceiverUDPIP(const std::string& udpip); /** * Validates the format of the receiver UDP MAC address and sets it \sa sharedSlsDetector * @param udpmac receiver UDP MAC address * @returns the receiver UDP MAC address */ - std::string setReceiverUDPMAC(std::string udpmac); + std::string setReceiverUDPMAC(const std::string& udpmac); /** * Sets the receiver UDP port\sa sharedSlsDetector @@ -996,7 +996,7 @@ public: * calculate individual ports) * @returns the client zmq port */ - std::string setClientStreamingPort(std::string port); + std::string setClientStreamingPort(const std::string& port); /** * Sets the receiver zmq port\sa sharedSlsDetector