added functionality to set additional json header key value pairs for prototype ctb, server fixed for eiger compile from ctb integration

This commit is contained in:
2019-02-13 09:37:31 +01:00
parent 031a11c4f7
commit f9be8b89ac
9 changed files with 161 additions and 21 deletions

View File

@ -1934,6 +1934,29 @@ std::string multiSlsDetector::getAdditionalJsonHeader(int detPos) {
return sls::concatenateIfDifferent(r);
}
std::string multiSlsDetector::setAdditionalJsonParameter(const std::string& key, const std::string& value, int detPos) {
// single
if (detPos >= 0) {
return detectors[detPos]->setAdditionalJsonParameter(key, value);
}
// multi
auto r = parallelCall(&slsDetector::setAdditionalJsonParameter, key, value);
return sls::concatenateIfDifferent(r);
}
std::string multiSlsDetector::getAdditionalJsonParameter(const std::string& key, int detPos) {
// single
if (detPos >= 0) {
return detectors[detPos]->getAdditionalJsonParameter(key);
}
// multi
auto r = serialCall(&slsDetector::getAdditionalJsonParameter, key);
return sls::concatenateIfDifferent(r);
}
int multiSlsDetector::setReceiverUDPSocketBufferSize(int udpsockbufsize, int detPos) {
// single
if (detPos >= 0) {

View File

@ -1057,17 +1057,36 @@ class multiSlsDetector : public virtual slsDetectorDefs,
* Sets the additional json header
* @param jsonheader additional json header
* @param detPos -1 for all detectors in list or specific detector position
* @returns additional json header, returns "none" if default setting and no custom ip set
* @returns additional json header, default is empty
*/
std::string setAdditionalJsonHeader(const std::string& jsonheader, int detPos = -1);
/**
* Returns the additional json header
* @param detPos -1 for all detectors in list or specific detector position
* @returns the additional json header, returns "none" if default setting and no custom ip set
* @returns the additional json header, default is empty
*/
std::string getAdditionalJsonHeader(int detPos = -1);
/**
* Sets the value for the additional json header parameter if found, else append it
* @param key additional json header parameter
* @param value additional json header parameter value (cannot be empty)
* @param detPos -1 for all detectors in list or specific detector position
* @returns the additional json header parameter value,
* empty if no parameter found in additional json header
*/
std::string setAdditionalJsonParameter(const std::string& key, const std::string& value, int detPos = -1);
/**
* Returns the additional json header parameter value
* @param key additional json header parameter
* @param detPos -1 for all detectors in list or specific detector position
* @returns the additional json header parameter value,
* empty if no parameter found in additional json header
*/
std::string getAdditionalJsonParameter(const std::string& key, int detPos = -1);
/**
* Sets the receiver UDP socket buffer size
* @param udpsockbufsize additional json header

View File

@ -310,7 +310,7 @@ void slsDetector::setDetectorSpecificParameters(detectorType type, detParameterL
list.nGappixelsY = 1;
break;
default:
FILE_LOG(logERROR) << "Unknown detector type!";
FILE_LOG(logERROR) << "Unknown detector type! " << type;
throw std::exception();
}
}
@ -2625,7 +2625,7 @@ std::string slsDetector::setAdditionalJsonHeader(const std::string &jsonheader)
sls::strcpy_safe(args, jsonheader.c_str());
FILE_LOG(logDEBUG1) << "Sending additional json header " << args;
if (thisDetector->receiverOnlineFlag == ONLINE_FLAG) {
if (thisDetector->receiverOnlineFlag == ONLINE_FLAG) {
auto receiver = sls::ClientSocket(thisDetector->receiver_hostname, thisDetector->receiverTCPPort);
ret = receiver.sendCommandThenRead(fnum, args, sizeof(args), retvals, sizeof(retvals));
if (ret == FAIL) {
@ -2646,6 +2646,65 @@ std::string slsDetector::getAdditionalJsonHeader() {
return std::string(thisDetector->receiver_additionalJsonHeader);
}
std::string slsDetector::setAdditionalJsonParameter(const std::string& key, const std::string& value) {
// validation (ignore if key or value has , : ")
if (key.find_first_of(",\":") != std::string::npos || value.find_first_of(",\":") != std::string::npos) {
FILE_LOG(logERROR) << "Could not set additional json header parameter as the key or value has illegal characters (,\":)";
return getAdditionalJsonParameter(key);
}
std::string header(thisDetector->receiver_additionalJsonHeader);
size_t keyPos = header.find(std::string("\"") + key + std::string("\":") );
// if key found, replace value
if (keyPos != std::string::npos) {
size_t valuePosStart = header.find (std::string(":\""), keyPos) + 2;
size_t valuePosEnd = header.find (std::string("\""), valuePosStart) - 1;
header.replace(valuePosStart, valuePosEnd - valuePosStart + 1, value);
}
// key not found, append key value pair
else {
if (header.length()) {
header.append(",");
}
// put it in formula \"key\":\"value\"
header.append(std::string("\"") + key + std::string("\"") + std::string(":")
+ std::string("\"") + value + std::string("\""));
}
// update additional json header
setAdditionalJsonHeader(header);
return getAdditionalJsonParameter(key);
}
std::string slsDetector::getAdditionalJsonParameter(const std::string& key) {
// additional json header is empty
if (!strlen(thisDetector->receiver_additionalJsonHeader))
return std::string("");
// add quotations before and after the key value
std::string keyLiteral = key;
keyLiteral.insert(0, "\"");
keyLiteral.append("\"");
// loop through the parameters
for (const auto &parameter : sls::split(thisDetector->receiver_additionalJsonHeader, ',')) {
// get a vector of key value pair for each parameter
const auto &pairs = sls::split(parameter, ':');
// match for key
if (pairs[0] == keyLiteral) {
// return value without quotations
return pairs[1].substr(1, pairs[1].length() - 2);
}
}
// return empty string as no match found with key
return std::string("");
}
int slsDetector::setReceiverUDPSocketBufferSize(int udpsockbufsize) {
int fnum = F_RECEIVER_UDP_SOCK_BUF_SIZE;
int ret = FAIL;

View File

@ -977,6 +977,23 @@ public:
*/
std::string getAdditionalJsonHeader();
/**
* Sets the value for the additional json header parameter if found, else append it
* @param key additional json header parameter
* @param value additional json header parameter value (cannot be empty)
* @returns the additional json header parameter value,
* empty if no parameter found in additional json header
*/
std::string setAdditionalJsonParameter(const std::string& key, const std::string& value);
/**
* Returns the additional json header parameter value
* @param key additional json header parameter
* @returns the additional json header parameter value,
* empty if no parameter found in additional json header
*/
std::string getAdditionalJsonParameter(const std::string& key);
/**
* Sets the receiver UDP socket buffer size
* @param udpsockbufsize additional json header

View File

@ -1640,6 +1640,13 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) {
descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdNetworkParameter;
i++;
/*! \page network
- <b>rx_jsonpara [k] [v]</b> sets/gets value v for additional json header parameter k to be streamed out with the zmq from receiver. If empty, then no parameter found Use only if it needs to be processed by an intermediate process. \c Returns \c (string)
*/
descrToFuncMap[i].m_pFuncName = "rx_jsonpara"; //
descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdNetworkParameter;
i++;
/*! \page network
- <b>configuremac [i]</b> configures the MAC of the detector with these parameters: detectorip, detectormac, rx_udpip, rx_udpmac, rx_udpport, rx_udpport2 (if applicable). This command is already included in \c rx_hsotname. Only put!. \c Returns \c (int)
*/
@ -2844,6 +2851,11 @@ std::string slsDetectorCommand::cmdNetworkParameter(int narg, char *args[], int
myDet->setAdditionalJsonHeader(args[1], detPos);
}
return myDet->getAdditionalJsonHeader(detPos);
} else if (cmd == "rx_jsonpara") {
if (action == PUT_ACTION) {
myDet->setAdditionalJsonParameter(args[1], args[2], detPos);
}
return myDet->getAdditionalJsonParameter(args[1]);
}
return ("unknown network parameter") + cmd;
@ -2884,6 +2896,7 @@ std::string slsDetectorCommand::helpNetworkParameter(int action) {
"out with the zmq from receiver. Default is empty. t must be in the format '\"label1\":\"value1\",\"label2\":\"value2\"' etc."
"Use only if it needs to be processed by an intermediate process."
<< std::endl;
os << "rx_jsonpara [k v]\n sets value to v for additional json header parameter k to be streamed out with the zmq from receiver. Use only if it needs to be processed by an intermediate process." << std::endl;
os << "rx_udpsocksize [t]\n sets the UDP socket buffer size. Different defaults for Jungfrau. "
"Does not remember in client shared memory, "
"so must be initialized each time after setting receiver "
@ -2908,6 +2921,7 @@ std::string slsDetectorCommand::helpNetworkParameter(int action) {
os << "rx_jsonaddheader \n gets additional json header to be streamed "
"out with the zmq from receiver."
<< std::endl;
os << "rx_jsonpara [k] \n gets value of additional json header parameter k to be streamed out with the zmq from receiver. If empty, then no parameter found. Use only if it needs to be processed by an intermediate process." << std::endl;
os << "rx_udpsocksize \n gets the UDP socket buffer size." << std::endl;
os << "rx_realudpsocksize \n gets the actual UDP socket buffer size. Usually double the set udp socket buffer size due to kernel bookkeeping." << std::endl;
}