gui client works for just getting status

git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorGui@149 af1100a4-978c-4157-bff7-07162d2ba061
This commit is contained in:
l_maliakal_d 2013-03-01 13:21:07 +00:00
parent 2fc324ab4b
commit 863b662c6b
15 changed files with 564 additions and 17 deletions

View File

@ -6,14 +6,13 @@ DOCDIR?=docs
LIBDIR?=../slsDetectorSoftware
all: $(PROG) Makefile.gui
all: $(PROG) Makefile.gui client
clean:
if test -e Makefile.gui; then make -f Makefile.gui clean; make -f Makefile.gui mocclean; rm Makefile.gui; else make Makefile.gui; make -f Makefile.gui clean; make -f Makefile.gui mocclean; fi
# cd manual && make clean
Makefile.gui: mm
mm:

View File

@ -0,0 +1,103 @@
/*
* qClient.cpp
*
* Created on: Feb 27, 2013
* Author: Dhanya Maliakal
*/
// Qt Project Class Headers
#include "qClient.h"
// Project Class Headers
#include "MySocketTCP.h"
#include "slsDetectorBase.h"
// C++ Include Headers
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
qClient *cl =new qClient(argv[1]);
cl->executeLine(argc-2, argv+2);
delete cl;
}
//-------------------------------------------------------------------------------------------------------------------------------------------------
qClient::qClient(char* hostname){
//create socket
mySocket = new MySocketTCP(hostname, DEFAULT_GUI_PORTNO);
if (mySocket->getErrorStatus()){
cout << "Error: could not connect to host:" << hostname << " with port " << DEFAULT_GUI_PORTNO << endl;
delete mySocket;
exit(-1);
}
}
//-------------------------------------------------------------------------------------------------------------------------------------------------
int qClient::executeLine(int narg, char *args[]){
char arg[MAX_STR_LENGTH] = "";
int iarg = -1;
char answer[100];
string retval = "";
string cmd = args[0];
//validate command structure
if(narg<1){
cout << "Error: no command parsed" << endl;
return slsDetectorDefs::FAIL;
}
//file name
if (cmd == "status"){
retval = getStatus();
}
//unrecognized command
else{
cout << "Error: unrecognized command" << endl;
return slsDetectorDefs::FAIL;
}
//print result
cout << cmd << ": " << retval << endl;
return slsDetectorDefs::OK;
}
//-------------------------------------------------------------------------------------------------------------------------------------------------
string qClient::getStatus(){
int fnum = slsDetectorDefs::F_GET_RUN_STATUS;
int ret = slsDetectorDefs::FAIL;
int retval = -1;
slsDetectorDefs::runStatus s=slsDetectorDefs::ERROR;
if (mySocket->Connect() >= 0) {
mySocket->SendDataOnly(&fnum,sizeof(fnum));
mySocket->ReceiveDataOnly(&ret,sizeof(ret));
mySocket->ReceiveDataOnly(&retval,sizeof(retval));
}
mySocket->Disconnect();
if(retval==-1)
retval=slsDetectorDefs::ERROR;
return slsDetectorBase::runStatusType((slsDetectorDefs::runStatus)retval);
}
//-------------------------------------------------------------------------------------------------------------------------------------------------

View File

@ -0,0 +1,46 @@
/*
* qClient.h
*
* Created on: Feb 27, 2013
* Author: Dhanya Maliakal
*/
#ifndef QCLIENT_H
#define QCLIENT_H
/** Qt Project Class Headers */
//#include "qDefs.h"
/** Project Class Headers */
class MySocketTCP;
#include "sls_detector_defs.h"
/** C++ Include Headers */
#include <stdlib.h>
#include <string>
using namespace std;
/**
*@short Sets up the gui server
*/
class qClient: public virtual slsDetectorDefs{
public:
/** \short The constructor*/
qClient(char* hostname);
/** Destructor */
virtual ~qClient(){};
/**Execute command*/
int executeLine(int narg, char *args[]);
private:
/** Gets run status */
string getStatus();
/** client socket */
MySocketTCP *mySocket;
};
#endif /* QCLIENT_H */

View File

@ -243,6 +243,7 @@
<addaction name="actionDebug"/>
<addaction name="actionExpert"/>
<addaction name="actionDockable"/>
<addaction name="actionListenGuiClient"/>
</widget>
<widget class="QMenu" name="menuHelp">
<property name="title">
@ -503,6 +504,14 @@ p, li { white-space: pre-wrap; }
<string>Save C&amp;alibration</string>
</property>
</action>
<action name="actionListenGuiClient">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Listen to Gui Client</string>
</property>
</action>
</widget>
<resources/>
<connections/>

View File

