merging refactor (replacing)

This commit is contained in:
2019-04-12 10:53:09 +02:00
parent 0bb800cc8a
commit 89a06f099c
1176 changed files with 82698 additions and 159058 deletions

View File

@ -1,31 +0,0 @@
CC = g++
CLAGS += -DVERBOSE #VERYBOSE
LDLIBS += -lm -lstdc++ -pthread
LDIR = ../../slsDetectorSoftware
RDIR = ../../slsReceiverSoftware
DDIR = ../../bin
INCLUDES = -I $(LDIR)/commonFiles -I $(LDIR)/slsDetector -I ../include -I $(RDIR)/include
SRC_CLNT = qClient.cpp $(RDIR)/src/MySocketTCP.cpp
DEPSINCLUDES= qClient.h $(RDIR)/include/MySocketTCP.h $(LDIR)/slsDetector/slsDetectorBase.h $(LDIR)/commonFiles/sls_detector_defs.h
all: client
client: $(OBJS) $(DDIR)/gui_client
OBJS = $(SRC_CLNT:%.cpp=%.o)
$(DDIR)/gui_client : $(SRC_CLNT) $(DEPSINCLUDES) Makefile
$(CXX) -o $@ -c $< $(INCLUDES) $(FLAGS) $(LDLIBS)
clean:
rm -rf $(DDIR)/gui_client *.o

311
slsDetectorGui/client/qClient.cpp Normal file → Executable file
View File

