setonline, setreceiveronline was never really setting offline flag, so was never really updating detector first time

This commit is contained in:
2019-03-19 18:42:45 +01:00
parent ce6289afda
commit 685fcc31b6

View File

@ -96,32 +96,30 @@ int slsDetector::checkDetectorVersionCompatibility() {
// control server // control server
if (detector_shm()->onlineFlag == ONLINE_FLAG) { if (detector_shm()->onlineFlag == ONLINE_FLAG) {
// in case it throws
detector_shm()->detectorControlAPIVersion = 0;
detector_shm()->detectorStopAPIVersion = 0;
detector_shm()->onlineFlag = OFFLINE_FLAG;
auto client = DetectorSocket(detector_shm()->hostname, detector_shm()->controlPort); auto client = DetectorSocket(detector_shm()->hostname, detector_shm()->controlPort);
ret = client.sendCommandThenRead(fnum, &arg, sizeof(arg), nullptr, 0); ret = client.sendCommandThenRead(fnum, &arg, sizeof(arg), nullptr, 0);
if (ret == FAIL) { auto stop = DetectorSocket(detector_shm()->hostname, detector_shm()->stopPort);
detector_shm()->detectorControlAPIVersion = 0; ret = stop.sendCommandThenRead(fnum, &arg, sizeof(arg), nullptr, 0);
// success
detector_shm()->detectorControlAPIVersion = arg;
detector_shm()->detectorStopAPIVersion = arg;
detector_shm()->onlineFlag = ONLINE_FLAG;
// stop server
} else {
detector_shm()->detectorControlAPIVersion = arg;
ret = FAIL;
auto stop = DetectorSocket(detector_shm()->hostname, detector_shm()->stopPort);
ret = stop.sendCommandThenRead(fnum, &arg, sizeof(arg), nullptr, 0);
if (ret == FAIL) {
detector_shm()->detectorStopAPIVersion = 0;
} else {
detector_shm()->detectorStopAPIVersion = arg;
}
}
}
if (ret == FAIL) {
setErrorMask((getErrorMask()) | (VERSION_COMPATIBILITY));
// if (strstr(mess, "Unrecognized Function") != nullptr) {
// FILE_LOG(logERROR) << "The " << ((t == CONTROL_PORT) ? "detector" : "receiver") << " server is too old to get API version. Please update detector server!";
// }
} }
// pointless
// if (ret == FAIL) {
// setErrorMask((getErrorMask()) | (VERSION_COMPATIBILITY));
// }
return ret; return ret;
} }
@ -136,21 +134,23 @@ int slsDetector::checkReceiverVersionCompatibility() {
<< std::hex << arg << std::dec; << std::hex << arg << std::dec;
if (detector_shm()->receiverOnlineFlag == ONLINE_FLAG) { if (detector_shm()->receiverOnlineFlag == ONLINE_FLAG) {
// in case it throws
detector_shm()->receiverAPIVersion = 0;
detector_shm()->receiverOnlineFlag = OFFLINE_FLAG;
auto receiver = ReceiverSocket(detector_shm()->receiver_hostname, detector_shm()->receiverTCPPort); auto receiver = ReceiverSocket(detector_shm()->receiver_hostname, detector_shm()->receiverTCPPort);
ret = receiver.sendCommandThenRead(fnum, &arg, sizeof(arg), nullptr, 0); ret = receiver.sendCommandThenRead(fnum, &arg, sizeof(arg), nullptr, 0);
if (ret == FAIL) {
detector_shm()->receiverAPIVersion = 0; // success
} else { detector_shm()->receiverAPIVersion = arg;
detector_shm()->receiverAPIVersion = arg; detector_shm()->receiverOnlineFlag = ONLINE_FLAG;
}
} }
if (ret == FAIL) { // pointless
setErrorMask((getErrorMask()) | (VERSION_COMPATIBILITY)); // if (ret == FAIL) {
// if (strstr(mess, "Unrecognized Function") != nullptr) { // setErrorMask((getErrorMask()) | (VERSION_COMPATIBILITY));
// FILE_LOG(logERROR) << "The " << ((t == CONTROL_PORT) ? "detector" : "receiver") << " server is too old to get API version. Please update detector server!"; // }
// }
}
return ret; return ret;
} }
@ -698,22 +698,35 @@ void slsDetector::updateMultiSize(int detx, int dety) {
int slsDetector::setOnline(int value) { int slsDetector::setOnline(int value) {
if (value != GET_ONLINE_FLAG) { if (value != GET_ONLINE_FLAG) {
detector_shm()->onlineFlag = value;
// set offline
if (value == OFFLINE_FLAG) {
detector_shm()->onlineFlag = value;
}
// set online // set online
if (detector_shm()->onlineFlag == ONLINE_FLAG) { else {
int old = detector_shm()->onlineFlag; int old = detector_shm()->onlineFlag;
// connect and set offline flag (set it to fail in case it throws)
detector_shm()->onlineFlag = OFFLINE_FLAG;
auto client = DetectorSocket(detector_shm()->hostname, detector_shm()->controlPort);
client.close();
detector_shm()->onlineFlag = ONLINE_FLAG;
// connecting first time // connecting first time
if (detector_shm()->onlineFlag == ONLINE_FLAG && old == OFFLINE_FLAG) { if (detector_shm()->onlineFlag == ONLINE_FLAG && old == OFFLINE_FLAG) {
auto client = DetectorSocket(detector_shm()->hostname, detector_shm()->controlPort); // check version compatibility (first time)
FILE_LOG(logINFO) << "Detector connecting for the first time - updating!"; if ((detector_shm()->detectorControlAPIVersion == 0) ||
client.close(); (detector_shm()->detectorStopAPIVersion == 0)) {
updateDetector(); checkDetectorVersionCompatibility();
} }
// error
else if (detector_shm()->onlineFlag == OFFLINE_FLAG) { // check detector version could set it offline
FILE_LOG(logERROR) << "Cannot connect to detector"; if (detector_shm()->onlineFlag == ONLINE_FLAG) {
setErrorMask((getErrorMask()) | (CANNOT_CONNECT_TO_DETECTOR)); FILE_LOG(logINFO) << "Detector connecting for the first time - updating!";
updateDetector();
}
} }
} }
} }
@ -4010,17 +4023,27 @@ int slsDetector::setReceiverOnline(int value) {
// no receiver // no receiver
if (!strcmp(detector_shm()->receiver_hostname, "none")) { if (!strcmp(detector_shm()->receiver_hostname, "none")) {
detector_shm()->receiverOnlineFlag = OFFLINE_FLAG; detector_shm()->receiverOnlineFlag = OFFLINE_FLAG;
} else {
detector_shm()->receiverOnlineFlag = value;
} }
// set online
if (detector_shm()->receiverOnlineFlag == ONLINE_FLAG) { else {
// setReceiverTCPSocket(); // set offline
// error in connecting if (value == OFFLINE_FLAG) {
if (detector_shm()->receiverOnlineFlag == OFFLINE_FLAG) { detector_shm()->receiverOnlineFlag = value;
FILE_LOG(logERROR) << "Cannot connect to receiver"; }
setErrorMask((getErrorMask()) | (CANNOT_CONNECT_TO_RECEIVER));
} // set online
else {
// connect and set offline flag
detector_shm()->receiverOnlineFlag = OFFLINE_FLAG;
auto receiver = ReceiverSocket(detector_shm()->receiver_hostname, detector_shm()->receiverTCPPort);
receiver.close();
detector_shm()->receiverOnlineFlag = ONLINE_FLAG;
// check for version compatibility
if (detector_shm()->receiverAPIVersion == 0) {
checkReceiverVersionCompatibility();
}
}
} }
} }
return detector_shm()->receiverOnlineFlag; return detector_shm()->receiverOnlineFlag;