This commit is contained in:
maliakal_d 2020-09-07 11:15:51 +02:00
parent 5b182469a1
commit f0c576c779
3 changed files with 25 additions and 6 deletions

View File

@ -83,7 +83,8 @@ void ClientInterface::startTCPServer() {
try {
auto socket = server.accept();
try {
verifyLock();
verifyLock(); // lock should be checked only for set (not get),
// Move it back?
ret = decodeFunction(socket);
} catch (const RuntimeError &e) {
// We had an error needs to be sent to client
@ -1115,7 +1116,7 @@ int ClientInterface::set_additional_json_header(Interface &socket) {
json[key] = value;
}
}
verifyIdle(socket);
// verifyIdle(socket); allowing it to be set on the fly
LOG(logDEBUG1) << "Setting additional json header: " << sls::ToString(json);
impl()->setAdditionalJsonHeader(json);
return socket.Send(OK);
@ -1531,7 +1532,7 @@ int ClientInterface::increment_file_index(Interface &socket) {
int ClientInterface::set_additional_json_parameter(Interface &socket) {
char args[2][SHORT_STR_LENGTH]{};
socket.Receive(args);
verifyIdle(socket);
// verifyIdle(socket); allowing it to be set on the fly
LOG(logDEBUG1) << "Setting additional json parameter (" << args[0]
<< "): " << args[1];
impl()->setAdditionalJsonParameter(args[0], args[1]);

View File

@ -69,7 +69,9 @@ void DataStreamer::SetFlippedDataX(int fd) { flippedDataX = fd; }
void DataStreamer::SetAdditionalJsonHeader(
const std::map<std::string, std::string> &json) {
additionJsonHeader = json;
std::lock guard<std::mutex> guard(additionalJsonMutex);
additionalJsonHeader = json;
isAdditionalJsonUpdated = true;
}
void DataStreamer::CreateZmqSockets(int *nunits, uint32_t port,
@ -232,7 +234,13 @@ int DataStreamer::SendHeader(sls_receiver_header *rheader, uint32_t size,
zHeader.quad = *quadEnable;
zHeader.completeImage =
(header.packetNumber < generalData->packetsPerFrame ? false : true);
zHeader.addJsonHeader = additionJsonHeader;
if (isAdditionalJsonUpdated) {
std::lock_guard<std::mutex> guard(additionalalJsonMutex);
localAdditionalJsonHeader = additionalJsonHeader;
isAdditionalalJsonUpdated = false;
}
zHeader.addJsonHeader = localAdditionalJsonHeader;
return zmqSocket->SendHeader(index, zHeader);
}

View File

@ -166,7 +166,17 @@ class DataStreamer : private virtual slsDetectorDefs, public ThreadObject {
int flippedDataX;
/** additional json header */
std::map<std::string, std::string> additionJsonHeader;
std::map<std::string, std::string> additionalJsonHeader;
/** Used by streamer thread to update local copy (reduce number of locks
* during streaming) */
std::atomic<bool>{false};
/** mutex to update json and to read and update local copy */
std::mutex additionalJsonMutex;
/** local copy of additional json header (it can be update on the fly) */
std::map<std::string, std::string> localAdditionalJsonHeader;
/** Aquisition Started flag */
bool startedFlag{nullptr};