mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-05-03 11:20:03 +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) {
|
||||
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();
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user