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

@ -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 */