mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-13 13:27:14 +02:00
gui_client more stable with 2 servers for stop and acquire
git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorGui@169 af1100a4-978c-4157-bff7-07162d2ba061
This commit is contained in:
@ -40,6 +40,15 @@ qClient::qClient(char* hostname){
|
|||||||
delete mySocket;
|
delete mySocket;
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//create socket to connect to stop server
|
||||||
|
myStopSocket = new MySocketTCP(hostname, DEFAULT_GUI_PORTNO+1);
|
||||||
|
if (myStopSocket->getErrorStatus()){
|
||||||
|
cout << "Error: could not connect to host:" << hostname << " with port " << DEFAULT_GUI_PORTNO + 1 << endl;
|
||||||
|
delete myStopSocket;
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -47,6 +56,7 @@ qClient::qClient(char* hostname){
|
|||||||
|
|
||||||
qClient::~qClient() {
|
qClient::~qClient() {
|
||||||
if(mySocket) delete mySocket;
|
if(mySocket) delete mySocket;
|
||||||
|
if(myStopSocket) delete myStopSocket;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -82,9 +92,9 @@ int qClient::executeLine(int narg, char *args[]){
|
|||||||
argument = args[1];
|
argument = args[1];
|
||||||
//start acquisition
|
//start acquisition
|
||||||
if(argument == "start")
|
if(argument == "start")
|
||||||
sendToGuiServer(F_START_ACQUISITION);
|
startAcquisition();
|
||||||
else if (argument == "stop")
|
else if (argument == "stop")
|
||||||
sendToGuiServer(F_STOP_ACQUISITION);
|
stopAcquisition();
|
||||||
else{
|
else{
|
||||||
cout << "Error: could not parse arguments: " << argument << endl;
|
cout << "Error: could not parse arguments: " << argument << endl;
|
||||||
printCommands();
|
printCommands();
|
||||||
@ -96,16 +106,13 @@ int qClient::executeLine(int narg, char *args[]){
|
|||||||
|
|
||||||
|
|
||||||
else if (cmd == "acquire"){
|
else if (cmd == "acquire"){
|
||||||
sendToGuiServer(F_START_AND_READ_ALL);
|
startAcquisition(true);
|
||||||
retval = getStatus();
|
retval = getStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
else if (cmd == "exit"){
|
else if (cmd == "exit"){
|
||||||
if (sendToGuiServer(F_EXIT_SERVER) == OK)
|
return exitServer();
|
||||||
retval = "Gui Server Exited successfully.";
|
|
||||||
else
|
|
||||||
retval = "Gui Server could not exit successfully";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -127,7 +134,7 @@ int qClient::executeLine(int narg, char *args[]){
|
|||||||
|
|
||||||
string qClient::printCommands(){
|
string qClient::printCommands(){
|
||||||
ostringstream os;
|
ostringstream os;
|
||||||
os << "\nexit \t exits server in gui" << std::endl;
|
os << "\nexit \t exits servers in gui" << std::endl;
|
||||||
os << "status \t gets status of acquisition in gui. - can be running or idle" << std::endl;
|
os << "status \t gets status of acquisition in gui. - can be running or idle" << std::endl;
|
||||||
os << "status i starts/stops acquistion in gui-non blocking. i is start or stop" << std::endl;
|
os << "status i starts/stops acquistion in gui-non blocking. i is start or stop" << std::endl;
|
||||||
os << "acquire starts acquistion in gui-blocking" << std::endl;
|
os << "acquire starts acquistion in gui-blocking" << std::endl;
|
||||||
@ -145,12 +152,12 @@ string qClient::getStatus(){
|
|||||||
int progress = 0;
|
int progress = 0;
|
||||||
char answer[100];
|
char answer[100];
|
||||||
|
|
||||||
if (mySocket->Connect() >= 0) {
|
if (myStopSocket->Connect() >= 0) {
|
||||||
mySocket->SendDataOnly(&fnum,sizeof(fnum));
|
myStopSocket->SendDataOnly(&fnum,sizeof(fnum));
|
||||||
mySocket->ReceiveDataOnly(&ret,sizeof(ret));
|
myStopSocket->ReceiveDataOnly(&ret,sizeof(ret));
|
||||||
mySocket->ReceiveDataOnly(&retval,sizeof(retval));
|
myStopSocket->ReceiveDataOnly(&retval,sizeof(retval));
|
||||||
mySocket->ReceiveDataOnly(&progress,sizeof(progress));
|
myStopSocket->ReceiveDataOnly(&progress,sizeof(progress));
|
||||||
mySocket->Disconnect();
|
myStopSocket->Disconnect();
|
||||||
}else
|
}else
|
||||||
exit(-1);
|
exit(-1);
|
||||||
|
|
||||||
@ -165,9 +172,10 @@ string qClient::getStatus(){
|
|||||||
//-------------------------------------------------------------------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
int qClient::sendToGuiServer(int fnum){
|
int qClient::startAcquisition(bool blocking){
|
||||||
|
int fnum = F_START_ACQUISITION;
|
||||||
|
if(blocking) fnum = F_START_AND_READ_ALL;
|
||||||
int ret = FAIL;
|
int ret = FAIL;
|
||||||
char mess[100] = "";
|
|
||||||
|
|
||||||
if (mySocket->Connect() >= 0) {
|
if (mySocket->Connect() >= 0) {
|
||||||
mySocket->SendDataOnly(&fnum,sizeof(fnum));
|
mySocket->SendDataOnly(&fnum,sizeof(fnum));
|
||||||
@ -186,3 +194,41 @@ int qClient::sendToGuiServer(int fnum){
|
|||||||
|
|
||||||
//-------------------------------------------------------------------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
int qClient::stopAcquisition(){
|
||||||
|
int fnum = F_STOP_ACQUISITION;
|
||||||
|
int ret = FAIL;
|
||||||
|
|
||||||
|
if (myStopSocket->Connect() >= 0) {
|
||||||
|
myStopSocket->SendDataOnly(&fnum,sizeof(fnum));
|
||||||
|
myStopSocket->ReceiveDataOnly(&ret,sizeof(ret));
|
||||||
|
if (ret == FAIL){
|
||||||
|
myStopSocket->ReceiveDataOnly(mess,sizeof(mess));
|
||||||
|
std::cout<< "Gui returned error: " << mess << std::endl;
|
||||||
|
}
|
||||||
|
myStopSocket->Disconnect();
|
||||||
|
}else
|
||||||
|
exit(-1);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
int qClient::exitServer(){
|
||||||
|
int fnum = F_EXIT_SERVER;
|
||||||
|
int ret = FAIL;
|
||||||
|
|
||||||
|
if (myStopSocket->Connect() >= 0) {
|
||||||
|
myStopSocket->SendDataOnly(&fnum,sizeof(fnum));
|
||||||
|
myStopSocket->ReceiveDataOnly(&ret,sizeof(ret));
|
||||||
|
myStopSocket->ReceiveDataOnly(mess,sizeof(mess));
|
||||||
|
cout << mess << endl;
|
||||||
|
myStopSocket->Disconnect();
|
||||||
|
}else
|
||||||
|
exit(-1);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
@ -36,15 +36,28 @@ private:
|
|||||||
/** Print list of commands */
|
/** Print list of commands */
|
||||||
string printCommands();
|
string printCommands();
|
||||||
|
|
||||||
/** Send to Gui Server */
|
/** Start Acquisition
|
||||||
int sendToGuiServer(int fnum);
|
* @param blocking true if its a blocking acquistion
|
||||||
|
*/
|
||||||
|
int startAcquisition(bool blocking = false);
|
||||||
|
|
||||||
|
/** Stops Acquisition */
|
||||||
|
int stopAcquisition();
|
||||||
|
|
||||||
/** Gets run status */
|
/** Gets run status */
|
||||||
string getStatus();
|
string getStatus();
|
||||||
|
|
||||||
|
/** Exits Server */
|
||||||
|
int exitServer();
|
||||||
|
|
||||||
/** client socket */
|
/** client socket */
|
||||||
MySocketTCP *mySocket;
|
MySocketTCP *mySocket;
|
||||||
|
|
||||||
|
/** client socket */
|
||||||
|
MySocketTCP *myStopSocket;
|
||||||
|
|
||||||
|
char mess[MAX_STR_LENGTH];
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -77,8 +77,6 @@ public:
|
|||||||
/** Returns progress bar value */
|
/** Returns progress bar value */
|
||||||
int GetProgress(){return tab_measurement->GetProgress();};
|
int GetProgress(){return tab_measurement->GetProgress();};
|
||||||
|
|
||||||
/** Uncheck the Listen to Gui Client mode when server has exited using exit command */
|
|
||||||
void GuiServerExited(){actionListenGuiClient->setChecked(false);};
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/** The Qt Application */
|
/** The Qt Application */
|
||||||
@ -181,6 +179,10 @@ void EnableTabs();
|
|||||||
* */
|
* */
|
||||||
void SetZoomToolTip(bool disable);
|
void SetZoomToolTip(bool disable);
|
||||||
|
|
||||||
|
/** Uncheck the Listen to gui client mode when the server has exited
|
||||||
|
*/
|
||||||
|
void UncheckServer();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/** Adjust the resizing to resize plot, except for actions tab
|
/** Adjust the resizing to resize plot, except for actions tab
|
||||||
* */
|
* */
|
||||||
|
@ -12,17 +12,19 @@
|
|||||||
#include "sls_detector_defs.h"
|
#include "sls_detector_defs.h"
|
||||||
#include "qDefs.h"
|
#include "qDefs.h"
|
||||||
class qDetectorMain;
|
class qDetectorMain;
|
||||||
|
|
||||||
/** Project Class Headers */
|
/** Project Class Headers */
|
||||||
class multiSlsDetector;
|
class multiSlsDetector;
|
||||||
class MySocketTCP;
|
class MySocketTCP;
|
||||||
|
/** Qt Include Headers */
|
||||||
|
#include <QWidget>
|
||||||
/** C++ Include Headers */
|
/** C++ Include Headers */
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*@short Sets up the gui server
|
*@short Sets up the gui server
|
||||||
*/
|
*/
|
||||||
class qServer: public virtual slsDetectorDefs{
|
class qServer: public QWidget, public virtual slsDetectorDefs{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -41,10 +43,10 @@ private:
|
|||||||
int FunctionTable();
|
int FunctionTable();
|
||||||
|
|
||||||
/** Decodes Function */
|
/** Decodes Function */
|
||||||
int DecodeFunction();
|
int DecodeFunction(MySocketTCP* sock);
|
||||||
|
|
||||||
/** Unrecognized Function */
|
/** Exit Server */
|
||||||
int M_nofunc();
|
int ExitServer();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -61,8 +63,21 @@ private:
|
|||||||
*/
|
*/
|
||||||
int StartServer();
|
int StartServer();
|
||||||
|
|
||||||
/** Exit Server */
|
/**
|
||||||
int ExitServer();
|
* Static function - Thread started which listens to client gui to stop acquisition
|
||||||
|
* Called by StartStopServer()
|
||||||
|
* @param this_pointer pointer to this object
|
||||||
|
*/
|
||||||
|
static void* StopServerThread(void *this_pointer);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Thread started which listens to client gui to stop acquisition.
|
||||||
|
* Called by startServerThread()
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
int StopServer();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** Get Detector Status */
|
/** Get Detector Status */
|
||||||
int GetStatus();
|
int GetStatus();
|
||||||
@ -83,8 +98,12 @@ private:
|
|||||||
|
|
||||||
/** tcp socket to gui client */
|
/** tcp socket to gui client */
|
||||||
MySocketTCP *mySocket;
|
MySocketTCP *mySocket;
|
||||||
|
/** tcp socket to gui client to stop or get status */
|
||||||
|
MySocketTCP *myStopSocket;
|
||||||
|
|
||||||
/** server port number*/
|
/** server port number*/
|
||||||
int port_no;
|
int port_no;
|
||||||
|
|
||||||
/** Lock Status if server locked to a client */
|
/** Lock Status if server locked to a client */
|
||||||
int lockStatus;
|
int lockStatus;
|
||||||
|
|
||||||
@ -97,13 +116,20 @@ private:
|
|||||||
static int gui_server_thread_running;
|
static int gui_server_thread_running;
|
||||||
/** thread listening to gui client*/
|
/** thread listening to gui client*/
|
||||||
pthread_t gui_server_thread;
|
pthread_t gui_server_thread;
|
||||||
|
/** thread also listening to gui client to stop acquisition*/
|
||||||
|
pthread_t gui_stop_server_thread;
|
||||||
|
|
||||||
/** server started */
|
/** server started */
|
||||||
int checkStarted;
|
int checkStarted;
|
||||||
|
int checkStopStarted;
|
||||||
|
|
||||||
/** Message */
|
/** Message */
|
||||||
char mess[MAX_STR_LENGTH];
|
char mess[MAX_STR_LENGTH];
|
||||||
|
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void ServerStoppedSignal();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -285,6 +285,10 @@ void qDetectorMain::Initialization(){
|
|||||||
connect(menuUtilities, SIGNAL(triggered(QAction*)), this,SLOT(ExecuteUtilities(QAction*)));
|
connect(menuUtilities, SIGNAL(triggered(QAction*)), this,SLOT(ExecuteUtilities(QAction*)));
|
||||||
// Help Menu
|
// Help Menu
|
||||||
connect(menuHelp, SIGNAL(triggered(QAction*)), this,SLOT(ExecuteHelp(QAction*)));
|
connect(menuHelp, SIGNAL(triggered(QAction*)), this,SLOT(ExecuteHelp(QAction*)));
|
||||||
|
|
||||||
|
|
||||||
|
//server
|
||||||
|
connect(myServer, SIGNAL(ServerStoppedSignal()), this,SLOT(UncheckServer()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -329,9 +333,12 @@ void qDetectorMain::EnableModes(QAction *action){
|
|||||||
|
|
||||||
//listen to gui client
|
//listen to gui client
|
||||||
if(action==actionListenGuiClient){
|
if(action==actionListenGuiClient){
|
||||||
disconnect(menuModes, SIGNAL(triggered(QAction*)), this,SLOT(EnableModes(QAction*)));
|
|
||||||
actionListenGuiClient->setChecked(myServer->StartStopServer(actionListenGuiClient->isChecked()));
|
myServer->StartStopServer(actionListenGuiClient->isChecked());
|
||||||
connect(menuModes, SIGNAL(triggered(QAction*)), this,SLOT(EnableModes(QAction*)));
|
|
||||||
|
//disconnect(menuModes, SIGNAL(triggered(QAction*)), this,SLOT(EnableModes(QAction*)));
|
||||||
|
//actionListenGuiClient->setChecked(myServer->StartStopServer(actionListenGuiClient->isChecked()));
|
||||||
|
//connect(menuModes, SIGNAL(triggered(QAction*)), this,SLOT(EnableModes(QAction*)));
|
||||||
}
|
}
|
||||||
//Set DebugMode
|
//Set DebugMode
|
||||||
else if(action==actionDebug){
|
else if(action==actionDebug){
|
||||||
@ -782,4 +789,17 @@ int qDetectorMain::StartStopAcquisitionFromClient(bool start){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
void qDetectorMain::UncheckServer(){
|
||||||
|
#ifdef VERBOSE
|
||||||
|
cout << "Unchecking Mode : Listen to Gui Client" << endl;
|
||||||
|
#endif
|
||||||
|
disconnect(menuModes, SIGNAL(triggered(QAction*)), this,SLOT(EnableModes(QAction*)));
|
||||||
|
actionListenGuiClient->setChecked(false);
|
||||||
|
connect(menuModes, SIGNAL(triggered(QAction*)), this,SLOT(EnableModes(QAction*)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -27,7 +27,7 @@ int qServer::gui_server_thread_running(0);
|
|||||||
|
|
||||||
|
|
||||||
qServer::qServer(qDetectorMain *t):
|
qServer::qServer(qDetectorMain *t):
|
||||||
myMainTab(t), mySocket(NULL),port_no(DEFAULT_GUI_PORTNO),lockStatus(0){
|
myMainTab(t), mySocket(NULL),myStopSocket(NULL),port_no(DEFAULT_GUI_PORTNO),lockStatus(0){
|
||||||
|
|
||||||
FunctionTable();
|
FunctionTable();
|
||||||
|
|
||||||
@ -40,6 +40,7 @@ qServer::qServer(qDetectorMain *t):
|
|||||||
qServer::~qServer(){
|
qServer::~qServer(){
|
||||||
delete myMainTab;
|
delete myMainTab;
|
||||||
if(mySocket) delete mySocket;
|
if(mySocket) delete mySocket;
|
||||||
|
if(myStopSocket) delete myStopSocket;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -48,9 +49,6 @@ qServer::~qServer(){
|
|||||||
|
|
||||||
int qServer::FunctionTable(){
|
int qServer::FunctionTable(){
|
||||||
|
|
||||||
for (int i=0;i<NUMBER_OF_FUNCTIONS;i++)
|
|
||||||
flist[i]=&qServer::M_nofunc;
|
|
||||||
|
|
||||||
flist[F_GET_RUN_STATUS] = &qServer::GetStatus;
|
flist[F_GET_RUN_STATUS] = &qServer::GetStatus;
|
||||||
flist[F_START_ACQUISITION] = &qServer::StartAcquisition;
|
flist[F_START_ACQUISITION] = &qServer::StartAcquisition;
|
||||||
flist[F_STOP_ACQUISITION] = &qServer::StopsAcquisition;
|
flist[F_STOP_ACQUISITION] = &qServer::StopsAcquisition;
|
||||||
@ -64,13 +62,13 @@ int qServer::FunctionTable(){
|
|||||||
//------------------------------------------------------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
int qServer::DecodeFunction(){
|
int qServer::DecodeFunction(MySocketTCP* sock){
|
||||||
int ret = qDefs::FAIL;
|
int ret = qDefs::FAIL;
|
||||||
int n,fnum;
|
int n,fnum;
|
||||||
#ifdef VERYVERBOSE
|
#ifdef VERYVERBOSE
|
||||||
cout << "receive data" << endl;
|
cout << "receive data" << endl;
|
||||||
#endif
|
#endif
|
||||||
n = mySocket->ReceiveDataOnly(&fnum,sizeof(fnum));
|
n = sock->ReceiveDataOnly(&fnum,sizeof(fnum));
|
||||||
if (n <= 0) {
|
if (n <= 0) {
|
||||||
#ifdef VERYVERBOSE
|
#ifdef VERYVERBOSE
|
||||||
cout << "ERROR reading from socket " << n << ", " << fnum << endl;
|
cout << "ERROR reading from socket " << n << ", " << fnum << endl;
|
||||||
@ -86,8 +84,26 @@ int qServer::DecodeFunction(){
|
|||||||
cout << "calling function fnum = "<< fnum << hex << ":"<< flist[fnum] << endl;
|
cout << "calling function fnum = "<< fnum << hex << ":"<< flist[fnum] << endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (fnum<0 || fnum>NUMBER_OF_FUNCTIONS-1)
|
|
||||||
fnum = NUMBER_OF_FUNCTIONS-1;
|
|
||||||
|
if (((sock == myStopSocket) && ((fnum == F_GET_RUN_STATUS) || (fnum == F_STOP_ACQUISITION) || (fnum == F_EXIT_SERVER))) ||
|
||||||
|
((sock == mySocket) && ((fnum == F_START_ACQUISITION) || (fnum == F_START_AND_READ_ALL))))
|
||||||
|
;
|
||||||
|
//unrecognized functions exit guis
|
||||||
|
else{
|
||||||
|
ret = qDefs::FAIL;
|
||||||
|
sprintf(mess,"Unrecognized Function\n");
|
||||||
|
cout << mess << endl;
|
||||||
|
|
||||||
|
if (mySocket)
|
||||||
|
mySocket->ShutDownSocket();
|
||||||
|
|
||||||
|
myStopSocket->SendDataOnly(&ret,sizeof(ret));
|
||||||
|
myStopSocket->SendDataOnly(mess,sizeof(mess));
|
||||||
|
return GOODBYE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//calling function
|
//calling function
|
||||||
ret = (this->*flist[fnum])();
|
ret = (this->*flist[fnum])();
|
||||||
if (ret==qDefs::FAIL)
|
if (ret==qDefs::FAIL)
|
||||||
@ -100,20 +116,24 @@ int qServer::DecodeFunction(){
|
|||||||
//------------------------------------------------------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
int qServer::M_nofunc(){
|
int qServer::ExitServer(){
|
||||||
|
|
||||||
int ret = qDefs::FAIL;
|
int ret = OK;
|
||||||
sprintf(mess,"Unrecognized Function\n");
|
strcpy(mess," Gui Server closed successfully\n");
|
||||||
|
|
||||||
|
if(mySocket)
|
||||||
|
mySocket->ShutDownSocket();
|
||||||
|
|
||||||
|
myStopSocket->SendDataOnly(&ret,sizeof(ret));
|
||||||
|
myStopSocket->SendDataOnly(mess,sizeof(mess));
|
||||||
cout << mess << endl;
|
cout << mess << endl;
|
||||||
|
|
||||||
mySocket->SendDataOnly(&ret,sizeof(ret));
|
|
||||||
mySocket->SendDataOnly(mess,sizeof(mess));
|
|
||||||
|
|
||||||
return GOODBYE;
|
return GOODBYE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int qServer::StartStopServer(int start){
|
int qServer::StartStopServer(int start){
|
||||||
@ -125,26 +145,43 @@ int qServer::StartStopServer(int start){
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(!gui_server_thread_running){
|
if(!gui_server_thread_running){
|
||||||
#ifdef VERBOSE
|
|
||||||
cout << "Starting gui server thread ...." << endl;
|
|
||||||
#endif
|
|
||||||
gui_server_thread_running=1;
|
gui_server_thread_running=1;
|
||||||
checkStarted=1;
|
|
||||||
|
|
||||||
//error creating thread
|
//error creating thread
|
||||||
|
checkStarted=1;
|
||||||
if (pthread_create(&gui_server_thread, NULL,StartServerThread, (void*) this)){
|
if (pthread_create(&gui_server_thread, NULL,StartServerThread, (void*) this)){
|
||||||
gui_server_thread_running=0;
|
gui_server_thread_running=0;
|
||||||
qDefs::Message(qDefs::WARNING,"Can't create gui server thread", "Server");
|
qDefs::Message(qDefs::WARNING,"Can't create gui server thread", "Server");
|
||||||
return 0;
|
cout << "ERROR: Can't create gui server thread" << endl;
|
||||||
|
return FAIL;
|
||||||
}
|
}
|
||||||
while(checkStarted);
|
while(checkStarted);
|
||||||
checkStarted=0;
|
checkStarted = 0;
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
if(gui_server_thread_running)
|
if(gui_server_thread_running)
|
||||||
cout << "Server thread created successfully." << endl;
|
cout << "Server thread created successfully." << endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
//error creating thread
|
||||||
|
checkStopStarted=1;
|
||||||
|
if (pthread_create(&gui_stop_server_thread, NULL,StopServerThread, (void*) this)){
|
||||||
|
gui_server_thread_running=0;
|
||||||
|
qDefs::Message(qDefs::WARNING,"Can't create gui stop server thread", "Server");
|
||||||
|
cout << "ERROR: Can't create gui stop server thread" << endl;
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
while(checkStopStarted);
|
||||||
|
checkStopStarted=0;
|
||||||
|
#ifdef VERBOSE
|
||||||
|
if(gui_server_thread_running)
|
||||||
|
cout << "Server Stop thread created successfully." << endl;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//stop server
|
//stop server
|
||||||
else{
|
else{
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
@ -152,10 +189,8 @@ int qServer::StartStopServer(int start){
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(gui_server_thread_running){
|
if(gui_server_thread_running){
|
||||||
#ifdef VERBOSE
|
|
||||||
cout << "Stopping gui server thread ...." << endl;
|
|
||||||
#endif
|
|
||||||
gui_server_thread_running=0;
|
gui_server_thread_running=0;
|
||||||
|
|
||||||
if(mySocket)
|
if(mySocket)
|
||||||
mySocket->ShutDownSocket();
|
mySocket->ShutDownSocket();
|
||||||
pthread_join(gui_server_thread,NULL);
|
pthread_join(gui_server_thread,NULL);
|
||||||
@ -163,13 +198,20 @@ int qServer::StartStopServer(int start){
|
|||||||
delete mySocket;
|
delete mySocket;
|
||||||
mySocket = NULL;
|
mySocket = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(myStopSocket)
|
||||||
|
myStopSocket->ShutDownSocket();
|
||||||
|
pthread_join(gui_stop_server_thread,NULL);
|
||||||
|
if(myStopSocket){
|
||||||
|
delete myStopSocket;
|
||||||
|
myStopSocket = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
cout << "Server stopped successfully." << endl;
|
cout << "Server threads stopped successfully." << endl;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return gui_server_thread_running;
|
return gui_server_thread_running;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,6 +219,71 @@ int qServer::StartStopServer(int start){
|
|||||||
//-------------------------------------------------------------------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
void* qServer::StopServerThread(void* this_pointer){
|
||||||
|
((qServer*)this_pointer)->StopServer();
|
||||||
|
return this_pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int qServer::StopServer(){
|
||||||
|
#ifdef VERYVERBOSE
|
||||||
|
cout << "In StopServer()" << endl;
|
||||||
|
#endif
|
||||||
|
int ret = qDefs::OK;
|
||||||
|
|
||||||
|
myStopSocket = new MySocketTCP(port_no+1);
|
||||||
|
if (myStopSocket->getErrorStatus()){
|
||||||
|
gui_server_thread_running = 0;
|
||||||
|
qDefs::Message(qDefs::WARNING,"Could not start gui stop server socket","Server");
|
||||||
|
}
|
||||||
|
checkStopStarted = 0;
|
||||||
|
|
||||||
|
while ((gui_server_thread_running) && (ret!=GOODBYE)) {
|
||||||
|
#ifdef VERBOSE
|
||||||
|
cout<< endl;
|
||||||
|
#endif
|
||||||
|
#ifdef VERYVERBOSE
|
||||||
|
cout << "Waiting for client call" << endl;
|
||||||
|
#endif
|
||||||
|
if(myStopSocket->Connect()>=0){
|
||||||
|
#ifdef VERYVERBOSE
|
||||||
|
cout << "Conenction accepted" << endl;
|
||||||
|
#endif
|
||||||
|
ret = DecodeFunction(myStopSocket);
|
||||||
|
#ifdef VERYVERBOSE
|
||||||
|
cout << "function executed" << endl;
|
||||||
|
#endif
|
||||||
|
myStopSocket->Disconnect();
|
||||||
|
#ifdef VERYVERBOSE
|
||||||
|
cout << "connection closed" << endl;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#ifdef VERBOSE
|
||||||
|
cout << "Stopped gui stop server thread" << endl;
|
||||||
|
#endif
|
||||||
|
gui_server_thread_running = 0;
|
||||||
|
//delete socket(via exit server)
|
||||||
|
if(myStopSocket){
|
||||||
|
delete myStopSocket;
|
||||||
|
myStopSocket = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!gui_server_thread_running)
|
||||||
|
emit ServerStoppedSignal();
|
||||||
|
|
||||||
|
return qDefs::OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void* qServer::StartServerThread(void* this_pointer){
|
void* qServer::StartServerThread(void* this_pointer){
|
||||||
((qServer*)this_pointer)->StartServer();
|
((qServer*)this_pointer)->StartServer();
|
||||||
return this_pointer;
|
return this_pointer;
|
||||||
@ -189,7 +296,7 @@ void* qServer::StartServerThread(void* this_pointer){
|
|||||||
|
|
||||||
int qServer::StartServer(){
|
int qServer::StartServer(){
|
||||||
#ifdef VERYVERBOSE
|
#ifdef VERYVERBOSE
|
||||||
cout << "In StartServer()\n");
|
cout << "In StartServer()" << endl;
|
||||||
#endif
|
#endif
|
||||||
int ret = qDefs::OK;
|
int ret = qDefs::OK;
|
||||||
|
|
||||||
@ -211,7 +318,7 @@ int qServer::StartServer(){
|
|||||||
#ifdef VERYVERBOSE
|
#ifdef VERYVERBOSE
|
||||||
cout << "Conenction accepted" << endl;
|
cout << "Conenction accepted" << endl;
|
||||||
#endif
|
#endif
|
||||||
ret = DecodeFunction();
|
ret = DecodeFunction(mySocket);
|
||||||
#ifdef VERYVERBOSE
|
#ifdef VERYVERBOSE
|
||||||
cout << "function executed" << endl;
|
cout << "function executed" << endl;
|
||||||
#endif
|
#endif
|
||||||
@ -230,8 +337,10 @@ int qServer::StartServer(){
|
|||||||
delete mySocket;
|
delete mySocket;
|
||||||
mySocket = NULL;
|
mySocket = NULL;
|
||||||
}
|
}
|
||||||
//uncheck the server in modes(via exit server)
|
|
||||||
myMainTab->GuiServerExited();
|
if(!gui_server_thread_running)
|
||||||
|
emit ServerStoppedSignal();
|
||||||
|
|
||||||
return qDefs::OK;
|
return qDefs::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -254,9 +363,9 @@ int qServer::GetStatus(){
|
|||||||
progress = myMainTab->GetProgress();
|
progress = myMainTab->GetProgress();
|
||||||
|
|
||||||
// send answer
|
// send answer
|
||||||
mySocket->SendDataOnly(&ret,sizeof(ret));
|
myStopSocket->SendDataOnly(&ret,sizeof(ret));
|
||||||
mySocket->SendDataOnly(&retval,sizeof(retval));
|
myStopSocket->SendDataOnly(&retval,sizeof(retval));
|
||||||
mySocket->SendDataOnly(&progress,sizeof(progress));
|
myStopSocket->SendDataOnly(&progress,sizeof(progress));
|
||||||
//return ok/fail
|
//return ok/fail
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -286,9 +395,9 @@ int qServer::StopsAcquisition(){
|
|||||||
strcpy(mess,"Could not stop acquisition in gui. \n");
|
strcpy(mess,"Could not stop acquisition in gui. \n");
|
||||||
|
|
||||||
int ret = myMainTab->StartStopAcquisitionFromClient(false);
|
int ret = myMainTab->StartStopAcquisitionFromClient(false);
|
||||||
mySocket->SendDataOnly(&ret,sizeof(ret));
|
myStopSocket->SendDataOnly(&ret,sizeof(ret));
|
||||||
if(ret==FAIL)
|
if(ret==FAIL)
|
||||||
mySocket->SendDataOnly(mess,sizeof(mess));
|
myStopSocket->SendDataOnly(mess,sizeof(mess));
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -316,18 +425,3 @@ int qServer::Acquire(){
|
|||||||
|
|
||||||
//------------------------------------------------------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
int qServer::ExitServer(){
|
|
||||||
|
|
||||||
int ret = OK;
|
|
||||||
strcpy(mess,"closing gui server");
|
|
||||||
|
|
||||||
mySocket->SendDataOnly(&ret,sizeof(ret));
|
|
||||||
mySocket->SendDataOnly(mess,sizeof(mess));
|
|
||||||
cout << mess << endl;
|
|
||||||
|
|
||||||
return GOODBYE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------------------------------------------------------------
|
|
||||||
|
Reference in New Issue
Block a user