@ -1,237 +1,124 @@
/*
* 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 "ClientSocket.h"
#include "logger.h"
#include "sls_detector_exceptions.h"
#include <iostream>
#include <sstream>
using namespace std;
//-------------------------------------------------------------------------------------------------------------------------------------------------
int main(int argc, char *argv[]){
qClient* cl = 0;
try {
cl = new qClient(argv[1]);
} catch(...) {
return 0;
}
cl->executeLine(argc-2, argv+2);
delete cl;
return 0;
int main(int argc, char *argv[]) {
qClient *cl = 0;
cl = new qClient(argv[1]);
cl->executeLine(argc - 2, argv + 2);
delete cl;
return 0;
}
//-------------------------------------------------------------------------------------------------------------------------------------------------
qClient::qClient(char* hostname):
mySocket(0),
myStopSocket(0){
try {
// control socket
mySocket = new MySocketTCP(hostname, DEFAULT_GUI_PORTNO);
// stop socket
myStopSocket = new MySocketTCP(hostname, DEFAULT_GUI_PORTNO+1);
} catch(...) {
if (mySocket == 0)
cout << "Error: could not connect to control server:" <<
hostname << " with port " << DEFAULT_GUI_PORTNO << endl;
else
cout << "Error: could not connect to stop server:" <<
hostname << " with port " << DEFAULT_GUI_PORTNO + 1 << endl;
throw;
}
qClient::qClient(char *h)
: controlPort(DEFAULT_GUI_PORTNO), stopPort(DEFAULT_GUI_PORTNO + 1) {
hostname.assign(h);
}
qClient::~qClient() {}
//-------------------------------------------------------------------------------------------------------------------------------------------------
void qClient::executeLine(int narg, char *args[]) {
qClient::~qClient() {
if(mySocket) delete mySocket;
if(myStopSocket) delete myStopSocket;
std::string retval = "";
std::string cmd = args[0];
// validate command structure
if (narg < 1) {
throw sls::RuntimeError("No command parsed. " + printCommands());
}
// help
if (cmd == "help") {
retval = printCommands();
}
// file name
else if (cmd == "status") {
if (narg > 1) {
std::string argument = args[1];
// start acquisition
if (argument == "start")
startAcquisition();
else if (argument == "stop")
stopAcquisition();
else {
throw sls::RuntimeError("Could not parse arguments. " +
printCommands());
}
}
retval = getStatus();
}
else if (cmd == "acquire") {
startAcquisition(true);
retval = getStatus();
}
else if (cmd == "exit") {
exitServer();
retval.assign("Server exited successfully");
}
// unrecognized command
else {
throw sls::RuntimeError("Unrecognized command. " + printCommands());
}
// print result
FILE_LOG(logINFO) << cmd << ": " << retval;
}
//-------------------------------------------------------------------------------------------------------------------------------------------------
int qClient::executeLine(int narg, char *args[]){
string retval = "";
string cmd = args[0];
string argument;
//validate command structure
if(narg<1){
cout << "Error: no command parsed" << endl;
return FAIL;
}
//help
if (cmd == "help"){
retval = printCommands();
}
//file name
else if (cmd == "status"){
if(narg>1){
argument = args[1];
//start acquisition
if(argument == "start")
startAcquisition();
else if (argument == "stop")
stopAcquisition();
else{
cprintf(RED,"Error: could not parse arguments: %s\n", argument.c_str());
printCommands();
return FAIL;
}
}
retval = getStatus();
}
else if (cmd == "acquire"){
startAcquisition(true);
retval = getStatus();
}
else if (cmd == "exit"){
return exitServer();
}
//unrecognized command
else{
cout << "Error: unrecognized command" << endl;
return FAIL;
}
//print result
cout << cmd << ": " << retval << endl;
return OK;
std::string qClient::printCommands() {
std::ostringstream os;
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 i starts/stops acquistion in gui-non blocking. i is start "
"or stop"
<< std::endl;
os << "acquire starts acquistion in gui-blocking" << std::endl;
return os.str();
}
//-------------------------------------------------------------------------------------------------------------------------------------------------
std::string qClient::getStatus() {
int fnum = qDefs::F_GUI_GET_RUN_STATUS;
int retvals[2] = {static_cast<int>(ERROR), 0};
auto client = sls::GuiSocket(hostname, controlPort);
client.sendCommandThenRead(fnum, nullptr, 0, retvals, sizeof(retvals));
string qClient::printCommands(){
ostringstream os;
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 i starts/stops acquistion in gui-non blocking. i is start or stop" << std::endl;
os << "acquire starts acquistion in gui-blocking" << std::endl;
return os.str();
runStatus status = static_cast<runStatus>(retvals[0]);
int progress = retvals[1];
return std::to_string(progress) + std::string("% ") +
slsDetectorDefs::runStatusType(status);
}
void qClient::startAcquisition(bool blocking) {
int fnum = qDefs::F_GUI_START_ACQUISITION;
if (blocking)
fnum = qDefs::F_GUI_START_AND_READ_ALL;
//-------------------------------------------------------------------------------------------------------------------------------------------------
string qClient::getStatus(){
int fnum = F_GET_RUN_STATUS;
int ret = FAIL;
runStatus retval=ERROR;
int progress = 0;
char answer[100];
if (myStopSocket->Connect() >= 0) {
myStopSocket->SendDataOnly(&fnum,sizeof(fnum));
myStopSocket->ReceiveDataOnly(&ret,sizeof(ret));
myStopSocket->ReceiveDataOnly(&retval,sizeof(retval));
myStopSocket->ReceiveDataOnly(&progress,sizeof(progress));
myStopSocket->Disconnect();
}else
exit(-1);
sprintf(answer,"%d%% ",progress);
strcat(answer,slsDetectorBase::runStatusType((runStatus)retval).c_str());
return string(answer);
auto client = sls::GuiSocket(hostname.c_str(), controlPort);
client.sendCommandThenRead(fnum, nullptr, 0, nullptr, 0);
}
void qClient::stopAcquisition() {
int fnum = qDefs::F_GUI_STOP_ACQUISITION;
//-------------------------------------------------------------------------------------------------------------------------------------------------
int qClient::startAcquisition(bool blocking){
int fnum = F_START_ACQUISITION;
if(blocking) fnum = F_START_AND_READ_ALL;
int ret = FAIL;
if (mySocket->Connect() >= 0) {
mySocket->SendDataOnly(&fnum,sizeof(fnum));
mySocket->ReceiveDataOnly(&ret,sizeof(ret));
if (ret == FAIL){
mySocket->ReceiveDataOnly(mess,sizeof(mess));
std::cout<< "Gui returned error: " << mess << std::endl;
}
mySocket->Disconnect();
}else
exit(-1);
return ret;
auto client = sls::GuiSocket(hostname, stopPort);
client.sendCommandThenRead(fnum, nullptr, 0, nullptr, 0);
}
//-------------------------------------------------------------------------------------------------------------------------------------------------
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;
}
void qClient::exitServer() {
int fnum = qDefs::F_GUI_EXIT_SERVER;
// closes both control and stop server
auto client = sls::GuiSocket(hostname, controlPort);
client.sendCommandThenRead(fnum, nullptr, 0, nullptr, 0);
}

95
slsDetectorGui/client/qClient.h Normal file → Executable file
View File

@ -1,65 +1,70 @@
/*
* qClient.h
*
* Created on: Feb 27, 2013
* Author: Dhanya Maliakal
*/
#ifndef QCLIENT_H
#define QCLIENT_H
#pragma once
#include "qDefs.h"
/** Qt Project Class Headers */
/** 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{
class qClient : public virtual slsDetectorDefs {
public:
/**
* The constructor
* @param h hostname
*/
qClient(char *h);
/**
* Destructor
*/
virtual ~qClient();
public:
/** \short The constructor*/
qClient(char* hostname);
/** Destructor */
virtual ~qClient();
/**
* Execute command
* @param narg number of arguments
* @param args argument list
*/
void executeLine(int narg, char *args[]);
/**Execute command*/
int executeLine(int narg, char *args[]);
private:
/**
* Print list of commands
* @returns string of result
*/
std::string printCommands();
private:
/** Print list of commands */
string printCommands();
/**
* Gets run status
* @returns status
*/
std::string getStatus();
/** Start Acquisition
* @param blocking true if its a blocking acquistion
*/
int startAcquisition(bool blocking = false);
/**
* Start Acquisition
* @param blocking true if its a blocking acquistion
*/
void startAcquisition(bool blocking = false);
/** Stops Acquisition */
int stopAcquisition();
/**
* Stops Acquisition
*/
void stopAcquisition();
/** Gets run status */
string getStatus();
/**
* Exits Server
*/
void exitServer();
/** Exits Server */
int exitServer();
/** hostname */
std::string hostname;
/** client socket */
MySocketTCP *mySocket;
/** client socket */
MySocketTCP *myStopSocket;
char mess[MAX_STR_LENGTH];
/** control port */
int controlPort;
/** stop port */
int stopPort;
};
#endif /* QCLIENT_H */