mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-05-03 19:30:04 +02:00
removing local variable in slsDetector::setTCPSocket and adding some const string&
This commit is contained in:
parent
b46fb5e9c4
commit
5ea5e83236
@ -1003,18 +1003,14 @@ std::string slsDetector::checkOnline() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int slsDetector::setTCPSocket(std::string const name, int const control_port, int const stop_port) {
|
int slsDetector::setTCPSocket(const std::string& hostname, int control_port, int stop_port) {
|
||||||
char thisName[MAX_STR_LENGTH] = {0};
|
|
||||||
int thisCP = 0, thisSP = 0;
|
int thisCP = 0, thisSP = 0;
|
||||||
int ret = OK;
|
int ret = OK;
|
||||||
|
|
||||||
// hostname
|
// hostname
|
||||||
if (name.empty()) {
|
if (!hostname.empty()) {
|
||||||
strcpy(thisName,thisDetector->hostname);
|
|
||||||
} else {
|
|
||||||
FILE_LOG(logDEBUG1) << "Setting hostname";
|
FILE_LOG(logDEBUG1) << "Setting hostname";
|
||||||
strcpy(thisName, name.c_str());
|
sls::strcpy_safe(thisDetector->hostname, hostname.c_str());
|
||||||
strcpy(thisDetector->hostname, thisName);
|
|
||||||
if (controlSocket) {
|
if (controlSocket) {
|
||||||
delete controlSocket;
|
delete controlSocket;
|
||||||
controlSocket = nullptr;
|
controlSocket = nullptr;
|
||||||
@ -1054,10 +1050,10 @@ int slsDetector::setTCPSocket(std::string const name, int const control_port, in
|
|||||||
// create control socket
|
// create control socket
|
||||||
if (!controlSocket) {
|
if (!controlSocket) {
|
||||||
try {
|
try {
|
||||||
controlSocket = new MySocketTCP(thisName, thisCP);
|
controlSocket = new MySocketTCP(thisDetector->hostname, thisCP);
|
||||||
FILE_LOG(logDEBUG1) << "Control socket connected " << thisName << " " << thisCP;
|
FILE_LOG(logDEBUG1) << "Control socket connected " << thisDetector->hostname << " " << thisCP;
|
||||||
} catch(...) {
|
} catch(...) {
|
||||||
FILE_LOG(logERROR) << "Could not connect control socket " << thisName << " " << thisCP;
|
FILE_LOG(logERROR) << "Could not connect control socket " << thisDetector->hostname << " " << thisCP;
|
||||||
controlSocket = nullptr;
|
controlSocket = nullptr;
|
||||||
ret = FAIL;
|
ret = FAIL;
|
||||||
}
|
}
|
||||||
@ -1067,10 +1063,10 @@ int slsDetector::setTCPSocket(std::string const name, int const control_port, in
|
|||||||
// create stop socket
|
// create stop socket
|
||||||
if (!stopSocket) {
|
if (!stopSocket) {
|
||||||
try {
|
try {
|
||||||
stopSocket = new MySocketTCP(thisName, thisSP);
|
stopSocket = new MySocketTCP(thisDetector->hostname, thisSP);
|
||||||
FILE_LOG(logDEBUG1) << "Stop socket connected " << thisName << " " << thisSP;
|
FILE_LOG(logDEBUG1) << "Stop socket connected " << thisDetector->hostname << " " << thisSP;
|
||||||
} catch(...) {
|
} catch(...) {
|
||||||
FILE_LOG(logERROR) << "Could not connect Stop socket " << thisName << " " << thisSP;
|
FILE_LOG(logERROR) << "Could not connect Stop socket " << thisDetector->hostname << " " << thisSP;
|
||||||
stopSocket = nullptr;
|
stopSocket = nullptr;
|
||||||
ret = FAIL;
|
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 fnum = F_EXEC_COMMAND;
|
||||||
int ret = FAIL;
|
int ret = FAIL;
|
||||||
char arg[MAX_STR_LENGTH] = {0};
|
char arg[MAX_STR_LENGTH] = {0};
|
||||||
char retval[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;
|
FILE_LOG(logDEBUG1) << "Sending command to detector " << arg;
|
||||||
|
|
||||||
if (thisDetector->onlineFlag == ONLINE_FLAG && connectControl() == OK) {
|
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;
|
int iline = 0;
|
||||||
std::ofstream outfile;
|
std::ofstream outfile;
|
||||||
outfile.open(fname.c_str(),std::ios_base::out);
|
outfile.open(fname.c_str(),std::ios_base::out);
|
||||||
@ -1770,13 +1766,13 @@ std::string slsDetector::getSettingsDir() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string slsDetector::setSettingsDir(std::string s) {
|
std::string slsDetector::setSettingsDir(const std::string& dir) {
|
||||||
sls::strcpy_safe(thisDetector->settingsDir, s.c_str());
|
sls::strcpy_safe(thisDetector->settingsDir, dir.c_str());
|
||||||
return thisDetector->settingsDir;
|
return thisDetector->settingsDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int slsDetector::loadSettingsFile(std::string fname) {
|
int slsDetector::loadSettingsFile(const std::string& fname) {
|
||||||
std::string fn = fname;
|
std::string fn = fname;
|
||||||
std::ostringstream ostfn;
|
std::ostringstream ostfn;
|
||||||
ostfn << fname;
|
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::string fn = fname;
|
||||||
std::ostringstream ostfn;
|
std::ostringstream ostfn;
|
||||||
ostfn << fname;
|
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) {
|
switch (index) {
|
||||||
case DETECTOR_MAC:
|
case DETECTOR_MAC:
|
||||||
return setDetectorMAC(value);
|
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
|
// invalid format
|
||||||
if ((detectorMAC.length() != 17) ||
|
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;
|
struct sockaddr_in sa;
|
||||||
if (detectorIP.length() && detectorIP.length() < 16) {
|
if (detectorIP.length() && detectorIP.length() < 16) {
|
||||||
int result = inet_pton(AF_INET, detectorIP.c_str(), &(sa.sin_addr));
|
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;
|
FILE_LOG(logDEBUG1) << "Setting up Receiver with " << receiverIP;
|
||||||
// recieverIP is none
|
// recieverIP is none
|
||||||
if (receiverIP == "none") {
|
if (receiverIP == "none") {
|
||||||
memset(thisDetector->receiver_hostname, 0, MAX_STR_LENGTH);
|
memset(thisDetector->receiver_hostname, 0, MAX_STR_LENGTH);
|
||||||
strcpy(thisDetector->receiver_hostname, "none");
|
sls::strcpy_safe(thisDetector->receiver_hostname, "none");
|
||||||
thisDetector->receiverOnlineFlag = OFFLINE_FLAG;
|
thisDetector->receiverOnlineFlag = OFFLINE_FLAG;
|
||||||
return std::string(thisDetector->receiver_hostname);
|
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;
|
struct sockaddr_in sa;
|
||||||
if (udpip.length() && udpip.length() < 16) {
|
if (udpip.length() && udpip.length() < 16) {
|
||||||
int result = inet_pton(AF_INET, udpip.c_str(), &(sa.sin_addr));
|
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
|
// valid format
|
||||||
else {
|
else {
|
||||||
strcpy(thisDetector->receiverUDPIP,udpip.c_str());
|
sls::strcpy_safe(thisDetector->receiverUDPIP,udpip.c_str());
|
||||||
if (!strcmp(thisDetector->receiver_hostname, "none")) {
|
if (!strcmp(thisDetector->receiver_hostname, "none")) {
|
||||||
FILE_LOG(logDEBUG1) << "Receiver hostname not set yet";
|
FILE_LOG(logDEBUG1) << "Receiver hostname not set yet";
|
||||||
} else if (setUDPConnection() == FAIL) {
|
} 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
|
// invalid format
|
||||||
if ((udpmac.length() != 17) ||
|
if ((udpmac.length() != 17) ||
|
||||||
(udpmac[2] != ':') || (udpmac[5] != ':') || (udpmac[8] != ':') ||
|
(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);
|
thisDetector->zmqport = stoi(port);
|
||||||
return getClientStreamingPort();
|
return getClientStreamingPort();
|
||||||
}
|
}
|
||||||
|
@ -510,7 +510,7 @@ public:
|
|||||||
* @returns OK or FAIL
|
* @returns OK or FAIL
|
||||||
* \sa sharedSlsDetector
|
* \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
|
* Set/Gets TCP Port of detector or receiver
|
||||||
@ -563,7 +563,7 @@ public:
|
|||||||
* @param cmd command to be executed
|
* @param cmd command to be executed
|
||||||
* @returns OK or FAIL
|
* @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
|
* Updates some of the shared memory receiving the data from the detector
|
||||||
@ -585,7 +585,7 @@ public:
|
|||||||
* @param m multiSlsDetector reference to parse commands
|
* @param m multiSlsDetector reference to parse commands
|
||||||
* @returns OK or FAIL
|
* @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
|
* Write current configuration to a stream
|
||||||
@ -672,7 +672,7 @@ public:
|
|||||||
* @param s trimbits/settings directory
|
* @param s trimbits/settings directory
|
||||||
* @returns the trimbit/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
|
* Loads the modules settings/trimbits reading from a specific file
|
||||||
@ -680,7 +680,7 @@ public:
|
|||||||
* @param fname specific settings/trimbits file
|
* @param fname specific settings/trimbits file
|
||||||
* returns OK or FAIL
|
* returns OK or FAIL
|
||||||
*/
|
*/
|
||||||
int loadSettingsFile(std::string fname);
|
int loadSettingsFile(const std::string& fname);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves the modules settings/trimbits to a specific file
|
* Saves the modules settings/trimbits to a specific file
|
||||||
@ -688,7 +688,7 @@ public:
|
|||||||
* @param fname specific settings/trimbits file
|
* @param fname specific settings/trimbits file
|
||||||
* returns OK or FAIL
|
* returns OK or FAIL
|
||||||
*/
|
*/
|
||||||
int saveSettingsFile(std::string fname);
|
int saveSettingsFile(const std::string& fname);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get run status of the detector
|
* Get run status of the detector
|
||||||
@ -864,7 +864,7 @@ public:
|
|||||||
* @param value network parameter value
|
* @param value network parameter value
|
||||||
* @returns network parameter value set (from getNetworkParameter)
|
* @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
|
* Get network parameter
|
||||||
@ -944,14 +944,14 @@ public:
|
|||||||
* @param detectorMAC detector MAC address
|
* @param detectorMAC detector MAC address
|
||||||
* @returns the 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
|
* Validates the format of the detector IP address and sets it \sa sharedSlsDetector
|
||||||
* @param detectorIP detector IP address
|
* @param detectorIP detector IP address
|
||||||
* @returns the 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.
|
* Validates and sets the receiver.
|
||||||
@ -960,21 +960,21 @@ public:
|
|||||||
* @param receiver receiver hostname or IP address
|
* @param receiver receiver hostname or IP address
|
||||||
* @returns the receiver IP address from shared memory
|
* @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
|
* Validates the format of the receiver UDP IP address and sets it \sa sharedSlsDetector
|
||||||
* @param udpip receiver UDP IP address
|
* @param udpip receiver UDP IP address
|
||||||
* @returns the 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
|
* Validates the format of the receiver UDP MAC address and sets it \sa sharedSlsDetector
|
||||||
* @param udpmac receiver UDP MAC address
|
* @param udpmac receiver UDP MAC address
|
||||||
* @returns the 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
|
* Sets the receiver UDP port\sa sharedSlsDetector
|
||||||
@ -996,7 +996,7 @@ public:
|
|||||||
* calculate individual ports)
|
* calculate individual ports)
|
||||||
* @returns the client zmq port
|
* @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
|
* Sets the receiver zmq port\sa sharedSlsDetector
|
||||||
|
Loading…
x
Reference in New Issue
Block a user