From 0bea688a83d5a00127b65449448d1343fcc3b502 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Wed, 23 Aug 2017 19:06:40 +0200 Subject: [PATCH] changes for external gui --- .../multiSlsDetector/multiSlsDetector.cpp | 33 ++++++++++--------- .../multiSlsDetector/multiSlsDetector.h | 2 +- slsDetectorSoftware/slsDetector/slsDetector.h | 2 +- .../slsDetector/slsDetectorCommand.cpp | 33 ++++++++++++------- .../slsDetector/slsDetectorUtils.h | 13 ++++++++ 5 files changed, 54 insertions(+), 29 deletions(-) diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index 1ae24fde9..3652d3a80 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -3590,11 +3590,11 @@ string multiSlsDetector::getNetworkParameter(networkParameter p) { string multiSlsDetector::setNetworkParameter(networkParameter p, string s){ // disable data streaming before changing zmq port (but only if they were on) - /*int prev_streaming = 0;*/ - // if (p == RECEIVER_STREAMING_PORT) { - /*prev_streaming = getStreamingSocketsCreatedInClient();*/ - // enableDataStreamingFromReceiver(0); - // } + int prev_streaming = 0; + if (p == RECEIVER_STREAMING_PORT) { + prev_streaming = getStreamingSocketsCreatedInClient(); + enableDataStreamingFromReceiver(0); + } if (s.find('+')==string::npos) { @@ -3647,11 +3647,11 @@ string multiSlsDetector::setNetworkParameter(networkParameter p, string s){ } } -/* + //enable data streaming if it was on if (p == RECEIVER_STREAMING_PORT && prev_streaming) enableDataStreamingFromReceiver(1); -*/ + return getNetworkParameter(p); } @@ -5874,8 +5874,10 @@ int multiSlsDetector::getStreamingSocketsCreatedInClient() { int multiSlsDetector::enableDataStreamingFromReceiver(int enable){ - /* if(enable >= 0){ - + //create client sockets only if no external gui + if (!thisMultiDetector->externalgui) { + if(enable >= 0){ + //destroy data threads if(dataSocketsStarted) createReceivingDataSockets(true); @@ -5890,10 +5892,8 @@ int multiSlsDetector::enableDataStreamingFromReceiver(int enable){ return -1; } } - - - }*/ - + } + } int ret=-100; @@ -5928,9 +5928,10 @@ int multiSlsDetector::enableDataStreamingFromReceiver(int enable){ } } - /* if(ret != dataSocketsStarted) - ret = -1; - */ + if (!thisMultiDetector->externalgui) { + if (ret != dataSocketsStarted) + ret = -1; + } return ret; } diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h index feba8e9ab..258bfa933 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h @@ -1455,7 +1455,7 @@ class multiSlsDetector : public slsDetectorUtils { Get external gui flag from shared memory \returns external gui flag */ - void getExternalGuiFlag(); + bool getExternalGuiFlag(); diff --git a/slsDetectorSoftware/slsDetector/slsDetector.h b/slsDetectorSoftware/slsDetector/slsDetector.h index a44770a9e..07a92ab14 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.h +++ b/slsDetectorSoftware/slsDetector/slsDetector.h @@ -1894,7 +1894,7 @@ class slsDetector : public slsDetectorUtils, public energyConversion { Get external gui flag from shared memory \returns external gui flag */ - void getExternalGuiFlag(); + bool getExternalGuiFlag(); protected: diff --git a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp index 26caf3999..d3c49ff9c 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp @@ -256,9 +256,9 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) { */ /*! \page config - - datastream enables/disables the 0MQ data stream (0MQ threads created) from receiver to client. \c Returns \c (int) + - externalgui sets/gets external gui flag. 1 sets and enables the 0MQ data stream (0MQ threads created) from receiver to client, while 0 unsets and disables. \c Returns \c (int) */ - descrToFuncMap[i].m_pFuncName="datastream"; // + descrToFuncMap[i].m_pFuncName="externalgui"; // descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdDataStream; i++; @@ -2296,8 +2296,9 @@ string slsDetectorCommand::cmdAcquire(int narg, char *args[], int action) { myDet->setOnline(ONLINE_FLAG); - myDet->setReceiverOnline(ONLINE_FLAG); - /*if (myDet->setReceiverOnline(ONLINE_FLAG) == ONLINE_FLAG) { + if (myDet->getExternalGuiFlag()) + myDet->setReceiverOnline(ONLINE_FLAG); + else if (myDet->setReceiverOnline(ONLINE_FLAG) == ONLINE_FLAG) { // command line: must be off, if receiver on or there was -1, then if (myDet->enableDataStreamingFromReceiver(-1) != 0){ //switch it off, if error @@ -2305,7 +2306,7 @@ string slsDetectorCommand::cmdAcquire(int narg, char *args[], int action) { return string("could not disable data streaming in receiver\n"); } } - }*/ + } if(myDet->acquire() == FAIL) return string("acquire unsuccessful"); @@ -2471,10 +2472,20 @@ string slsDetectorCommand::cmdDataStream(int narg, char *args[], int action) { if (action==PUT_ACTION) { if (!sscanf(args[1],"%d",&ival)) - return string ("cannot scan datastream mode"); + return string ("cannot scan externalgui mode"); + bool bval=ival>0?true:false; + bool oldval = myDet->getExternalGuiFlag(); + myDet->setExternalGuiFlag(bval); myDet->enableDataStreamingFromReceiver(ival); } - sprintf(ans,"%d",myDet->enableDataStreamingFromReceiver()); + + int retval = myDet->getExternalGuiFlag(); + //if external gui on and datastreaming off + if (retval && !myDet->enableDataStreamingFromReceiver()) { + retval=-1; + printf("Error: data streaming in receiver is switched off while external gui flag in shared memory is off.\n"); + } + sprintf(ans,"%d",myDet->getExternalGuiFlag()); return string(ans); } @@ -2483,9 +2494,9 @@ string slsDetectorCommand::helpDataStream(int narg, char *args[], int action) { ostringstream os; if (action==GET_ACTION || action==HELP_ACTION) - os << string("datastream \t gets if zmq data stream from receiver is enabled. \n"); + os << string("externalgui \t gets external gui flag. 1/0 means the 0MQ data stream (0MQ threads created) from receiver to client is enabled/disabled. -1 for inconsistency. \n"); if (action==PUT_ACTION || action==HELP_ACTION) - os << string("datastream i\t enables/disables the zmq data stream from receiver. \n"); + os << string("externalgui i\t sets external gui flag. 1/0 means the 0MQ data stream (0MQ threads created) from receiver to client is enabled/disabled. \n"); return os.str(); } @@ -5870,7 +5881,7 @@ string slsDetectorCommand::cmdReceiver(int narg, char *args[], int action) { if (action==PUT_ACTION) { if(!strcasecmp(args[1],"start")) { //to ensure data streaming enable is the same across client and receiver - /*if (receivers == ONLINE_FLAG) { + if ((!myDet->getExternalGuiFlag()) && (receivers == ONLINE_FLAG)) { //if it was not off if (myDet->enableDataStreamingFromReceiver(-1) != 0){ //switch it off, if error @@ -5878,7 +5889,7 @@ string slsDetectorCommand::cmdReceiver(int narg, char *args[], int action) { return string("could not disable data streaming in receiver\n"); } } - }*/ + } myDet->startReceiver(); } else if(!strcasecmp(args[1],"stop")){ diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUtils.h b/slsDetectorSoftware/slsDetector/slsDetectorUtils.h index 655c77d78..0eb80899d 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUtils.h +++ b/slsDetectorSoftware/slsDetector/slsDetectorUtils.h @@ -846,6 +846,19 @@ virtual int setReceiverFifoDepth(int i = -1)=0; */ virtual bool getAcquiringFlag() = 0; + /** + Set external gui flag in shared memory + \param b set external gui flag + */ + virtual void setExternalGuiFlag(bool b=false) = 0; + + /** + Get external gui flag from shared memory + \returns external gui flag + */ + virtual bool getExternalGuiFlag() = 0; + +