@ -28,6 +28,7 @@ public:
static const int64_t GUI_VERSION=0x20121213;
#define GOODBYE -200
//-------------------------------------------------------------------------------------------------------------------------------------------------
enum{

View File

@ -22,6 +22,7 @@ class qTabSettings;
class qTabDebugging;
class qTabDeveloper;
class qTabMessages;
class qServer;
/** Project Class Headers */
class multiSlsDetector;
/** Qt Include Headers */
@ -110,6 +111,9 @@ private:
/**Messages tab */
qTabMessages *tab_messages;
/** server object*/
qServer *myServer;
/**if the developer tab should be enabled,known from command line */
int isDeveloper;

View File

@ -2,7 +2,7 @@
* qDrawPlot.h
*
* Created on: May 7, 2012
* Author: Ian Johnson
* Author: Dhanya Maliakal
*/
#ifndef QDRAWPLOT_H
#define QDRAWPLOT_H
@ -117,8 +117,6 @@ public:
int UpdateTrimbitPlot(bool fromDetector,bool Histogram);
public slots:
/** To select 1D or 2D plot
@param i is 1 for 1D, else 2D plot */

View File

@ -0,0 +1,106 @@
/*
* qServer.h.h
*
* Created on: Feb 27, 2013
* Author: Dhanya Maliakal
*/
#ifndef QSERVER_H
#define QSERVER_H
/** Qt Project Class Headers */
#include "sls_detector_defs.h"
#include "qDefs.h"
class qDrawPlot;
class qTabMeasurement;
/** Project Class Headers */
class multiSlsDetector;
class MySocketTCP;
/** C++ Include Headers */
/**
*@short Sets up the gui server
*/
class qServer: public virtual slsDetectorDefs{
public:
/** \short The constructor */
qServer(multiSlsDetector*& detector, qTabMeasurement* m, qDrawPlot *d);
/** Destructor */
~qServer();
/** Start or Stop Gui Server
* @param start is 1 to start and 0 to stop
*/
int StartStopServer(int start);
private:
/** assigns functions to the fnum enum */
int function_table();
/** Decodes Function */
int decode_function();
/** Unrecognized Function */
int M_nofunc();
/**
* Static function - Thread started which listens to client gui.
* Called by StartStopServer()
* @param this_pointer pointer to this object
*/
static void* StartServerThread(void *this_pointer);
/**
* Thread started which listens to client gui.
* Called by startServerThread()
*
*/
int StartServer();
/** Get Detector Status */
int get_status();
/** The multi detector object */
multiSlsDetector *myDet;
/**The measurement tab object*/
qTabMeasurement *tab_measurement;
/**The plot widget object*/
qDrawPlot *myPlot;
/** tcp socket to gui client */
MySocketTCP *mySocket;
/** server port number*/
int port_no;
/** Lock Status if server locked to a client */
int lockStatus;
/** Function List */
static const int NUMBER_OF_FUNCTIONS = 256;
int (qServer::*flist[NUMBER_OF_FUNCTIONS])();
/** if the gui server thread is running*/
static int gui_server_thread_running;
/** thread listening to gui client*/
pthread_t gui_server_thread;
/** server started */
int checkStarted;
/** Message */
char mess[MAX_STR_LENGTH];
};
#endif /* QSERVER_H */

View File

@ -91,7 +91,6 @@ private:
void Enable(bool enable);
private slots:
/** Sets the timing mode
* @ param mode cane be None, Auto, Gated, Trigger Exposure Series,
@ -156,7 +155,6 @@ private slots:
void EnableFileWrite(bool enable);
private:
/** The sls detector object */
multiSlsDetector *myDet;

View File

@ -2,10 +2,10 @@
#define SVNURL "file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorGui"
//#define SVNREPPATH ""
#define SVNREPUUID "af1100a4-978c-4157-bff7-07162d2ba061"
//#define SVNREV 0x147
//#define SVNREV 0x148
//#define SVNKIND ""
//#define SVNSCHED ""
#define SVNAUTH "l_maliakal_d"
#define SVNREV 0x147
#define SVNREV 0x148
#define SVNDATE 0x20130226
//

View File

@ -82,7 +82,8 @@ SOURCES = \
src/qTabSettings.cpp\
src/qTabDebugging.cpp\
src/qTabDeveloper.cpp\
src/qTabMessages.cpp
src/qTabMessages.cpp\
src/qServer.cpp
HEADERS = \
slsDetectorPlotting/include/SlsQt1DPlot.h\
@ -110,7 +111,8 @@ HEADERS = \
include/qTabDeveloper.h\
include/qTabMessages.h\
include/svnInfoGui.h\
../slsDetectorSoftware/commonFiles/sls_detector_defs.h
../slsDetectorSoftware/commonFiles/sls_detector_defs.h\
include/qServer.h
FORMS = \

View File

@ -14,6 +14,7 @@
#include "qTabDebugging.h"
#include "qTabDeveloper.h"
#include "qTabMessages.h"
#include "qServer.h"
// Project Class Headers
#include "slsDetector.h"
#include "multiSlsDetector.h"
@ -112,6 +113,8 @@ void qDetectorMain::SetUpWidgetWindow(){
tab_debugging = new qTabDebugging (this, myDet); cout<<"Debugging ready"<<endl;
tab_developer = new qTabDeveloper (this, myDet); cout<<"Developer ready"<<endl;
myServer = new qServer(myDet, tab_measurement, myPlot);
// creating the scroll area widgets for the tabs
for(int i=0;i<NumberOfTabs;i++){
scroll[i] = new QScrollArea;
@ -320,8 +323,14 @@ void qDetectorMain::LoadConfigFile(const string fName){
void qDetectorMain::EnableModes(QAction *action){
bool enable;
//listen to gui client
if(action==actionListenGuiClient){
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
if(action==actionDebug){
else if(action==actionDebug){
enable = actionDebug->isChecked();
tabs->setTabEnabled(Debugging,enable);
#ifdef VERBOSE

View File

@ -2,7 +2,7 @@
* qDrawPlot.cpp
*
* Created on: May 7, 2012
* Author: Ian Johnson
* Author: Dhanya Maliakal
*/
// Qt Project Class Headers
#include "qDrawPlot.h"
@ -174,9 +174,6 @@ void qDrawPlot::SetupWidgetWindow(){
pedestalCount = 0;
//widget related initialization
// clone
@ -578,7 +575,6 @@ void qDrawPlot::SetupMeasurement(){
void* qDrawPlot::DataStartAcquireThread(void *this_pointer){
((qDrawPlot*)this_pointer)->myDet->acquire(1);
return this_pointer;
}

View File

@ -0,0 +1,256 @@
/*
* qServer.cpp
*
* Created on: Feb 27, 2013
* Author: Dhanya Maliakal
*/
// Qt Project Class Headers
#include "qServer.h"
#include "qTabMeasurement.h"
#include "qDrawPlot.h"
// Project Class Headers
#include "slsDetector.h"
#include "multiSlsDetector.h"
#include "MySocketTCP.h"
// C++ Include Headers
#include <iostream>
#include <string>
using namespace std;
//-------------------------------------------------------------------------------------------------------------------------------------------------
int qServer::gui_server_thread_running(0);
//-------------------------------------------------------------------------------------------------------------------------------------------------
qServer::qServer(multiSlsDetector*& detector, qTabMeasurement* m, qDrawPlot *d):
myDet(detector),tab_measurement(m),myPlot(d),mySocket(NULL),port_no(DEFAULT_GUI_PORTNO),lockStatus(0){
function_table();
}
//-------------------------------------------------------------------------------------------------------------------------------------------------
qServer::~qServer(){
delete myDet;
delete tab_measurement;
delete myPlot;
if(mySocket) delete mySocket;
}
//-------------------------------------------------------------------------------------------------------------------------------------------------
int qServer::function_table(){
for (int i=0;i<NUMBER_OF_FUNCTIONS;i++)
flist[i]=&qServer::M_nofunc;
flist[F_GET_RUN_STATUS] = &qServer::get_status;
flist[F_START_ACQUISITION] = &qServer::get_status;
flist[F_STOP_ACQUISITION] = &qServer::get_status;
flist[F_START_AND_READ_ALL] = &qServer::get_status;
flist[F_EXIT_SERVER] = &qServer::get_status;
return qDefs::OK;
}
//------------------------------------------------------------------------------------------------------------------------------------------
int qServer::decode_function(){
int ret = qDefs::FAIL;
int n,fnum;
#ifdef VERYVERBOSE
cout << "receive data" << endl;
#endif
n = mySocket->ReceiveDataOnly(&fnum,sizeof(fnum));
if (n <= 0) {
#ifdef VERYVERBOSE
cout << "ERROR reading from socket " << n << ", " << fnum << endl;
#endif
return qDefs::FAIL;
}
#ifdef VERYVERBOSE
else
cout << "size of data received " << n <<endl;
#endif
#ifdef VERYVERBOSE
cout << "calling function fnum = "<< fnum << hex << ":"<< flist[fnum] << endl;
#endif
if (fnum<0 || fnum>NUMBER_OF_FUNCTIONS-1)
fnum = NUMBER_OF_FUNCTIONS-1;
//calling function
(this->*flist[fnum])();
if (ret==qDefs::FAIL)
cout << "Error executing the function = " << fnum << endl;
return ret;
}
//------------------------------------------------------------------------------------------------------------------------------------------
int qServer::M_nofunc(){
int ret = qDefs::FAIL;
sprintf(mess,"Unrecognized Function\n");
cout << mess << endl;
mySocket->SendDataOnly(&ret,sizeof(ret));
mySocket->SendDataOnly(mess,sizeof(mess));
return GOODBYE;
}
//-------------------------------------------------------------------------------------------------------------------------------------------------
int qServer::StartStopServer(int start){
//start server
if(start){
#ifdef VERBOSE
cout << endl << "Starting Gui Server" << endl;
#endif
if(!gui_server_thread_running){
#ifdef VERBOSE
cout << "Starting gui server thread ...." << endl;
#endif
gui_server_thread_running=1;
checkStarted=1;
//error creating thread
if (pthread_create(&gui_server_thread, NULL,StartServerThread, (void*) this)){
gui_server_thread_running=0;
qDefs::Message(qDefs::WARNING,"Can't create gui server thread", "Server");
return 0;
}
while(checkStarted);
checkStarted=0;
#ifdef VERBOSE
if(gui_server_thread_running)
cout << "Server thread created successfully." << endl;
#endif
}
}
//stop server
else{
#ifdef VERBOSE
cout << "Stopping Gui Server" << endl;
#endif
if(gui_server_thread_running){
#ifdef VERBOSE
cout << "Stopping gui server thread ...." << endl;
#endif
gui_server_thread_running=0;
mySocket->Disconnect();
mySocket->ShutDownSocket();
pthread_join(gui_server_thread,NULL);
delete mySocket;
mySocket = NULL;
}
#ifdef VERBOSE
cout << "Server stopped successfully." << endl;
#endif
}
return gui_server_thread_running;
}
//-------------------------------------------------------------------------------------------------------------------------------------------------
void* qServer::StartServerThread(void* this_pointer){
((qServer*)this_pointer)->StartServer();
return this_pointer;
}
//-------------------------------------------------------------------------------------------------------------------------------------------------
int qServer::StartServer(){
#ifdef VERYVERBOSE
cout << "In StartServer()\n");
#endif
int ret = qDefs::OK;
mySocket = new MySocketTCP(port_no);
if (mySocket->getErrorStatus()){
gui_server_thread_running = 0;
qDefs::Message(qDefs::WARNING,"Could not start gui server socket","Server");
}
checkStarted = 0;
while ((gui_server_thread_running) && (ret!=GOODBYE)) {
#ifdef VERBOSE
cout<< endl;
#endif
#ifdef VERYVERBOSE
cout << "Waiting for client call" << endl;
#endif
if(mySocket->Connect()>=0){
#ifdef VERYVERBOSE
cout << "Conenction accepted" << endl;
#endif
ret = decode_function();
#ifdef VERYVERBOSE
cout << "function executed" << endl;
#endif
mySocket->Disconnect();
#ifdef VERYVERBOSE
cout << "connection closed" << endl;
#endif
}
}
#ifdef VERBOSE
cout << "Stopped gui server thread" << endl;
#endif
gui_server_thread_running = 0;
return qDefs::OK;
}
//-------------------------------------------------------------------------------------------------------------------------------------------------
int qServer::get_status(){
int ret = qDefs::OK;
enum slsDetectorDefs::runStatus retval;
// execute action if the arguments correctly arrived
if(myPlot->isRunning())
retval = slsDetectorDefs::RUNNING;
else
retval = slsDetectorDefs::IDLE;
// send answer
mySocket->SendDataOnly(&ret,sizeof(ret));
mySocket->SendDataOnly(&retval,sizeof(retval));
//return ok/fail
return ret;
}
//------------------------------------------------------------------------------------------------------------------------------------------

View File

@ -83,6 +83,7 @@ void qTabMeasurement::SetupWidgetWindow(){
iconStart = new QIcon(":/icons/images/start.png");
iconStop = new QIcon(":/icons/images/stop.png");
}
@ -323,6 +324,25 @@ void qTabMeasurement::startStopAcquisition(){
}
//-------------------------------------------------------------------------------------------------------------------------------------------------
/*
int qTabMeasurement::GetAcquisitionStarted(){
cout<<" acquisition started call back"<<endl;
//if the acquisition started from client, the button wont be checked
if(!btnStartStop->isChecked()){cout<<" hasnt started, so from client"<<endl;
myPlot->SetAcqFromClient();
btnStartStop->click();
//wait till the gui is ready to execute the acquire(), but doesnt execute it
//acqFromClient is reset when it is ready
while(myPlot->GetAcqFromClient());
}else
cout<<" has started, so from gui"<<endl;
return 0;
}
*/
//-------------------------------------------------------------------------------------------------------------------------------------------------